Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,27 @@
|
|
1 |
-
import gradio as gr
|
2 |
import torch
|
3 |
-
from diffusers import
|
|
|
4 |
|
5 |
-
|
6 |
-
pipe =
|
7 |
-
pipe.to("cpu")
|
8 |
|
9 |
def generate_image(prompt):
|
10 |
-
image = pipe(
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
num_inference_steps=50,
|
16 |
-
max_sequence_length=512,
|
17 |
-
generator=torch.Generator("cpu").manual_seed(0)
|
18 |
-
).images[0]
|
19 |
return image
|
20 |
|
21 |
-
# Create the
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
"image",
|
26 |
-
title="
|
27 |
-
description="
|
28 |
)
|
29 |
|
30 |
-
# Launch the
|
31 |
-
|
|
|
|
|
1 |
import torch
|
2 |
+
from diffusers import StableDiffusionPipeline
|
3 |
+
import gradio as gr
|
4 |
|
5 |
+
model_id = "SG161222/RealVisXL_V4.0"
|
6 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
7 |
+
pipe.to("cpu") # Use "cuda" if GPU is available
|
8 |
|
9 |
def generate_image(prompt):
|
10 |
+
image = pipe(prompt).images[0]
|
11 |
+
return image
|
12 |
+
def chatbot(prompt):
|
13 |
+
# Generate the image based on the user's input
|
14 |
+
image = generate_image(prompt)
|
|
|
|
|
|
|
|
|
15 |
return image
|
16 |
|
17 |
+
# Create the Gradio interface
|
18 |
+
interface = gr.Interface(
|
19 |
+
fn=chatbot,
|
20 |
+
inputs="text",
|
21 |
+
outputs="image",
|
22 |
+
title="RealVisXL V4.0 Text-to-Image Chatbot",
|
23 |
+
description="Enter a text prompt and get an AI-generated image."
|
24 |
)
|
25 |
|
26 |
+
# Launch the interface
|
27 |
+
interface.launch()
|