Spaces:
Sleeping
Sleeping
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() |