Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,7 @@ import spaces
|
|
8 |
from PIL import Image
|
9 |
import requests
|
10 |
import transformers
|
11 |
-
from transformers import T5EncoderModel
|
12 |
from translatepy import Translator
|
13 |
|
14 |
os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
|
@@ -54,9 +54,15 @@ text_encoder_3 = T5EncoderModel.from_pretrained(
|
|
54 |
torch_dtype=torch.float16,
|
55 |
)
|
56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
# Ensure model and scheduler are initialized in GPU-enabled function
|
58 |
if torch.cuda.is_available():
|
59 |
-
pipe = StableDiffusion3Pipeline.from_pretrained(repo, vae=vae, transformer=transformer, text_encoder_3=text_encoder_3, torch_dtype=torch.float16).to("cuda")
|
60 |
|
61 |
pipe.scheduler = FlowMatchEulerDiscreteScheduler.from_config(pipe.scheduler.config)
|
62 |
|
@@ -73,14 +79,23 @@ def generate_image(
|
|
73 |
|
74 |
if seed == -1:
|
75 |
seed = random.randint(0, MAX_SEED)
|
76 |
-
generator = torch.Generator().manual_seed(seed)
|
77 |
|
78 |
-
prompt = str(translator.translate(prompt, 'English'))
|
79 |
-
|
80 |
print(f'prompt:{prompt}')
|
81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
image = pipe(
|
83 |
-
|
|
|
84 |
negative_prompt=negative,
|
85 |
width=width,
|
86 |
height=height,
|
@@ -109,10 +124,10 @@ examples = [
|
|
109 |
|
110 |
with gr.Blocks(css=CSS, js=JS, theme="soft") as demo:
|
111 |
gr.HTML("<h1><center>SD3M🦄</center></h1>")
|
112 |
-
gr.HTML("<p><center><a href='https://huggingface.co/stabilityai/stable-diffusion-3-medium'>sd3m</a> text-to-image generation</center></p>")
|
113 |
with gr.Group():
|
114 |
with gr.Row():
|
115 |
-
prompt = gr.
|
116 |
submit = gr.Button(scale=1, variant='primary')
|
117 |
img = gr.Image(label='SD3M Generated Image')
|
118 |
with gr.Accordion("Advanced Options", open=False):
|
|
|
8 |
from PIL import Image
|
9 |
import requests
|
10 |
import transformers
|
11 |
+
from transformers import AutoTokenizer, T5EncoderModel
|
12 |
from translatepy import Translator
|
13 |
|
14 |
os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
|
|
|
54 |
torch_dtype=torch.float16,
|
55 |
)
|
56 |
|
57 |
+
tokenizer_3 = AutoTokenizer.from_pretrained(
|
58 |
+
repo,
|
59 |
+
subfolder="tokenizer_3",
|
60 |
+
torch_dtype=torch.float16,
|
61 |
+
)
|
62 |
+
|
63 |
# Ensure model and scheduler are initialized in GPU-enabled function
|
64 |
if torch.cuda.is_available():
|
65 |
+
pipe = StableDiffusion3Pipeline.from_pretrained(repo, vae=vae, transformer=transformer, tokenizer_3=tokenizer_3, text_encoder_3=text_encoder_3, torch_dtype=torch.float16).to("cuda")
|
66 |
|
67 |
pipe.scheduler = FlowMatchEulerDiscreteScheduler.from_config(pipe.scheduler.config)
|
68 |
|
|
|
79 |
|
80 |
if seed == -1:
|
81 |
seed = random.randint(0, MAX_SEED)
|
|
|
82 |
|
|
|
|
|
83 |
print(f'prompt:{prompt}')
|
84 |
|
85 |
+
text = str(translator.translate(prompt['text'], 'English'))
|
86 |
+
|
87 |
+
|
88 |
+
if prompt['files']:
|
89 |
+
images = Image.open(prompt['files'][-1]).convert('RGB')
|
90 |
+
else:
|
91 |
+
images = None
|
92 |
+
generator = torch.Generator().manual_seed(seed)
|
93 |
+
|
94 |
+
|
95 |
+
|
96 |
image = pipe(
|
97 |
+
text,
|
98 |
+
image=images,
|
99 |
negative_prompt=negative,
|
100 |
width=width,
|
101 |
height=height,
|
|
|
124 |
|
125 |
with gr.Blocks(css=CSS, js=JS, theme="soft") as demo:
|
126 |
gr.HTML("<h1><center>SD3M🦄</center></h1>")
|
127 |
+
gr.HTML("<p><center><a href='https://huggingface.co/stabilityai/stable-diffusion-3-medium'>sd3m</a> text/img-to-image generation</center></p>")
|
128 |
with gr.Group():
|
129 |
with gr.Row():
|
130 |
+
prompt = gr.MultimodalTextbox(label='Enter Your Prompt (Multi-Languages)', value="best quality, HD", file_types=['image'], scale=6)
|
131 |
submit = gr.Button(scale=1, variant='primary')
|
132 |
img = gr.Image(label='SD3M Generated Image')
|
133 |
with gr.Accordion("Advanced Options", open=False):
|