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