123LETSPLAY commited on
Commit
e308050
1 Parent(s): 508f5c2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from diffusers import DiffusionPipeline
3
+ import gradio as gr
4
+
5
+ # Load the Flux model with ControlNet upscaling
6
+ pipe = DiffusionPipeline.from_pretrained("jasperai/Flux.1-dev-Controlnet-Upscaler", torch_dtype=torch.float16)
7
+ pipe.to("cuda") # Send the model to GPU if available
8
+
9
+ # Function to generate an image based on user prompt
10
+ def generate_image(prompt):
11
+ # Generate an image using the Flux model
12
+ with torch.inference_mode():
13
+ image = pipe(prompt).images[0]
14
+ return image
15
+
16
+ # Set up the Gradio interface
17
+ with gr.Blocks() as demo:
18
+ gr.Markdown("# Image Generation using Flux (jasperai/Flux.1-dev-Controlnet-Upscaler)")
19
+
20
+ # Input for user to provide a text prompt
21
+ prompt_input = gr.Textbox(label="Enter Text Prompt",
22
+ placeholder="e.g. 'Astronaut in a jungle, cold color palette, muted colors, detailed, 8k'",
23
+ value="Astronaut in a jungle, cold color palette, muted colors, detailed, 8k")
24
+
25
+ # Output to display the generated image
26
+ output_image = gr.Image(label="Generated Image")
27
+
28
+ # Button to trigger image generation
29
+ generate_button = gr.Button("Generate Image")
30
+
31
+ # Link button click to image generation function
32
+ generate_button.click(fn=generate_image, inputs=prompt_input, outputs=output_image)
33
+
34
+ # Launch the Gradio app
35
+ demo.launch()