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