File size: 812 Bytes
7a49396
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import os  # For accessing environment variables
from diffusers import StableDiffusionPipeline
import torch

# Load the token from Hugging Face secrets
HF_TOKEN = os.environ.get("HF_TOKEN")  # This fetches your secret!

# Load the model with your token
model_id = "runwayml/stable-diffusion-v1-5"
pipe = StableDiffusionPipeline.from_pretrained(
    model_id,
    use_auth_token=HF_TOKEN  # Authenticates using your secret
)
pipe = pipe.to("cuda")  # Uses Hugging Face's GPU

def generate_image(prompt):
    image = pipe(prompt).images[0]
    return image

# Gradio UI
app = gr.Interface(
    fn=generate_image,
    inputs=gr.Textbox(label="Describe your image..."),
    outputs=gr.Image(label="Generated Image"),
    title="Free AI Image Generator"
)

app.launch()