man08man commited on
Commit
7a49396
·
verified ·
1 Parent(s): f5da3ea

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py CHANGED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os # For accessing environment variables
3
+ from diffusers import StableDiffusionPipeline
4
+ import torch
5
+
6
+ # Load the token from Hugging Face secrets
7
+ HF_TOKEN = os.environ.get("HF_TOKEN") # This fetches your secret!
8
+
9
+ # Load the model with your token
10
+ model_id = "runwayml/stable-diffusion-v1-5"
11
+ pipe = StableDiffusionPipeline.from_pretrained(
12
+ model_id,
13
+ use_auth_token=HF_TOKEN # Authenticates using your secret
14
+ )
15
+ pipe = pipe.to("cuda") # Uses Hugging Face's GPU
16
+
17
+ def generate_image(prompt):
18
+ image = pipe(prompt).images[0]
19
+ return image
20
+
21
+ # Gradio UI
22
+ app = gr.Interface(
23
+ fn=generate_image,
24
+ inputs=gr.Textbox(label="Describe your image..."),
25
+ outputs=gr.Image(label="Generated Image"),
26
+ title="Free AI Image Generator"
27
+ )
28
+
29
+ app.launch()