my-static-app / app.py
man08man's picture
Upload app.py
7a49396 verified
raw
history blame
812 Bytes
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()