man08man commited on
Commit
d6b5bf1
·
verified ·
1 Parent(s): 27c73e7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -28
app.py CHANGED
@@ -1,29 +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()
 
1
+ import gradio as gr
2
+ import os
3
+ from diffusers import StableDiffusionPipeline
4
+ import torch
5
+
6
+ # Fetch the Hugging Face token from secrets
7
+ HF_TOKEN = os.environ.get("HF_TOKEN")
8
+
9
+ # Load the model
10
+ model_id = "runwayml/stable-diffusion-v1-5"
11
+ pipe = StableDiffusionPipeline.from_pretrained(
12
+ model_id,
13
+ use_auth_token=HF_TOKEN
14
+ )
15
+ pipe = pipe.to("cuda") # Use 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()