Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,14 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
|
13 |
# Initialize Hugging Face Inference Client
|
14 |
def get_client(model_name):
|
@@ -22,8 +22,19 @@ def generate_image(prompt, model_name):
|
|
22 |
|
23 |
# Gradio interface
|
24 |
with gr.Blocks() as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
gr.Markdown("# Text to Image Generator using Hugging Face Inference Client")
|
26 |
-
|
|
|
|
|
27 |
with gr.Row():
|
28 |
# Input for text prompt
|
29 |
prompt_input = gr.Textbox(label="Enter your prompt", placeholder="Describe the image you want...")
|
@@ -38,10 +49,39 @@ with gr.Blocks() as demo:
|
|
38 |
choices=list(model_options.keys()), # Display model names
|
39 |
value="FLUX 1.0 (black-forest-labs)", # Default model
|
40 |
)
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
with gr.Column():
|
43 |
# Image output
|
44 |
image_output = gr.Image(label="Generated Image")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
# Link the button click to the function
|
47 |
generate_button.click(generate_image, inputs=[prompt_input, model_dropdown], outputs=image_output)
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
4 |
+
|
5 |
+
|
6 |
+
def update_model(selected_model, use_textbox, custom_model):
|
7 |
+
if use_textbox:
|
8 |
+
return custom_model # Return the custom model from textbox
|
9 |
+
else:
|
10 |
+
return selected_model # Return the selected model from dropdown
|
11 |
+
|
12 |
|
13 |
# Initialize Hugging Face Inference Client
|
14 |
def get_client(model_name):
|
|
|
22 |
|
23 |
# Gradio interface
|
24 |
with gr.Blocks() as demo:
|
25 |
+
# List of available models (custom models included)
|
26 |
+
model_options = {
|
27 |
+
"Stable Diffusion 2": "stabilityai/stable-diffusion-2",
|
28 |
+
"Stable Diffusion 1.5": "runwayml/stable-diffusion-v1-5",
|
29 |
+
"DALL-E Mini": "dalle-mini/dalle-mini",
|
30 |
+
"FLUX 1.0 (black-forest-labs)": "black-forest-labs/FLUX.1-dev",
|
31 |
+
"Pony Diffusion V6": "John6666/pony-diffusion-v6-xl-sdxl-spo"
|
32 |
+
}
|
33 |
+
|
34 |
gr.Markdown("# Text to Image Generator using Hugging Face Inference Client")
|
35 |
+
with gr.Row():
|
36 |
+
use_textbox = gr.Checkbox(label="Use Custom Model", value=False)
|
37 |
+
|
38 |
with gr.Row():
|
39 |
# Input for text prompt
|
40 |
prompt_input = gr.Textbox(label="Enter your prompt", placeholder="Describe the image you want...")
|
|
|
49 |
choices=list(model_options.keys()), # Display model names
|
50 |
value="FLUX 1.0 (black-forest-labs)", # Default model
|
51 |
)
|
52 |
+
custom_model_textbox = gr.Textbox(label="Enter Custom Model", placeholder="Type your model name here")
|
53 |
+
|
54 |
+
output = gr.Textbox(label="Selected Model", interactive=False)
|
55 |
+
|
56 |
+
|
57 |
+
|
58 |
+
with gr.Row():
|
59 |
+
submit_button = gr.Button("Submit Option")
|
60 |
with gr.Column():
|
61 |
# Image output
|
62 |
image_output = gr.Image(label="Generated Image")
|
63 |
+
|
64 |
+
|
65 |
+
# Event to update the selected model based on the checkbox
|
66 |
+
use_textbox.change(
|
67 |
+
lambda checked: model_dropdown.update(visible=not checked, value=None),
|
68 |
+
inputs=[use_textbox],
|
69 |
+
outputs=[model_dropdown]
|
70 |
+
)
|
71 |
+
|
72 |
+
use_textbox.change(
|
73 |
+
lambda checked: custom_model_textbox.update(visible=checked, value=""),
|
74 |
+
inputs=[use_textbox],
|
75 |
+
outputs=[custom_model_textbox]
|
76 |
+
)
|
77 |
+
|
78 |
+
# Button to confirm selection
|
79 |
+
|
80 |
+
submit_button.click(
|
81 |
+
update_model,
|
82 |
+
inputs=[model_dropdown, use_textbox, custom_model_textbox],
|
83 |
+
outputs=[output]
|
84 |
+
)
|
85 |
|
86 |
# Link the button click to the function
|
87 |
generate_button.click(generate_image, inputs=[prompt_input, model_dropdown], outputs=image_output)
|