File size: 1,221 Bytes
7b011af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from huggingface_hub import InferenceClient
from PIL import Image

# Function to generate an image from text using the Hugging Face Inference API
def generate_image(prompt, hf_token):
    # Initialize the InferenceClient with the model and API token
    client = InferenceClient("stabilityai/stable-diffusion-3.5-large", token=hf_token)
    
    # Use the client to generate an image from the text prompt
    image = client.text_to_image(prompt)
    
    # Return the generated image
    return image

# Define Gradio interface
iface = gr.Interface(
    fn=generate_image,  # Function to call
    inputs=[
        gr.Textbox(label="Enter your prompt", placeholder="Describe the image you want...", lines=2),
        gr.Textbox(label="Hugging Face API Token", placeholder="Enter your Hugging Face API token here...", type="password")
    ],
    outputs=gr.Image(type="pil", label="Generated Image"),
    live=True,  # Optionally enable live updates while typing
    title="Stable Diffusion 3.5 Image Generation",
    description="Generate images using Stable Diffusion 3.5 model by Stability AI. Enter a text prompt and your Hugging Face API token to get started."
)

# Launch Gradio app
iface.launch()