File size: 1,321 Bytes
a1c995c
 
 
bcb28b5
207598c
a1c995c
 
 
 
 
 
719c01b
a1c995c
 
 
 
 
 
3561e6d
207598c
a1c995c
 
bcb28b5
 
 
 
 
 
 
 
3561e6d
a1c995c
 
 
 
bcb28b5
 
a1c995c
 
bcb28b5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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()