Spaces:
Runtime error
Runtime error
AbdalrhmanRi
commited on
Upload text2img.py
Browse files- text2img.py +35 -0
text2img.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from diffusers import AutoPipelineForText2Image
|
3 |
+
import gradio as gr
|
4 |
+
import peft
|
5 |
+
|
6 |
+
MODEL_NAME = "stabilityai/sdxl-turbo"
|
7 |
+
|
8 |
+
pipe = AutoPipelineForText2Image.from_pretrained(MODEL_NAME, torch_dtype=torch.float16, variant="fp16")
|
9 |
+
pipe.to("cuda")
|
10 |
+
|
11 |
+
pipe.load_lora_weights("SDXL-Turbo-fineTuned/", weight_name="pytorch_lora_weights.safetensors")
|
12 |
+
|
13 |
+
def generate_image(prompt):
|
14 |
+
image = pipe(prompt=prompt, guidance_scale=2.0, num_inference_steps=40, height=480)
|
15 |
+
image = image.images[0]
|
16 |
+
|
17 |
+
yield image, None
|
18 |
+
|
19 |
+
refiner_image = pipe(prompt=prompt, image=image, guidance_scale=1.0, height=480)
|
20 |
+
refiner_image = refiner_image.images[0]
|
21 |
+
|
22 |
+
yield image, refiner_image
|
23 |
+
|
24 |
+
|
25 |
+
# Set up the Gradio interface
|
26 |
+
interface = gr.Interface(
|
27 |
+
fn=generate_image,
|
28 |
+
inputs=gr.components.Textbox(label="Prompt", lines=2, placeholder="Enter your prompt here..."),
|
29 |
+
outputs=[gr.Image(type="pil", label="Generated Image"), gr.Image(type="pil", label="Refined Image")],
|
30 |
+
title="Generate Image Using Generative AI",
|
31 |
+
theme=gr.themes.Default(primary_hue="green")
|
32 |
+
)
|
33 |
+
|
34 |
+
# Launch the interface
|
35 |
+
interface.launch()
|