Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,26 @@
|
|
|
|
1 |
import torch
|
2 |
import gradio as gr
|
|
|
3 |
from diffusers import StableDiffusion3Pipeline
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
def image_generator(prompt):
|
7 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
8 |
-
pipeline = StableDiffusion3Pipeline.from_pretrained(
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
13 |
pipeline.to(device)
|
14 |
|
15 |
image = pipeline(
|
@@ -25,9 +36,9 @@ def image_generator(prompt):
|
|
25 |
|
26 |
interface = gr.Interface(
|
27 |
fn=image_generator,
|
28 |
-
inputs=gr.Textbox(lines=2, placeholder
|
29 |
-
outputs=gr.Image(type
|
30 |
-
title
|
31 |
-
description
|
|
|
32 |
interface.launch()
|
33 |
-
print(interface)
|
|
|
1 |
+
import os
|
2 |
import torch
|
3 |
import gradio as gr
|
4 |
+
from huggingface_hub import login
|
5 |
from diffusers import StableDiffusion3Pipeline
|
6 |
+
|
7 |
+
# Get the Hugging Face token from environment variables
|
8 |
+
hf_token = os.getenv("HF_API_TOKEN")
|
9 |
+
|
10 |
+
# Authenticate with the token
|
11 |
+
if hf_token:
|
12 |
+
login(token=hf_token)
|
13 |
+
else:
|
14 |
+
raise ValueError("Hugging Face token is missing. Please set it in the environment variables.")
|
15 |
|
16 |
def image_generator(prompt):
|
17 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
18 |
+
pipeline = StableDiffusion3Pipeline.from_pretrained(
|
19 |
+
"stabilityai/stable-diffusion-3-medium-diffusers",
|
20 |
+
torch_dtype=torch.float16 if device == "cuda" else torch.float32,
|
21 |
+
text_encoder_3=None,
|
22 |
+
tokenizer_3=None
|
23 |
+
)
|
24 |
pipeline.to(device)
|
25 |
|
26 |
image = pipeline(
|
|
|
36 |
|
37 |
interface = gr.Interface(
|
38 |
fn=image_generator,
|
39 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter your prompt..."),
|
40 |
+
outputs=gr.Image(type="pil"),
|
41 |
+
title="Image Generator App",
|
42 |
+
description="This is a simple image generator app using HuggingFace's Stable Diffusion 3 model."
|
43 |
+
)
|
44 |
interface.launch()
|
|