Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from huggingface_hub import InferenceClient
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
# Function to generate an image from text using the Hugging Face Inference API
|
6 |
+
def generate_image(prompt, hf_token):
|
7 |
+
# Initialize the InferenceClient with the model and API token
|
8 |
+
client = InferenceClient("stabilityai/stable-diffusion-3.5-large", token=hf_token)
|
9 |
+
|
10 |
+
# Use the client to generate an image from the text prompt
|
11 |
+
image = client.text_to_image(prompt)
|
12 |
+
|
13 |
+
# Return the generated image
|
14 |
+
return image
|
15 |
+
|
16 |
+
# Define Gradio interface
|
17 |
+
iface = gr.Interface(
|
18 |
+
fn=generate_image, # Function to call
|
19 |
+
inputs=[
|
20 |
+
gr.Textbox(label="Enter your prompt", placeholder="Describe the image you want...", lines=2),
|
21 |
+
gr.Textbox(label="Hugging Face API Token", placeholder="Enter your Hugging Face API token here...", type="password")
|
22 |
+
],
|
23 |
+
outputs=gr.Image(type="pil", label="Generated Image"),
|
24 |
+
live=True, # Optionally enable live updates while typing
|
25 |
+
title="Stable Diffusion 3.5 Image Generation",
|
26 |
+
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."
|
27 |
+
)
|
28 |
+
|
29 |
+
# Launch Gradio app
|
30 |
+
iface.launch()
|