File size: 650 Bytes
d6b5bf1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from diffusers import StableDiffusionPipeline
import torch

# Fetch the Hugging Face token from secrets
HF_TOKEN = os.environ.get("HF_TOKEN")

# Load the model
model_id = "runwayml/stable-diffusion-v1-5"
pipe = StableDiffusionPipeline.from_pretrained(
    model_id,
    use_auth_token=HF_TOKEN
)
pipe = pipe.to("cuda")  # Use 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()