Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -14,7 +14,6 @@ from PIL import Image
|
|
14 |
from transformers import pipeline
|
15 |
import base64
|
16 |
|
17 |
-
|
18 |
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
|
19 |
|
20 |
# Hugging Face ํ ํฐ ์ค์
|
@@ -124,7 +123,7 @@ def process_and_save_image(height=1024, width=1024, steps=8, scales=3.5, prompt=
|
|
124 |
translated = translator(prompt)[0]['translation_text']
|
125 |
prompt = translated
|
126 |
|
127 |
-
formatted_prompt = f"wbgmsst, 3D, {prompt}
|
128 |
|
129 |
with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16), timer("inference"):
|
130 |
try:
|
@@ -147,19 +146,9 @@ def process_and_save_image(height=1024, width=1024, steps=8, scales=3.5, prompt=
|
|
147 |
print(f"Error in image generation: {str(e)}")
|
148 |
return None
|
149 |
|
150 |
-
def generate_image(h, w, s, sc, p, sd):
|
151 |
-
"""Gradio์์ ๋๊ฒจ๋ฐ์ ํ๋ผ๋ฏธํฐ ์์์ ๋ง์ถฐ ์ด๋ฏธ์ง ์์ฑ ํจ์ ํธ์ถ"""
|
152 |
-
return process_and_save_image(
|
153 |
-
height=h,
|
154 |
-
width=w,
|
155 |
-
steps=s,
|
156 |
-
scales=sc,
|
157 |
-
prompt=p,
|
158 |
-
seed=sd
|
159 |
-
)
|
160 |
-
|
161 |
def update_random_seed():
|
162 |
-
|
|
|
163 |
|
164 |
# Gradio ์ธํฐํ์ด์ค
|
165 |
with gr.Blocks(
|
@@ -270,12 +259,12 @@ with gr.Blocks(
|
|
270 |
value="3d.webp"
|
271 |
)
|
272 |
|
273 |
-
# Gallery ์น์
|
274 |
with gr.Row(elem_classes="gallery-container"):
|
275 |
gr.HTML("<h2 class='gallery-title'>Gallery</h2>")
|
276 |
gallery_html = "<div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px;'>"
|
277 |
|
278 |
-
for img_file,
|
279 |
img_path = os.path.abspath(img_file) # ์ ๋ ๊ฒฝ๋ก๋ก ๋ณํ
|
280 |
if os.path.exists(img_path):
|
281 |
try:
|
@@ -283,6 +272,7 @@ with gr.Blocks(
|
|
283 |
with open(img_path, "rb") as img:
|
284 |
img_data = base64.b64encode(img.read()).decode()
|
285 |
|
|
|
286 |
gallery_html += f"""
|
287 |
<div style='
|
288 |
border: 1px solid #ddd;
|
@@ -301,7 +291,7 @@ with gr.Blocks(
|
|
301 |
font-weight: bold;
|
302 |
color: #333;
|
303 |
padding: 10px;
|
304 |
-
'>Prompt: {
|
305 |
</div>
|
306 |
"""
|
307 |
except Exception as e:
|
@@ -310,31 +300,10 @@ with gr.Blocks(
|
|
310 |
gallery_html += "</div>"
|
311 |
gr.HTML(gallery_html)
|
312 |
|
313 |
-
# ์ด๋ฒคํธ ํธ๋ค๋ฌ
|
314 |
-
def generate_image(h, w, s, sc, p, sd):
|
315 |
-
return process_and_save_image(
|
316 |
-
height=h,
|
317 |
-
width=w,
|
318 |
-
steps=s,
|
319 |
-
scales=sc,
|
320 |
-
prompt=p,
|
321 |
-
seed=sd
|
322 |
-
)
|
323 |
-
|
324 |
-
def update_random_seed():
|
325 |
-
return gr.update(value=get_random_seed())
|
326 |
-
|
327 |
-
# ์ด๋ฒคํธ ๋ฐ์ธ๋ฉ
|
328 |
generate_btn.click(
|
329 |
-
fn=process_and_save_image,
|
330 |
-
inputs=
|
331 |
-
"height": height,
|
332 |
-
"width": width,
|
333 |
-
"steps": steps,
|
334 |
-
"scales": scales,
|
335 |
-
"prompt": prompt,
|
336 |
-
"seed": seed
|
337 |
-
},
|
338 |
outputs=output
|
339 |
)
|
340 |
|
@@ -345,4 +314,4 @@ with gr.Blocks(
|
|
345 |
)
|
346 |
|
347 |
if __name__ == "__main__":
|
348 |
-
demo.launch(allowed_paths=[PERSISTENT_DIR])
|
|
|
14 |
from transformers import pipeline
|
15 |
import base64
|
16 |
|
|
|
17 |
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
|
18 |
|
19 |
# Hugging Face ํ ํฐ ์ค์
|
|
|
123 |
translated = translator(prompt)[0]['translation_text']
|
124 |
prompt = translated
|
125 |
|
126 |
+
formatted_prompt = f"wbgmsst, 3D, {prompt}, white background"
|
127 |
|
128 |
with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16), timer("inference"):
|
129 |
try:
|
|
|
146 |
print(f"Error in image generation: {str(e)}")
|
147 |
return None
|
148 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
def update_random_seed():
|
150 |
+
"""๋ฒํผ์ผ๋ก ๋๋ ์ ๋ ์๋ก์ด ์๋๋ฅผ ์
๋ฐ์ดํธ"""
|
151 |
+
return gr.update(value=get_random_seed())
|
152 |
|
153 |
# Gradio ์ธํฐํ์ด์ค
|
154 |
with gr.Blocks(
|
|
|
259 |
value="3d.webp"
|
260 |
)
|
261 |
|
262 |
+
# Gallery ์น์
|
263 |
with gr.Row(elem_classes="gallery-container"):
|
264 |
gr.HTML("<h2 class='gallery-title'>Gallery</h2>")
|
265 |
gallery_html = "<div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px;'>"
|
266 |
|
267 |
+
for img_file, prompt_text in SAMPLE_IMAGES.items():
|
268 |
img_path = os.path.abspath(img_file) # ์ ๋ ๊ฒฝ๋ก๋ก ๋ณํ
|
269 |
if os.path.exists(img_path):
|
270 |
try:
|
|
|
272 |
with open(img_path, "rb") as img:
|
273 |
img_data = base64.b64encode(img.read()).decode()
|
274 |
|
275 |
+
# 3d1.webp ํ์ผ์ด๋ฏ๋ก MIMEํ์
์ webp
|
276 |
gallery_html += f"""
|
277 |
<div style='
|
278 |
border: 1px solid #ddd;
|
|
|
291 |
font-weight: bold;
|
292 |
color: #333;
|
293 |
padding: 10px;
|
294 |
+
'>Prompt: {prompt_text}</p>
|
295 |
</div>
|
296 |
"""
|
297 |
except Exception as e:
|
|
|
300 |
gallery_html += "</div>"
|
301 |
gr.HTML(gallery_html)
|
302 |
|
303 |
+
# ์ด๋ฒคํธ ํธ๋ค๋ฌ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
304 |
generate_btn.click(
|
305 |
+
fn=process_and_save_image,
|
306 |
+
inputs=[height, width, steps, scales, prompt, seed], # ๋์
๋๋ฆฌ ๋์ ๋ฆฌ์คํธ ํํ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
307 |
outputs=output
|
308 |
)
|
309 |
|
|
|
314 |
)
|
315 |
|
316 |
if __name__ == "__main__":
|
317 |
+
demo.launch(allowed_paths=[PERSISTENT_DIR])
|