Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from huggingface_hub import InferenceClient
|
3 |
+
|
4 |
+
# List of available models (custom models included)
|
5 |
+
model_options = {
|
6 |
+
"Stable Diffusion 2": "stabilityai/stable-diffusion-2",
|
7 |
+
"Stable Diffusion 1.5": "runwayml/stable-diffusion-v1-5",
|
8 |
+
"DALL-E Mini": "dalle-mini/dalle-mini",
|
9 |
+
"FLUX 1.0 (black-forest-labs)": "black-forest-labs/FLUX.1-dev",
|
10 |
+
"Pony Diffusion": "AstraliteHeart/ponydiffusion"
|
11 |
+
}
|
12 |
+
|
13 |
+
# Initialize Hugging Face Inference Client
|
14 |
+
def get_client(model_name):
|
15 |
+
return InferenceClient(model=model_name)
|
16 |
+
|
17 |
+
# Function to generate the image based on selected model and prompt
|
18 |
+
def generate_image(prompt, model_name):
|
19 |
+
client = get_client(model_options[model_name])
|
20 |
+
response = client.text_to_image(prompt, guidance_scale=7.5)
|
21 |
+
return response
|
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 |
+
with gr.Column():
|
29 |
+
# Dropdown for model selection
|
30 |
+
model_dropdown = gr.Dropdown(
|
31 |
+
label="Select Model",
|
32 |
+
choices=list(model_options.keys()), # Display model names
|
33 |
+
value="Stable Diffusion 2", # Default model
|
34 |
+
)
|
35 |
+
|
36 |
+
# Input for text prompt
|
37 |
+
prompt_input = gr.Textbox(label="Enter your prompt", placeholder="Describe the image you want...")
|
38 |
+
|
39 |
+
# Button to generate image
|
40 |
+
generate_button = gr.Button("Generate Image")
|
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)
|
48 |
+
|
49 |
+
# Launch the Gradio app
|
50 |
+
demo.launch()
|