Spaces:
Runtime error
Runtime error
import gradio as gr | |
from huggingface_hub import InferenceClient | |
# Initialize Hugging Face Inference Client | |
def get_client(model_name): | |
return InferenceClient(model=model_name) | |
# Function to generate the image based on selected model and prompt | |
def generate_image(prompt, model_name): | |
client = get_client(model_name) | |
response = client.text_to_image(prompt, guidance_scale=7.5) | |
return response | |
# Gradio interface | |
with gr.Blocks() as demo: | |
gr.Markdown("# Text to Image Generator using Hugging Face Inference Client") | |
with gr.Row(): | |
with gr.Column(): | |
# Dropdown for model selection | |
prompt_model = gr.Textbox(label="Enter your prompt", placeholder="your model...") | |
# Input for text prompt | |
prompt_input = gr.Textbox(label="Enter your prompt", placeholder="Describe the image you want...") | |
# Button to generate image | |
generate_button = gr.Button("Generate Image") | |
with gr.Column(): | |
# Image output | |
image_output = gr.Image(label="Generated Image") | |
# Link the button click to the function | |
generate_button.click(generate_image, inputs=[prompt_model, prompt_input], outputs=image_output) | |
# Launch the Gradio app | |
demo.launch() | |