Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -44,6 +44,9 @@ def choose_alternative(transformation):
|
|
44 |
else:
|
45 |
return random.choice([left, right])
|
46 |
|
|
|
|
|
|
|
47 |
# ์ฐฝ์์ ์ธ ๋ชจ๋ธ/์ปจ์
/ํ์ ๋ณํ ์์ด๋์ด๋ฅผ ์ํ ์นดํ
๊ณ ๋ฆฌ (๊ธฐ์กด '๋ฌผ๋ฆฌ์ ๋ณํ' ์ฌ์ ์ ์ง)
|
48 |
physical_transformation_categories = {
|
49 |
"๊ณต๊ฐ ์ด๋": [
|
@@ -283,30 +286,20 @@ def generate_three_objects_interaction(obj1, obj2, obj3):
|
|
283 |
##############################################################################
|
284 |
# ์์ฑ๋ ๊ธฐ๋ณธ ์ค๋ช
์ LLM์ ํตํด ํ์ฅ
|
285 |
##############################################################################
|
286 |
-
def enhance_descriptions(results, objects
|
|
|
287 |
obj_name = " ๋ฐ ".join([obj for obj in objects if obj])
|
288 |
-
total_categories = len(results)
|
289 |
|
290 |
-
for
|
291 |
-
# ํ๋ก๊ทธ๋ ์ค ์
๋ฐ์ดํธ (์งํ๋ฅ ์ 0.2~0.9 ์ฌ์ด๋ก ๋งคํ)
|
292 |
-
if progress:
|
293 |
-
progress_value = 0.2 + (i / total_categories) * 0.7
|
294 |
-
progress(progress_value, f"์นดํ
๊ณ ๋ฆฌ '{category}' ์ฒ๋ฆฌ ์ค...")
|
295 |
-
|
296 |
result["enhanced"] = enhance_with_llm(result["base"], obj_name, category)
|
297 |
|
298 |
-
# ์๋ฃ ๋ฉ์์ง
|
299 |
-
if progress:
|
300 |
-
progress(0.95, "๊ฒฐ๊ณผ ์ ๋ฆฌ ์ค...")
|
301 |
-
|
302 |
return results
|
303 |
|
304 |
##############################################################################
|
305 |
# ์ฌ์ฉ์ ์
๋ ฅ(์ต๋ 3๊ฐ ํค์๋)์ ๋ฐ๋ผ ์ฐฝ์์ ๋ณํ ์์ด๋์ด ์์ฑ
|
306 |
##############################################################################
|
307 |
-
def generate_transformations(text1, text2=None, text3=None
|
308 |
-
|
309 |
-
progress(0.1, "์์ด๋์ด ๊ธฐ๋ณธ ๊ตฌ์กฐ ์์ฑ ์ค...")
|
310 |
|
311 |
if text2 and text3:
|
312 |
results = generate_three_objects_interaction(text1, text2, text3)
|
@@ -318,10 +311,7 @@ def generate_transformations(text1, text2=None, text3=None, progress=None):
|
|
318 |
results = generate_single_object_transformations(text1)
|
319 |
objects = [text1]
|
320 |
|
321 |
-
|
322 |
-
progress(0.2, "Gemini API๋ฅผ ํตํ ์์ด๋์ด ํ์ฅ ์ค...")
|
323 |
-
|
324 |
-
return enhance_descriptions(results, objects, progress)
|
325 |
|
326 |
##############################################################################
|
327 |
# ๊ฒฐ๊ณผ ํฌ๋งทํ
|
@@ -343,7 +333,8 @@ def process_inputs(text1, text2, text3, progress=gr.Progress()):
|
|
343 |
if not text1:
|
344 |
return "์ค๋ฅ: ์ต์ ํ๋์ ํค์๋๋ฅผ ์
๋ ฅํด์ฃผ์ธ์."
|
345 |
|
346 |
-
|
|
|
347 |
|
348 |
# ํค์๋ ์ ๋ณด ํ์ธ
|
349 |
keyword_info = f"ํค์๋: {text1}"
|
@@ -352,16 +343,26 @@ def process_inputs(text1, text2, text3, progress=gr.Progress()):
|
|
352 |
if text3:
|
353 |
keyword_info += f", {text3}"
|
354 |
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
365 |
|
366 |
##############################################################################
|
367 |
# API ํค ๊ฒฝ๊ณ ๋ฉ์์ง
|
@@ -402,9 +403,24 @@ with gr.Blocks(title="ํค์๋ ๊ธฐ๋ฐ ์ฐฝ์์ ๋ณํ ์์ด๋์ด ์์ฑ๊ธฐ",
|
|
402 |
text_input2 = gr.Textbox(label="ํค์๋ 2 (์ ํ)", placeholder="์: ์ธ๊ณต์ง๋ฅ")
|
403 |
text_input3 = gr.Textbox(label="ํค์๋ 3 (์ ํ)", placeholder="์: ํฌ์ค์ผ์ด")
|
404 |
|
405 |
-
# ์ํ ๋ฉ์์ง๋ฅผ ํ์ํ ์์ญ ์ถ๊ฐ
|
406 |
status_msg = gr.Markdown("๐ก '์์ด๋์ด ์์ฑํ๊ธฐ' ๋ฒํผ์ ํด๋ฆญํ๋ฉด ํ๋ก๊ทธ๋ ์ค ๋ฐ๏ฟฝ๏ฟฝ๏ฟฝ ๋ํ๋ฉ๋๋ค.")
|
407 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
408 |
submit_button = gr.Button("์์ด๋์ด ์์ฑํ๊ธฐ", variant="primary")
|
409 |
|
410 |
# ์ฐ์ธก ์ถ๋ ฅ ์์ญ
|
@@ -414,19 +430,37 @@ with gr.Blocks(title="ํค์๋ ๊ธฐ๋ฐ ์ฐฝ์์ ๋ณํ ์์ด๋์ด ์์ฑ๊ธฐ",
|
|
414 |
# ์์ ์
๋ ฅ
|
415 |
gr.Examples(
|
416 |
examples=[
|
417 |
-
|
418 |
-
["
|
419 |
-
["
|
|
|
420 |
["์ด๋ํ", "์จ์ด๋ฌ๋ธ", "๊ฑด๊ฐ"],
|
|
|
421 |
],
|
422 |
inputs=[text_input1, text_input2, text_input3],
|
423 |
)
|
424 |
|
425 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
426 |
submit_button.click(
|
|
|
|
|
|
|
|
|
427 |
fn=process_inputs,
|
428 |
inputs=[text_input1, text_input2, text_input3],
|
429 |
outputs=idea_output
|
|
|
|
|
|
|
|
|
430 |
)
|
431 |
|
432 |
if __name__ == "__main__":
|
|
|
44 |
else:
|
45 |
return random.choice([left, right])
|
46 |
|
47 |
+
# ์ฐฝ์์ ์ธ ๋ชจ๋ธ/์ปจ์
/ํ์ ๋ณํ ์์ด๋์ด๋ฅผ ์ํ ์นดํ
๊ณ ๋ฆฌ (๊ธฐ์กด '๋ฌผ๋ฆฌ์ ๋ณํ' ์ฌ์ ์ ์ง)
|
48 |
+
|
49 |
+
|
50 |
# ์ฐฝ์์ ์ธ ๋ชจ๋ธ/์ปจ์
/ํ์ ๋ณํ ์์ด๋์ด๋ฅผ ์ํ ์นดํ
๊ณ ๋ฆฌ (๊ธฐ์กด '๋ฌผ๋ฆฌ์ ๋ณํ' ์ฌ์ ์ ์ง)
|
51 |
physical_transformation_categories = {
|
52 |
"๊ณต๊ฐ ์ด๋": [
|
|
|
286 |
##############################################################################
|
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():
|
|
|
|
|
|
|
|
|
|
|
294 |
result["enhanced"] = enhance_with_llm(result["base"], obj_name, category)
|
295 |
|
|
|
|
|
|
|
|
|
296 |
return results
|
297 |
|
298 |
##############################################################################
|
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)
|
|
|
311 |
results = generate_single_object_transformations(text1)
|
312 |
objects = [text1]
|
313 |
|
314 |
+
return enhance_descriptions(results, objects)
|
|
|
|
|
|
|
315 |
|
316 |
##############################################################################
|
317 |
# ๊ฒฐ๊ณผ ํฌ๋งทํ
|
|
|
333 |
if not text1:
|
334 |
return "์ค๋ฅ: ์ต์ ํ๋์ ํค์๋๋ฅผ ์
๋ ฅํด์ฃผ์ธ์."
|
335 |
|
336 |
+
# ์งํ ์ํ ๋ฉ์์ง (์ค์ฒฉ ๋ฆฌ์คํธ ๋์ ๋จ์ ๋ฌธ์์ด ์ฌ์ฉ)
|
337 |
+
status_message = ""
|
338 |
|
339 |
# ํค์๋ ์ ๋ณด ํ์ธ
|
340 |
keyword_info = f"ํค์๋: {text1}"
|
|
|
343 |
if text3:
|
344 |
keyword_info += f", {text3}"
|
345 |
|
346 |
+
# ๊ฒฐ๊ณผ ์์ฑ (progress ์ธ์ ์ ๋ฌํ์ง ์์)
|
347 |
+
try:
|
348 |
+
# ์งํ ์ํ๋ฅผ ๋จ๊ณ๋ณ๋ก ํ์
|
349 |
+
progress(0.05, desc="์์ด๋์ด ์์ฑ ์ค๋น ์ค...")
|
350 |
+
time.sleep(0.3) # ์๊ฐ์ ํจ๊ณผ๋ฅผ ์ํ ์งง์ ์ง์ฐ
|
351 |
+
|
352 |
+
progress(0.1, desc="์ฐฝ์์ ์ธ ๋ชจ๋ธ/์ปจ์
/ํ์ ๋ณํ ์์ด๋์ด ์์ฑ ์์...")
|
353 |
+
|
354 |
+
# text1, text2, text3๋ง ์ ๋ฌํ๊ณ progress๋ ์ ๋ฌํ์ง ์์
|
355 |
+
results = generate_transformations(text1, text2, text3)
|
356 |
+
|
357 |
+
progress(0.8, desc="๊ฒฐ๊ณผ ํฌ๋งทํ
์ค...")
|
358 |
+
formatted = format_results(results)
|
359 |
+
|
360 |
+
progress(1.0, desc="์๋ฃ!")
|
361 |
+
return formatted
|
362 |
+
|
363 |
+
except Exception as e:
|
364 |
+
logger.error(f"Error in process_inputs: {e}")
|
365 |
+
return f"์ฒ๋ฆฌ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}"
|
366 |
|
367 |
##############################################################################
|
368 |
# API ํค ๊ฒฝ๊ณ ๋ฉ์์ง
|
|
|
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 |
+
with gr.Box(visible=False) as processing_box:
|
411 |
+
processing_indicator = gr.HTML("""
|
412 |
+
<div style="display: flex; justify-content: center; align-items: center; margin: 10px 0;">
|
413 |
+
<div style="border: 5px solid #f3f3f3; border-top: 5px solid #3498db; border-radius: 50%; width: 30px; height: 30px; animation: spin 2s linear infinite;"></div>
|
414 |
+
<p style="margin-left: 10px; font-weight: bold; color: #3498db;">์ฒ๋ฆฌ ์ค์
๋๋ค...</p>
|
415 |
+
</div>
|
416 |
+
<style>
|
417 |
+
@keyframes spin {
|
418 |
+
0% { transform: rotate(0deg); }
|
419 |
+
100% { transform: rotate(360deg); }
|
420 |
+
}
|
421 |
+
</style>
|
422 |
+
""")
|
423 |
+
|
424 |
submit_button = gr.Button("์์ด๋์ด ์์ฑํ๊ธฐ", variant="primary")
|
425 |
|
426 |
# ์ฐ์ธก ์ถ๋ ฅ ์์ญ
|
|
|
430 |
# ์์ ์
๋ ฅ
|
431 |
gr.Examples(
|
432 |
examples=[
|
433 |
+
|
434 |
+
["์๋์ฐจ", "", ""],
|
435 |
+
["์ค๋งํธํฐ", "์ธ๊ณต์ง๋ฅ", ""],
|
436 |
+
["๋๋ก ", "์ธ๊ณต์ง๋ฅ", ""],
|
437 |
["์ด๋ํ", "์จ์ด๋ฌ๋ธ", "๊ฑด๊ฐ"],
|
438 |
+
|
439 |
],
|
440 |
inputs=[text_input1, text_input2, text_input3],
|
441 |
)
|
442 |
|
443 |
+
# ์ฒ๋ฆฌ ์์ ์ ํจ์ (๋ก๋ฉ ํ์๊ธฐ ๋ณด์ด๊ฒ)
|
444 |
+
def show_processing_indicator():
|
445 |
+
return gr.update(visible=True)
|
446 |
+
|
447 |
+
# ์ฒ๋ฆฌ ์๋ฃ ํ ํจ์ (๋ก๋ฉ ํ์๊ธฐ ์จ๊ธฐ๊ธฐ)
|
448 |
+
def hide_processing_indicator():
|
449 |
+
return gr.update(visible=False)
|
450 |
+
|
451 |
+
# ๋ฒํผ ์ด๋ฒคํธ - ์ฌ๋ฌ ํจ์ ์์ฐจ ์คํ
|
452 |
submit_button.click(
|
453 |
+
fn=show_processing_indicator,
|
454 |
+
inputs=None,
|
455 |
+
outputs=processing_box
|
456 |
+
).then(
|
457 |
fn=process_inputs,
|
458 |
inputs=[text_input1, text_input2, text_input3],
|
459 |
outputs=idea_output
|
460 |
+
).then(
|
461 |
+
fn=hide_processing_indicator,
|
462 |
+
inputs=None,
|
463 |
+
outputs=processing_box
|
464 |
)
|
465 |
|
466 |
if __name__ == "__main__":
|