anshg07 commited on
Commit
cab4f1d
·
verified ·
1 Parent(s): 6ed30f5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -4
app.py CHANGED
@@ -1,7 +1,25 @@
1
  import gradio as gr
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
 
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from diffusers import AutoPipelineForText2Image, DPMSolverMultistepScheduler
3
+ import torch
4
+ import matplotlib.pyplot as plt
5
 
6
+ # Load the model
7
+ def load_model():
8
+ pipe = AutoPipelineForText2Image.from_pretrained('lykon/dreamshaper-xl-v2-turbo', torch_dtype=torch.float16, variant="fp16")
9
+ pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
10
+ pipe = pipe.to("cuda")
11
+ return pipe
12
 
13
+ # Main function to generate image
14
+ def generate_image(prompt):
15
+ pipe = load_model()
16
+ generator = torch.manual_seed(0)
17
+ image = pipe(prompt, num_inference_steps=6, guidance_scale=2).images[0]
18
+ return image
19
+
20
+ # Define Gradio Interface
21
+ inputs = gr.inputs.Textbox(lines=5, label="Enter your text prompt")
22
+ output = gr.outputs.Image(label="Generated Image")
23
+
24
+ # Create Gradio Interface
25
+ gr.Interface(fn=generate_image, inputs=inputs, outputs=output, title="Text to Image Generation").launch()