Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,25 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|