Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,44 +1,11 @@
|
|
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
|
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(
|
27 |
-
prompt=prompt,
|
28 |
-
negative_prompt="blurred, ugly, watermark, low, resolution, blurry",
|
29 |
-
num_inference_steps=40,
|
30 |
-
height=1024,
|
31 |
-
width=1024,
|
32 |
-
guidance_scale=9.0
|
33 |
-
).images[0]
|
34 |
-
|
35 |
-
return image
|
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()
|
|
|
1 |
import os
|
|
|
|
|
2 |
from huggingface_hub import login
|
|
|
3 |
|
4 |
+
# Get Hugging Face token from environment variables
|
5 |
hf_token = os.getenv("HF_API_TOKEN")
|
6 |
|
|
|
7 |
if hf_token:
|
8 |
login(token=hf_token)
|
9 |
+
print("lgin sucessfull")
|
10 |
else:
|
11 |
raise ValueError("Hugging Face token is missing. Please set it in the environment variables.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|