Spaces:
Running
Running
broadfield-dev
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from huggingface_hub import InferenceClient
|
3 |
+
|
4 |
+
# List of models and their corresponding names
|
5 |
+
models = [
|
6 |
+
"CompVis/stable-diffusion-v1-4",
|
7 |
+
"runwayml/stable-diffusion-v1-5",
|
8 |
+
"hakurei/waifu-diffusion",
|
9 |
+
"prompthero/openjourney",
|
10 |
+
"jacek-huszar/$(IMG2TEXT_MODEL_NAME)",
|
11 |
+
"cjwbw/canvae-text-to-image",
|
12 |
+
"tdbooth/hollow-kingdom-ddim",
|
13 |
+
"kuprel/min-dalle",
|
14 |
+
"osanseviero/stable-diffusion-webui",
|
15 |
+
"lambdal/text-to-image"
|
16 |
+
]
|
17 |
+
|
18 |
+
def generate_image(prompt, model_name):
|
19 |
+
client = InferenceClient(model_name)
|
20 |
+
response = client.text_to_image(prompt)
|
21 |
+
return response.image
|
22 |
+
|
23 |
+
# Create Gradio Interface
|
24 |
+
with gr.Blocks() as demo:
|
25 |
+
gr.Markdown("## Text-to-Image Generation with Hugging Face Models")
|
26 |
+
with gr.Row():
|
27 |
+
with gr.Column():
|
28 |
+
model_dropdown = gr.Dropdown(models, label="Select Model")
|
29 |
+
prompt_input = gr.Textbox(label="Enter Text Prompt")
|
30 |
+
generate_button = gr.Button("Generate Image")
|
31 |
+
with gr.Column():
|
32 |
+
output_image = gr.Image(label="Generated Image")
|
33 |
+
|
34 |
+
generate_button.click(generate_image, inputs=[prompt_input, model_dropdown], outputs=output_image)
|
35 |
+
|
36 |
+
# Launch the interface
|
37 |
+
demo.launch()
|