Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,29 @@
|
|
1 |
from diffusers import StableDiffusionPipeline
|
2 |
import torch
|
3 |
-
|
4 |
-
modelieo=[
|
5 |
-
'naclbit/trinart_stable_diffusion_v2',
|
6 |
-
]
|
7 |
-
|
8 |
-
|
9 |
-
def TextToImage(Prompt,model):
|
10 |
-
model_id = model
|
11 |
-
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
12 |
-
pipe = pipe.to("cpu")
|
13 |
-
|
14 |
-
prompt = Prompt
|
15 |
-
image = pipe(prompt).images[0]
|
16 |
-
|
17 |
-
return image
|
18 |
-
|
19 |
-
|
20 |
import gradio as gr
|
21 |
-
interface = gr.Interface(fn=TextToImage,
|
22 |
-
inputs=["text", gr.Dropdown(modelieo)],
|
23 |
-
outputs="image",
|
24 |
-
title='Text to Image')
|
25 |
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from diffusers import StableDiffusionPipeline
|
2 |
import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
import gradio as gr
|
|
|
|
|
|
|
|
|
4 |
|
5 |
+
# Load the model
|
6 |
+
model_id = "CompVis/stable-diffusion-v-1-4-original"
|
7 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_id)
|
8 |
+
pipe = pipe.to("cuda") # Use GPU if available
|
9 |
+
|
10 |
+
def generate_image(prompt):
|
11 |
+
image = pipe(prompt).images[0]
|
12 |
+
return image
|
13 |
+
|
14 |
+
# Define the chatbot function
|
15 |
+
def chatbot(prompt):
|
16 |
+
image = generate_image(prompt)
|
17 |
+
return image
|
18 |
+
|
19 |
+
# Create the Gradio interface
|
20 |
+
interface = gr.Interface(
|
21 |
+
fn=chatbot,
|
22 |
+
inputs="text",
|
23 |
+
outputs="image",
|
24 |
+
title="Text to Image Chatbot",
|
25 |
+
description="Generate images from text using Stable Diffusion"
|
26 |
+
)
|
27 |
+
|
28 |
+
# Launch the interface
|
29 |
+
interface.launch()
|