Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,3 @@
|
|
1 |
-
|
2 |
-
|
3 |
import os
|
4 |
import gradio as gr
|
5 |
import random
|
@@ -44,10 +42,7 @@ def choose_alternative(transformation):
|
|
44 |
else:
|
45 |
return random.choice([left, right])
|
46 |
|
47 |
-
# μ°½μμ μΈ λͺ¨λΈ/컨μ
/νμ λ³ν μμ΄λμ΄λ₯Ό μν μΉ΄ν
κ³ λ¦¬
|
48 |
-
|
49 |
-
|
50 |
-
# μ°½μμ μΈ λͺ¨λΈ/컨μ
/νμ λ³ν μμ΄λμ΄λ₯Ό μν μΉ΄ν
κ³ λ¦¬ (κΈ°μ‘΄ '물리μ λ³ν' μ¬μ μ μ§)
|
51 |
physical_transformation_categories = {
|
52 |
"κ³΅κ° μ΄λ": [
|
53 |
"μ/λ€ μ΄λ", "μ’/μ° μ΄λ", "μ/μλ μ΄λ", "μΈλ‘μΆ νμ (κ³ κ° λλμ)",
|
@@ -287,7 +282,6 @@ def generate_three_objects_interaction(obj1, obj2, obj3):
|
|
287 |
# μμ±λ κΈ°λ³Έ μ€λͺ
μ LLMμ ν΅ν΄ νμ₯
|
288 |
##############################################################################
|
289 |
def enhance_descriptions(results, objects):
|
290 |
-
# progress μΈμ μ κ±°
|
291 |
obj_name = " λ° ".join([obj for obj in objects if obj])
|
292 |
|
293 |
for category, result in results.items():
|
@@ -299,8 +293,6 @@ def enhance_descriptions(results, objects):
|
|
299 |
# μ¬μ©μ μ
λ ₯(μ΅λ 3κ° ν€μλ)μ λ°λΌ μ°½μμ λ³ν μμ΄λμ΄ μμ±
|
300 |
##############################################################################
|
301 |
def generate_transformations(text1, text2=None, text3=None):
|
302 |
-
# progress μΈμ μ κ±°
|
303 |
-
|
304 |
if text2 and text3:
|
305 |
results = generate_three_objects_interaction(text1, text2, text3)
|
306 |
objects = [text1, text2, text3]
|
@@ -325,7 +317,7 @@ def format_results(results):
|
|
325 |
##############################################################################
|
326 |
# Gradio UIμμ νΈμΆν ν¨μ
|
327 |
##############################################################################
|
328 |
-
def process_inputs(text1, text2, text3, progress=gr.Progress()):
|
329 |
text1 = text1.strip() if text1 else None
|
330 |
text2 = text2.strip() if text2 else None
|
331 |
text3 = text3.strip() if text3 else None
|
@@ -333,36 +325,30 @@ def process_inputs(text1, text2, text3, progress=gr.Progress()):
|
|
333 |
if not text1:
|
334 |
return "μ€λ₯: μ΅μ νλμ ν€μλλ₯Ό μ
λ ₯ν΄μ£ΌμΈμ."
|
335 |
|
336 |
-
# μ§ν μν λ©μμ§ (μ€μ²© 리μ€νΈ λμ λ¨μ λ¬Έμμ΄ μ¬μ©)
|
337 |
-
status_message = ""
|
338 |
-
|
339 |
-
# ν€μλ μ 보 νμΈ
|
340 |
keyword_info = f"ν€μλ: {text1}"
|
341 |
if text2:
|
342 |
keyword_info += f", {text2}"
|
343 |
if text3:
|
344 |
keyword_info += f", {text3}"
|
345 |
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
results =
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
logger.error(f"Error in process_inputs: {e}")
|
365 |
-
return f"μ²λ¦¬ μ€ μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}"
|
366 |
|
367 |
##############################################################################
|
368 |
# API ν€ κ²½κ³ λ©μμ§
|
@@ -392,7 +378,7 @@ with gr.Blocks(title="ν€μλ κΈ°λ° μ°½μμ λ³ν μμ΄λμ΄ μμ±κΈ°",
|
|
392 |
""")
|
393 |
|
394 |
gr.Markdown("# π ν€μλ κΈ°λ° μ°½μμ λ³ν μμ΄λμ΄ μμ±κΈ°")
|
395 |
-
gr.Markdown("μ
λ ₯ν **ν€μλ**(μ΅λ 3κ°)
|
396 |
|
397 |
warning = gr.Markdown(get_warning_message())
|
398 |
|
@@ -402,11 +388,16 @@ with gr.Blocks(title="ν€μλ κΈ°λ° μ°½μμ λ³ν μμ΄λμ΄ μμ±κΈ°",
|
|
402 |
text_input1 = gr.Textbox(label="ν€μλ 1 (νμ)", placeholder="μ: μ€λ§νΈν°")
|
403 |
text_input2 = gr.Textbox(label="ν€μλ 2 (μ ν)", placeholder="μ: μΈκ³΅μ§λ₯")
|
404 |
text_input3 = gr.Textbox(label="ν€μλ 3 (μ ν)", placeholder="μ: ν¬μ€μΌμ΄")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
405 |
|
406 |
-
# μ
λ ₯κ³Ό λ²νΌ μ¬μ΄μ μν λ©μμ§λ₯Ό νμν μμ μΆκ°
|
407 |
status_msg = gr.Markdown("π‘ 'μμ΄λμ΄ μμ±νκΈ°' λ²νΌμ ν΄λ¦νλ©΄ μμ΄λμ΄ μμ±μ΄ μμλ©λλ€.")
|
408 |
|
409 |
-
# μ²λ¦¬ μ€μΌ λλ§ νμλλ μν λ©μμ§
|
410 |
processing_indicator = gr.HTML("""
|
411 |
<div style="display: flex; justify-content: center; align-items: center; margin: 10px 0;">
|
412 |
<div style="border: 5px solid #f3f3f3; border-top: 5px solid #3498db; border-radius: 50%; width: 30px; height: 30px; animation: spin 2s linear infinite;"></div>
|
@@ -426,34 +417,30 @@ with gr.Blocks(title="ν€μλ κΈ°λ° μ°½μμ λ³ν μμ΄λμ΄ μμ±κΈ°",
|
|
426 |
with gr.Column(scale=2):
|
427 |
idea_output = gr.Markdown(label="μμ΄λμ΄ κ²°κ³Ό")
|
428 |
|
429 |
-
# μμ μ
λ ₯
|
430 |
gr.Examples(
|
431 |
examples=[
|
432 |
-
["μ€λ§νΈν°", "", ""],
|
433 |
-
["μλμ°¨", "", ""],
|
434 |
-
["μλμ°¨", "μΈκ³΅μ§λ₯", ""],
|
435 |
-
["λλ‘ ", "μΈκ³΅μ§λ₯", ""],
|
436 |
-
["μ΄λν", "μ¨μ΄λ¬λΈ", "건κ°"],
|
437 |
],
|
438 |
-
inputs=[text_input1, text_input2, text_input3],
|
439 |
)
|
440 |
|
441 |
-
# μ²λ¦¬ μμ μ ν¨μ (λ‘λ© νμκΈ° 보μ΄κ²)
|
442 |
def show_processing_indicator():
|
443 |
return gr.update(visible=True)
|
444 |
|
445 |
-
# μ²λ¦¬ μλ£ ν ν¨μ (λ‘λ© νμκΈ° μ¨κΈ°κΈ°)
|
446 |
def hide_processing_indicator():
|
447 |
return gr.update(visible=False)
|
448 |
|
449 |
-
# λ²νΌ μ΄λ²€νΈ - μ¬λ¬ ν¨μ μμ°¨ μ€ν
|
450 |
submit_button.click(
|
451 |
fn=show_processing_indicator,
|
452 |
inputs=None,
|
453 |
outputs=processing_indicator
|
454 |
).then(
|
455 |
fn=process_inputs,
|
456 |
-
inputs=[text_input1, text_input2, text_input3],
|
457 |
outputs=idea_output
|
458 |
).then(
|
459 |
fn=hide_processing_indicator,
|
@@ -462,4 +449,4 @@ with gr.Blocks(title="ν€μλ κΈ°λ° μ°½μμ λ³ν μμ΄λμ΄ μμ±κΈ°",
|
|
462 |
)
|
463 |
|
464 |
if __name__ == "__main__":
|
465 |
-
demo.launch(debug=True)
|
|
|
|
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
import random
|
|
|
42 |
else:
|
43 |
return random.choice([left, right])
|
44 |
|
45 |
+
# μ°½μμ μΈ λͺ¨λΈ/컨μ
/νμ λ³ν μμ΄λμ΄λ₯Ό μν μΉ΄ν
κ³ λ¦¬
|
|
|
|
|
|
|
46 |
physical_transformation_categories = {
|
47 |
"κ³΅κ° μ΄λ": [
|
48 |
"μ/λ€ μ΄λ", "μ’/μ° μ΄λ", "μ/μλ μ΄λ", "μΈλ‘μΆ νμ (κ³ κ° λλμ)",
|
|
|
282 |
# μμ±λ κΈ°λ³Έ μ€λͺ
μ LLMμ ν΅ν΄ νμ₯
|
283 |
##############################################################################
|
284 |
def enhance_descriptions(results, objects):
|
|
|
285 |
obj_name = " λ° ".join([obj for obj in objects if obj])
|
286 |
|
287 |
for category, result in results.items():
|
|
|
293 |
# μ¬μ©μ μ
λ ₯(μ΅λ 3κ° ν€μλ)μ λ°λΌ μ°½μμ λ³ν μμ΄λμ΄ μμ±
|
294 |
##############################################################################
|
295 |
def generate_transformations(text1, text2=None, text3=None):
|
|
|
|
|
296 |
if text2 and text3:
|
297 |
results = generate_three_objects_interaction(text1, text2, text3)
|
298 |
objects = [text1, text2, text3]
|
|
|
317 |
##############################################################################
|
318 |
# Gradio UIμμ νΈμΆν ν¨μ
|
319 |
##############################################################################
|
320 |
+
def process_inputs(text1, text2, text3, selected_category, progress=gr.Progress()):
|
321 |
text1 = text1.strip() if text1 else None
|
322 |
text2 = text2.strip() if text2 else None
|
323 |
text3 = text3.strip() if text3 else None
|
|
|
325 |
if not text1:
|
326 |
return "μ€λ₯: μ΅μ νλμ ν€μλλ₯Ό μ
λ ₯ν΄μ£ΌμΈμ."
|
327 |
|
|
|
|
|
|
|
|
|
328 |
keyword_info = f"ν€μλ: {text1}"
|
329 |
if text2:
|
330 |
keyword_info += f", {text2}"
|
331 |
if text3:
|
332 |
keyword_info += f", {text3}"
|
333 |
|
334 |
+
progress(0.05, desc="μμ΄λμ΄ μμ± μ€λΉ μ€...")
|
335 |
+
time.sleep(0.3) # μκ°μ ν¨κ³Όλ₯Ό μν μ§§μ μ§μ°
|
336 |
+
|
337 |
+
progress(0.1, desc="μ°½μμ μΈ λͺ¨λΈ/컨μ
/νμ λ³ν μμ΄λμ΄ μμ± μμ...")
|
338 |
+
|
339 |
+
results = generate_transformations(text1, text2, text3)
|
340 |
+
|
341 |
+
# μ νν μΉ΄ν
κ³ λ¦¬μ ν΄λΉνλ κ²°κ³Όλ§ νν°λ§
|
342 |
+
if selected_category in results:
|
343 |
+
results = {selected_category: results[selected_category]}
|
344 |
+
else:
|
345 |
+
return "μ νν μΉ΄ν
κ³ λ¦¬κ° κ²°κ³Όμ μ‘΄μ¬νμ§ μμ΅λλ€."
|
346 |
+
|
347 |
+
progress(0.8, desc="κ²°κ³Ό ν¬λ§·ν
μ€...")
|
348 |
+
formatted = format_results(results)
|
349 |
+
|
350 |
+
progress(1.0, desc="μλ£!")
|
351 |
+
return formatted
|
|
|
|
|
352 |
|
353 |
##############################################################################
|
354 |
# API ν€ κ²½κ³ λ©μμ§
|
|
|
378 |
""")
|
379 |
|
380 |
gr.Markdown("# π ν€μλ κΈ°λ° μ°½μμ λ³ν μμ΄λμ΄ μμ±κΈ°")
|
381 |
+
gr.Markdown("μ
λ ₯ν **ν€μλ**(μ΅λ 3κ°)μ **μΉ΄ν
κ³ λ¦¬**λ₯Ό λ°νμΌλ‘, **μ°½μμ μΈ λͺ¨λΈ/컨μ
/νμ λ³ν**μ λν μ΄ν΄μ **νμ ν¬μΈνΈ**, **κΈ°λ₯μ±** λ±μ μ€μ¬μΌλ‘ νμ₯λ μμ΄λμ΄λ₯Ό μ μν©λλ€.")
|
382 |
|
383 |
warning = gr.Markdown(get_warning_message())
|
384 |
|
|
|
388 |
text_input1 = gr.Textbox(label="ν€μλ 1 (νμ)", placeholder="μ: μ€λ§νΈν°")
|
389 |
text_input2 = gr.Textbox(label="ν€μλ 2 (μ ν)", placeholder="μ: μΈκ³΅μ§λ₯")
|
390 |
text_input3 = gr.Textbox(label="ν€μλ 3 (μ ν)", placeholder="μ: ν¬μ€μΌμ΄")
|
391 |
+
# μΉ΄ν
κ³ λ¦¬ μ ν λλ‘λ€μ΄ μΆκ°
|
392 |
+
category_dropdown = gr.Dropdown(
|
393 |
+
label="μΉ΄ν
κ³ λ¦¬ μ ν",
|
394 |
+
choices=list(physical_transformation_categories.keys()),
|
395 |
+
value=list(physical_transformation_categories.keys())[0],
|
396 |
+
info="μΆλ ₯ν μΉ΄ν
κ³ λ¦¬λ₯Ό μ ννμΈμ."
|
397 |
+
)
|
398 |
|
|
|
399 |
status_msg = gr.Markdown("π‘ 'μμ΄λμ΄ μμ±νκΈ°' λ²νΌμ ν΄λ¦νλ©΄ μμ΄λμ΄ μμ±μ΄ μμλ©λλ€.")
|
400 |
|
|
|
401 |
processing_indicator = gr.HTML("""
|
402 |
<div style="display: flex; justify-content: center; align-items: center; margin: 10px 0;">
|
403 |
<div style="border: 5px solid #f3f3f3; border-top: 5px solid #3498db; border-radius: 50%; width: 30px; height: 30px; animation: spin 2s linear infinite;"></div>
|
|
|
417 |
with gr.Column(scale=2):
|
418 |
idea_output = gr.Markdown(label="μμ΄λμ΄ κ²°κ³Ό")
|
419 |
|
|
|
420 |
gr.Examples(
|
421 |
examples=[
|
422 |
+
["μ€λ§νΈν°", "", "", list(physical_transformation_categories.keys())[0]],
|
423 |
+
["μλμ°¨", "", "", list(physical_transformation_categories.keys())[0]],
|
424 |
+
["μλμ°¨", "μΈκ³΅μ§λ₯", "", list(physical_transformation_categories.keys())[0]],
|
425 |
+
["λλ‘ ", "μΈκ³΅μ§λ₯", "", list(physical_transformation_categories.keys())[0]],
|
426 |
+
["μ΄λν", "μ¨μ΄λ¬λΈ", "건κ°", list(physical_transformation_categories.keys())[0]],
|
427 |
],
|
428 |
+
inputs=[text_input1, text_input2, text_input3, category_dropdown],
|
429 |
)
|
430 |
|
|
|
431 |
def show_processing_indicator():
|
432 |
return gr.update(visible=True)
|
433 |
|
|
|
434 |
def hide_processing_indicator():
|
435 |
return gr.update(visible=False)
|
436 |
|
|
|
437 |
submit_button.click(
|
438 |
fn=show_processing_indicator,
|
439 |
inputs=None,
|
440 |
outputs=processing_indicator
|
441 |
).then(
|
442 |
fn=process_inputs,
|
443 |
+
inputs=[text_input1, text_input2, text_input3, category_dropdown],
|
444 |
outputs=idea_output
|
445 |
).then(
|
446 |
fn=hide_processing_indicator,
|
|
|
449 |
)
|
450 |
|
451 |
if __name__ == "__main__":
|
452 |
+
demo.launch(debug=True)
|