Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,9 @@
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
import torch
|
4 |
-
|
5 |
-
|
|
|
6 |
import spaces
|
7 |
from PIL import Image
|
8 |
import requests
|
@@ -13,18 +14,7 @@ translator = Translator()
|
|
13 |
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
14 |
# Constants
|
15 |
model = "stabilityai/stable-diffusion-3-medium"
|
16 |
-
|
17 |
-
|
18 |
-
model_path = snapshot_download(
|
19 |
-
repo_id=model,
|
20 |
-
revision="refs/pr/26",
|
21 |
-
repo_type="model",
|
22 |
-
ignore_patterns=["*.md", "*..gitattributes"],
|
23 |
-
local_dir="model",
|
24 |
-
token=HF_TOKEN,
|
25 |
-
)
|
26 |
-
|
27 |
-
|
28 |
|
29 |
CSS = """
|
30 |
.gradio-container {
|
@@ -47,7 +37,7 @@ JS = """function () {
|
|
47 |
|
48 |
# Ensure model and scheduler are initialized in GPU-enabled function
|
49 |
if torch.cuda.is_available():
|
50 |
-
pipe = StableDiffusion3Pipeline.from_pretrained(
|
51 |
|
52 |
|
53 |
# Function
|
@@ -60,6 +50,10 @@ def generate_image(
|
|
60 |
scale=1.5,
|
61 |
steps=30,
|
62 |
clip=3):
|
|
|
|
|
|
|
|
|
63 |
|
64 |
prompt = str(translator.translate(prompt, 'English'))
|
65 |
|
@@ -73,6 +67,7 @@ def generate_image(
|
|
73 |
guidance_scale=scale,
|
74 |
num_inference_steps=steps,
|
75 |
clip_skip=clip,
|
|
|
76 |
)
|
77 |
return image.images[0]
|
78 |
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
import torch
|
4 |
+
import numpy as np
|
5 |
+
import random
|
6 |
+
from diffusers import StableDiffusion3Pipeline, SD3Transformer2DModel, FlowMatchEulerDiscreteScheduler
|
7 |
import spaces
|
8 |
from PIL import Image
|
9 |
import requests
|
|
|
14 |
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
15 |
# Constants
|
16 |
model = "stabilityai/stable-diffusion-3-medium"
|
17 |
+
MAX_SEED = np.iinfo(np.int32).max
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
CSS = """
|
20 |
.gradio-container {
|
|
|
37 |
|
38 |
# Ensure model and scheduler are initialized in GPU-enabled function
|
39 |
if torch.cuda.is_available():
|
40 |
+
pipe = StableDiffusion3Pipeline.from_pretrained(model, torch_dtype=torch.float16, revision="refs/pr/26").to("cuda")
|
41 |
|
42 |
|
43 |
# Function
|
|
|
50 |
scale=1.5,
|
51 |
steps=30,
|
52 |
clip=3):
|
53 |
+
|
54 |
+
|
55 |
+
seed = random.randint(0, MAX_SEED)
|
56 |
+
generator = torch.Generator().manual_seed(seed)
|
57 |
|
58 |
prompt = str(translator.translate(prompt, 'English'))
|
59 |
|
|
|
67 |
guidance_scale=scale,
|
68 |
num_inference_steps=steps,
|
69 |
clip_skip=clip,
|
70 |
+
generator = generator,
|
71 |
)
|
72 |
return image.images[0]
|
73 |
|