Spaces:
Runtime error
Runtime error
Update app-backup.py
Browse files- app-backup.py +362 -187
app-backup.py
CHANGED
@@ -12,7 +12,7 @@ from transformers import pipeline as hf_pipeline
|
|
12 |
import re
|
13 |
|
14 |
##############################################################################
|
15 |
-
# 1) ZeroGPU
|
16 |
##############################################################################
|
17 |
try:
|
18 |
import zerogpu
|
@@ -34,7 +34,7 @@ dtype = torch.bfloat16 if device == "cuda" else torch.float32
|
|
34 |
print(f"Using device: {device}, dtype: {dtype}")
|
35 |
|
36 |
##############################################################################
|
37 |
-
# 2)
|
38 |
##############################################################################
|
39 |
try:
|
40 |
translator = hf_pipeline(
|
@@ -71,7 +71,7 @@ MAX_SEED = np.iinfo(np.int32).max
|
|
71 |
MAX_IMAGE_SIZE = 2048
|
72 |
|
73 |
##############################################################################
|
74 |
-
#
|
75 |
##############################################################################
|
76 |
def contains_korean(text):
|
77 |
for char in text:
|
@@ -79,45 +79,39 @@ def contains_korean(text):
|
|
79 |
return True
|
80 |
return False
|
81 |
|
82 |
-
##############################################################################
|
83 |
-
# μ
λ ₯ ν
μ€νΈ ν΄λ¦°μ§ ν¨μ: νκΈ, μλ¬Έ, μ«μ, 곡백 λ° μΌλ°μ μΈ λ¬Έμ₯ λΆνΈλ§ νμ©
|
84 |
-
##############################################################################
|
85 |
def clean_input_text(text):
|
86 |
"""
|
87 |
-
|
88 |
-
|
89 |
"""
|
90 |
allowed = re.compile(r'[^γ±-γ
κ°-ν£a-zA-Z0-9\s\.\,\!\?\-\:\;\'\"]')
|
91 |
cleaned_text = allowed.sub('', text)
|
92 |
return cleaned_text
|
93 |
|
94 |
-
##############################################################################
|
95 |
-
# μ
λ ₯ ν
μ€νΈμ μμμΉ λͺ»ν λ¬Έμ λ‘κ·Έ ν¨μ (λλ²κΉ
μ©)
|
96 |
-
##############################################################################
|
97 |
def log_unexpected_characters(text):
|
98 |
allowed = re.compile(r'[γ±-γ
κ°-ν£a-zA-Z0-9\s\.\,\!\?\-\:\;\'\"]')
|
99 |
unexpected_chars = [char for char in text if not allowed.match(char)]
|
100 |
if unexpected_chars:
|
101 |
-
print("
|
102 |
else:
|
103 |
-
print("
|
104 |
|
105 |
##############################################################################
|
106 |
-
#
|
107 |
##############################################################################
|
108 |
def generate_design_image(prompt, seed=42, randomize_seed=True, width=1024, height=1024, num_inference_steps=4):
|
109 |
original_prompt = prompt
|
110 |
translated = False
|
111 |
|
112 |
-
#
|
113 |
prompt = clean_input_text(prompt)
|
114 |
|
115 |
-
#
|
116 |
if len(prompt) > 1000:
|
117 |
prompt = prompt[:1000]
|
118 |
|
119 |
if contains_korean(prompt):
|
120 |
-
#
|
121 |
translation = translator(prompt, max_length=400, truncation=True)
|
122 |
prompt = translation[0]['translation_text']
|
123 |
translated = True
|
@@ -138,9 +132,8 @@ def generate_design_image(prompt, seed=42, randomize_seed=True, width=1024, heig
|
|
138 |
|
139 |
return image
|
140 |
|
141 |
-
|
142 |
##############################################################################
|
143 |
-
#
|
144 |
##############################################################################
|
145 |
logging.basicConfig(
|
146 |
level=logging.INFO,
|
@@ -153,13 +146,13 @@ logging.basicConfig(
|
|
153 |
logger = logging.getLogger("idea_generator")
|
154 |
|
155 |
##############################################################################
|
156 |
-
# Gemini API
|
157 |
##############################################################################
|
158 |
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
|
159 |
genai.configure(api_key=GEMINI_API_KEY)
|
160 |
|
161 |
##############################################################################
|
162 |
-
#
|
163 |
##############################################################################
|
164 |
def choose_alternative(transformation):
|
165 |
if "/" not in transformation:
|
@@ -183,8 +176,9 @@ def choose_alternative(transformation):
|
|
183 |
return random.choice([left, right])
|
184 |
|
185 |
##############################################################################
|
186 |
-
#
|
187 |
##############################################################################
|
|
|
188 |
physical_transformation_categories = {
|
189 |
"μΌμ κΈ°λ₯": [
|
190 |
"μκ° μΌμ/κ°μ§", "μ²κ° μΌμ/κ°μ§", "μ΄κ° μΌμ/κ°μ§", "λ―Έκ° μΌμ/κ°μ§", "νκ° μΌμ/κ°μ§",
|
@@ -214,10 +208,7 @@ physical_transformation_categories = {
|
|
214 |
"κ΄ν/μ€κΈ° λ³ν", "μμ‘°/μ±λ λ³ν", "λ°κ΄/νκ΄", "λΉ μ°λ ν¨κ³Ό",
|
215 |
"λΉ ν‘μ λ³ν", "λ°ν¬λͺ
ν¨κ³Ό", "κ·Έλ¦Όμ ν¨κ³Ό λ³ν", "μμΈμ λ°μ λ³ν",
|
216 |
"μΌκ΄ ν¨κ³Ό"
|
217 |
-
],
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
"λ¬Όμ§μ μν λ³ν": [
|
222 |
"κ³ μ²΄/μ‘체/기체 μ ν", "κ²°μ ν/μ©ν΄", "μ°ν/λΆμ", "λ±λ±ν΄μ§/λΆλλ¬μμ§",
|
223 |
"νΉμ μν μ ν", "무μ ν/κ²°μ ν μ ν", "μ±λΆ λΆλ¦¬", "λ―ΈμΈ μ
μ νμ±/λΆν΄",
|
@@ -226,7 +217,6 @@ physical_transformation_categories = {
|
|
226 |
"건쑰/μ΅μ€", "ν½μ€/μμΆ", "λκ²°/ν΄λ", "νν/μΉ¨μ", "μΆ©μ /λ°©μ ",
|
227 |
"κ²°ν©/λΆλ¦¬", "λ°ν¨/λΆν¨"
|
228 |
],
|
229 |
-
|
230 |
"μμ§μ νΉμ± λ³ν": [
|
231 |
"κ°μ/κ°μ", "μΌμ μλ μ μ§", "μ§λ/μ§λ κ°μ", "λΆλͺν/νκΉ",
|
232 |
"νμ μλ μ¦κ°/κ°μ", "νμ λ°©ν₯ λ³ν", "λΆκ·μΉ μμ§μ", "λ©μ·λ€ λ―Έλλ¬μ§λ νμ",
|
@@ -273,53 +263,138 @@ physical_transformation_categories = {
|
|
273 |
"μ§λ ν¨ν΄ λ³ν", "νμ
ν¨κ³Ό", "μν₯ νΌλλ°±", "μν₯ μ°¨ν/μ¦ν",
|
274 |
"μ리 μ§ν₯μ±", "μν₯ μ곑", "λΉνΈ μμ±", "νλͺ¨λμ€ μμ±", "μ£Όνμ λ³μ‘°",
|
275 |
"μν₯ 좩격ν", "μν₯ νν°λ§"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
276 |
],
|
277 |
-
"
|
278 |
-
"
|
279 |
-
"
|
280 |
-
"
|
281 |
-
"
|
282 |
-
"
|
283 |
-
"
|
284 |
],
|
285 |
-
"
|
286 |
-
"
|
287 |
-
"
|
288 |
-
"
|
289 |
-
"
|
290 |
-
"
|
291 |
-
"
|
292 |
-
"
|
293 |
],
|
294 |
-
"
|
295 |
-
"
|
296 |
-
"
|
297 |
-
"
|
298 |
-
"
|
299 |
-
"
|
300 |
-
"
|
301 |
],
|
302 |
-
|
303 |
-
|
304 |
-
"
|
305 |
-
"
|
306 |
-
"
|
307 |
-
"
|
308 |
-
"
|
309 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
310 |
],
|
311 |
-
"
|
312 |
-
"
|
313 |
-
"
|
314 |
-
"
|
315 |
-
"
|
316 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
317 |
]
|
318 |
-
|
319 |
}
|
320 |
|
321 |
##############################################################################
|
322 |
-
# Gemini API
|
323 |
##############################################################################
|
324 |
def query_gemini_api(prompt):
|
325 |
try:
|
@@ -349,7 +424,7 @@ def query_gemini_api(prompt):
|
|
349 |
return f"An error occurred while calling the API: {str(e)}"
|
350 |
|
351 |
##############################################################################
|
352 |
-
#
|
353 |
##############################################################################
|
354 |
def enhance_with_llm(base_description, obj_name, category):
|
355 |
prompt = f"""
|
@@ -362,101 +437,129 @@ def enhance_with_llm(base_description, obj_name, category):
|
|
362 |
"""
|
363 |
return query_gemini_api(prompt)
|
364 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
365 |
##############################################################################
|
366 |
-
#
|
367 |
##############################################################################
|
368 |
-
def
|
369 |
-
transformations =
|
370 |
if not transformations:
|
371 |
return {}
|
372 |
transformation = choose_alternative(random.choice(transformations))
|
373 |
-
|
|
|
|
|
|
|
374 |
return {selected_category: {"base": base_description, "enhanced": None}}
|
375 |
|
376 |
-
def
|
377 |
-
transformations =
|
378 |
if not transformations:
|
379 |
return {}
|
380 |
transformation = choose_alternative(random.choice(transformations))
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
385 |
base_description = template.format(obj1=obj1, obj2=obj2, change=transformation)
|
386 |
return {selected_category: {"base": base_description, "enhanced": None}}
|
387 |
|
388 |
-
def
|
389 |
-
transformations =
|
390 |
if not transformations:
|
391 |
return {}
|
392 |
transformation = choose_alternative(random.choice(transformations))
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
397 |
base_description = template.format(obj1=obj1, obj2=obj2, obj3=obj3, change=transformation)
|
398 |
return {selected_category: {"base": base_description, "enhanced": None}}
|
399 |
|
400 |
-
|
401 |
-
|
402 |
-
##############################################################################
|
403 |
-
def enhance_descriptions(results, objects):
|
404 |
-
obj_name = " λ° ".join([obj for obj in objects if obj])
|
405 |
for category, result in results.items():
|
406 |
-
|
|
|
|
|
|
|
407 |
return results
|
408 |
|
409 |
-
|
410 |
-
# μ¬μ©μ μ
λ ₯(μ΅λ 3κ° ν€μλ) + μ ν μΉ΄ν
κ³ λ¦¬ β λ³ν μμ΄λμ΄ μμ±
|
411 |
-
##############################################################################
|
412 |
-
def generate_transformations(text1, text2, text3, selected_category):
|
413 |
if text2 and text3:
|
414 |
-
results =
|
415 |
objects = [text1, text2, text3]
|
416 |
elif text2:
|
417 |
-
results =
|
418 |
objects = [text1, text2]
|
419 |
else:
|
420 |
-
results =
|
421 |
objects = [text1]
|
422 |
-
return
|
423 |
|
424 |
-
|
425 |
-
# κ²°κ³Ό ν¬λ§·ν
|
426 |
-
##############################################################################
|
427 |
-
def format_results(results):
|
428 |
formatted = ""
|
429 |
-
|
430 |
-
|
|
|
|
|
|
|
|
|
431 |
return formatted
|
432 |
|
433 |
-
|
434 |
-
# Gradio UIμμ νΈμΆλ ν¨μ (ν
μ€νΈ μμ΄λμ΄λ§ μμ±)
|
435 |
-
##############################################################################
|
436 |
-
def process_inputs(text1, text2, text3, selected_category, progress=gr.Progress()):
|
437 |
text1 = text1.strip() if text1 else None
|
438 |
text2 = text2.strip() if text2 else None
|
439 |
text3 = text3.strip() if text3 else None
|
440 |
|
441 |
if not text1:
|
442 |
-
return "μ€λ₯: μ΅μ νλμ ν€μλλ₯Ό μ
λ ₯ν΄μ£ΌμΈμ."
|
443 |
|
444 |
-
|
445 |
-
|
446 |
-
|
|
|
|
|
|
|
|
|
|
|
447 |
|
448 |
-
results =
|
449 |
|
450 |
-
|
451 |
-
|
452 |
-
|
|
|
|
|
|
|
|
|
|
|
453 |
return formatted
|
454 |
|
455 |
-
|
456 |
-
|
457 |
-
##############################################################################
|
458 |
-
def process_all(text1, text2, text3, selected_category, progress=gr.Progress()):
|
459 |
-
idea_result = process_inputs(text1, text2, text3, selected_category, progress)
|
460 |
image_result = generate_design_image(
|
461 |
idea_result,
|
462 |
seed=42,
|
@@ -468,18 +571,19 @@ def process_all(text1, text2, text3, selected_category, progress=gr.Progress()):
|
|
468 |
return idea_result, image_result
|
469 |
|
470 |
##############################################################################
|
471 |
-
# API
|
472 |
##############################################################################
|
473 |
-
def
|
474 |
if not GEMINI_API_KEY:
|
475 |
-
return "β οΈ νκ²½ λ³μ GEMINI_API_KEYκ° μ€μ λμ§ μμμ΅λλ€. Gemini API ν€λ₯Ό μ€μ νμΈμ."
|
476 |
return ""
|
477 |
|
|
|
478 |
##############################################################################
|
479 |
-
# Gradio UI
|
480 |
##############################################################################
|
481 |
with gr.Blocks(
|
482 |
-
title="
|
483 |
theme=gr.themes.Soft(primary_hue="teal", secondary_hue="slate", neutral_hue="neutral")
|
484 |
) as demo:
|
485 |
|
@@ -521,73 +625,144 @@ with gr.Blocks(
|
|
521 |
</style>
|
522 |
""")
|
523 |
|
524 |
-
gr.
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
539 |
)
|
540 |
-
status_msg = gr.Markdown("π‘ 'μμ΄λμ΄ μμ±νκΈ°' λ²νΌμ ν΄λ¦νλ©΄ μ νν μΉ΄ν
κ³ λ¦¬μ ν΄λΉνλ μμ΄λμ΄μ λμμΈ μ΄λ―Έμ§κ° μμ±λ©λλ€.")
|
541 |
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
<style>
|
548 |
-
@keyframes spin {
|
549 |
-
0% { transform: rotate(0deg); }
|
550 |
-
100% { transform: rotate(360deg); }
|
551 |
-
}
|
552 |
-
</style>
|
553 |
-
""", visible=False)
|
554 |
|
555 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
556 |
|
557 |
-
with gr.
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
591 |
|
592 |
if __name__ == "__main__":
|
593 |
demo.launch(debug=True)
|
|
|
12 |
import re
|
13 |
|
14 |
##############################################################################
|
15 |
+
# 1) ZeroGPU Environment Setup + Device and Dtype Configuration
|
16 |
##############################################################################
|
17 |
try:
|
18 |
import zerogpu
|
|
|
34 |
print(f"Using device: {device}, dtype: {dtype}")
|
35 |
|
36 |
##############################################################################
|
37 |
+
# 2) Load Models: Translation Model, Diffusion Pipeline
|
38 |
##############################################################################
|
39 |
try:
|
40 |
translator = hf_pipeline(
|
|
|
71 |
MAX_IMAGE_SIZE = 2048
|
72 |
|
73 |
##############################################################################
|
74 |
+
# Korean detection and input text cleaning functions
|
75 |
##############################################################################
|
76 |
def contains_korean(text):
|
77 |
for char in text:
|
|
|
79 |
return True
|
80 |
return False
|
81 |
|
|
|
|
|
|
|
82 |
def clean_input_text(text):
|
83 |
"""
|
84 |
+
Allows only Korean, English, numbers, whitespace and common punctuation marks.
|
85 |
+
Adjust allowed characters as needed.
|
86 |
"""
|
87 |
allowed = re.compile(r'[^γ±-γ
κ°-ν£a-zA-Z0-9\s\.\,\!\?\-\:\;\'\"]')
|
88 |
cleaned_text = allowed.sub('', text)
|
89 |
return cleaned_text
|
90 |
|
|
|
|
|
|
|
91 |
def log_unexpected_characters(text):
|
92 |
allowed = re.compile(r'[γ±-γ
κ°-ν£a-zA-Z0-9\s\.\,\!\?\-\:\;\'\"]')
|
93 |
unexpected_chars = [char for char in text if not allowed.match(char)]
|
94 |
if unexpected_chars:
|
95 |
+
print("Unexpected characters found:", set(unexpected_chars))
|
96 |
else:
|
97 |
+
print("No unexpected characters in the input text.")
|
98 |
|
99 |
##############################################################################
|
100 |
+
# Image Generation Function
|
101 |
##############################################################################
|
102 |
def generate_design_image(prompt, seed=42, randomize_seed=True, width=1024, height=1024, num_inference_steps=4):
|
103 |
original_prompt = prompt
|
104 |
translated = False
|
105 |
|
106 |
+
# Clean the input text
|
107 |
prompt = clean_input_text(prompt)
|
108 |
|
109 |
+
# Pre-process: if input is too long, trim to 1000 characters
|
110 |
if len(prompt) > 1000:
|
111 |
prompt = prompt[:1000]
|
112 |
|
113 |
if contains_korean(prompt):
|
114 |
+
# When calling translation, add max_length and truncation options to avoid length issues
|
115 |
translation = translator(prompt, max_length=400, truncation=True)
|
116 |
prompt = translation[0]['translation_text']
|
117 |
translated = True
|
|
|
132 |
|
133 |
return image
|
134 |
|
|
|
135 |
##############################################################################
|
136 |
+
# Logging Setup
|
137 |
##############################################################################
|
138 |
logging.basicConfig(
|
139 |
level=logging.INFO,
|
|
|
146 |
logger = logging.getLogger("idea_generator")
|
147 |
|
148 |
##############################################################################
|
149 |
+
# Gemini API Key
|
150 |
##############################################################################
|
151 |
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
|
152 |
genai.configure(api_key=GEMINI_API_KEY)
|
153 |
|
154 |
##############################################################################
|
155 |
+
# Optional Transformation Choice Function
|
156 |
##############################################################################
|
157 |
def choose_alternative(transformation):
|
158 |
if "/" not in transformation:
|
|
|
176 |
return random.choice([left, right])
|
177 |
|
178 |
##############################################################################
|
179 |
+
# Transformation Categories Dictionaries
|
180 |
##############################################################################
|
181 |
+
# Korean version
|
182 |
physical_transformation_categories = {
|
183 |
"μΌμ κΈ°λ₯": [
|
184 |
"μκ° μΌμ/κ°μ§", "μ²κ° μΌμ/κ°μ§", "μ΄κ° μΌμ/κ°μ§", "λ―Έκ° μΌμ/κ°μ§", "νκ° μΌμ/κ°μ§",
|
|
|
208 |
"κ΄ν/μ€κΈ° λ³ν", "μμ‘°/μ±λ λ³ν", "λ°κ΄/νκ΄", "λΉ μ°λ ν¨κ³Ό",
|
209 |
"λΉ ν‘μ λ³ν", "λ°ν¬λͺ
ν¨κ³Ό", "κ·Έλ¦Όμ ν¨κ³Ό λ³ν", "μμΈμ λ°μ λ³ν",
|
210 |
"μΌκ΄ ν¨κ³Ό"
|
211 |
+
],
|
|
|
|
|
|
|
212 |
"λ¬Όμ§μ μν λ³ν": [
|
213 |
"κ³ μ²΄/μ‘체/기체 μ ν", "κ²°μ ν/μ©ν΄", "μ°ν/λΆμ", "λ±λ±ν΄μ§/λΆλλ¬μμ§",
|
214 |
"νΉμ μν μ ν", "무μ ν/κ²°μ ν μ ν", "μ±λΆ λΆλ¦¬", "λ―ΈμΈ μ
μ νμ±/λΆν΄",
|
|
|
217 |
"건쑰/μ΅μ€", "ν½μ€/μμΆ", "λκ²°/ν΄λ", "νν/μΉ¨μ", "μΆ©μ /λ°©μ ",
|
218 |
"κ²°ν©/λΆλ¦¬", "λ°ν¨/λΆν¨"
|
219 |
],
|
|
|
220 |
"μμ§μ νΉμ± λ³ν": [
|
221 |
"κ°μ/κ°μ", "μΌμ μλ μ μ§", "μ§λ/μ§λ κ°μ", "λΆλͺν/νκΉ",
|
222 |
"νμ μλ μ¦κ°/κ°μ", "νμ λ°©ν₯ λ³ν", "λΆκ·μΉ μμ§μ", "λ©μ·λ€ λ―Έλλ¬μ§λ νμ",
|
|
|
263 |
"μ§λ ν¨ν΄ λ³ν", "νμ
ν¨κ³Ό", "μν₯ νΌλλ°±", "μν₯ μ°¨ν/μ¦ν",
|
264 |
"μ리 μ§ν₯μ±", "μν₯ μ곑", "λΉνΈ μμ±", "νλͺ¨λμ€ μμ±", "μ£Όνμ λ³μ‘°",
|
265 |
"μν₯ 좩격ν", "μν₯ νν°λ§"
|
266 |
+
]
|
267 |
+
}
|
268 |
+
|
269 |
+
# English version
|
270 |
+
physical_transformation_categories_en = {
|
271 |
+
"Sensor Functions": [
|
272 |
+
"Visual sensor/detection", "Auditory sensor/detection", "Tactile sensor/detection", "Taste sensor/detection", "Olfactory sensor/detection",
|
273 |
+
"Temperature sensor/detection", "Humidity sensor/detection", "Pressure sensor/detection", "Acceleration sensor/detection", "Rotational sensor/detection",
|
274 |
+
"Proximity sensor/detection", "Position sensor/detection", "Motion sensor/detection", "Gas sensor/detection", "Infrared sensor/detection",
|
275 |
+
"Ultraviolet sensor/detection", "Radiation sensor/detection", "Magnetic sensor/detection", "Electric field sensor/detection", "Chemical sensor/detection",
|
276 |
+
"Biosignal sensor/detection", "Vibration sensor/detection", "Noise sensor/detection", "Light intensity sensor/detection", "Light wavelength sensor/detection",
|
277 |
+
"Tilt sensor/detection", "pH sensor/detection", "Current sensor/detection", "Voltage sensor/detection", "Image sensor/detection",
|
278 |
+
"Distance sensor/detection", "Depth sensor/detection", "Gravity sensor/detection", "Speed sensor/detection", "Flow sensor/detection",
|
279 |
+
"Water level sensor/detection", "Turbidity sensor/detection", "Salinity sensor/detection", "Metal detection", "Piezoelectric sensor/detection",
|
280 |
+
"Photovoltaic sensor/detection", "Thermocouple sensor/detection", "Hall effect sensor/detection", "Ultrasonic sensor/detection", "Radar sensor/detection",
|
281 |
+
"Lidar sensor/detection", "Touch sensor/detection", "Gesture sensor/detection", "Heart rate sensor/detection", "Blood pressure sensor/detection"
|
282 |
],
|
283 |
+
"Size and Shape Change": [
|
284 |
+
"Volume increase/decrease", "Length increase/decrease", "Width increase/decrease", "Height increase/decrease",
|
285 |
+
"Density change", "Weight increase/decrease", "Shape deformation", "State change", "Uneven deformation",
|
286 |
+
"Complex shape deformation", "Twisting/entwining", "Non-uniform expansion/contraction", "Rounded/sharpened edges",
|
287 |
+
"Cracking/splitting", "Fragmentation", "Water resistance", "Dust resistance", "Denting/recovery",
|
288 |
+
"Folding/unfolding", "Compression/expansion", "Stretching/contraction", "Wrinkling/flattening", "Crushing/hardening",
|
289 |
+
"Rolling/unrolling", "Bending/curving"
|
290 |
],
|
291 |
+
"Surface and Appearance Change": [
|
292 |
+
"Color change", "Texture change", "Transparency change", "Glossy/matte change",
|
293 |
+
"Light reflection variation", "Pattern change", "Angle-dependent color change", "Light-induced color change",
|
294 |
+
"Temperature-dependent color change", "Holographic effect", "Angle-specific light reflection", "Surface shape alteration",
|
295 |
+
"Nano-scale surface structure change", "Self-cleaning effect", "Stain/pattern formation", "Blurriness/clarity change",
|
296 |
+
"Luster/shine change", "Hue/saturation change", "Luminescence/fluorescence", "Light scattering effect",
|
297 |
+
"Light absorption change", "Translucency effect", "Shadow effect change", "UV response change",
|
298 |
+
"Glow effect"
|
299 |
],
|
300 |
+
"Material State Change": [
|
301 |
+
"Solid/liquid/gas transition", "Crystallization/dissolution", "Oxidation/corrosion", "Hardening/softening",
|
302 |
+
"Special state transition", "Amorphous/crystalline transition", "Component separation", "Particle formation/disintegration",
|
303 |
+
"Gel formation/dissolution", "Metastable state change", "Molecular self-assembly/disintegration", "Delayed state change",
|
304 |
+
"Melting", "Solidification", "Evaporation/condensation", "Sublimation/deposition", "Precipitation/suspension", "Dispersion/aggregation",
|
305 |
+
"Drying/moistening", "Swelling/shrinkage", "Freezing/thawing", "Weathering/erosion", "Charging/discharging",
|
306 |
+
"Bonding/separation", "Fermentation/decay"
|
307 |
],
|
308 |
+
"Movement Characteristics Change": [
|
309 |
+
"Acceleration/deceleration", "Maintaining constant speed", "Vibration/vibration reduction", "Collision/bouncing",
|
310 |
+
"Increase/decrease in rotational speed", "Change in rotational direction", "Irregular movement", "Stop-and-slide phenomenon",
|
311 |
+
"Resonance/anti-resonance", "Resistance/lift change in fluid", "Change in movement resistance", "Complex vibrational movement",
|
312 |
+
"Movement in special fluid", "Rotational-translational movement", "Inertial stoppage", "Shock absorption",
|
313 |
+
"Shock transfer", "Conservation of momentum", "Friction change", "Overcoming inertia", "Unstable equilibrium",
|
314 |
+
"Dynamic stability", "Damping of oscillation", "Path predictability", "Evasive movement"
|
315 |
+
],
|
316 |
+
"Structural Change": [
|
317 |
+
"Addition/removal of components", "Assembly/disassembly", "Folding/unfolding", "Deformation/recovery", "Optimal structural change",
|
318 |
+
"Self-rearrangement", "Natural pattern formation/disappearance", "Regular pattern change", "Modular transformation",
|
319 |
+
"Increased structural complexity", "Memory of original shape effect", "Shape change over time", "Partial removal",
|
320 |
+
"Partial replacement", "Bonding", "Separation", "Division/integration", "Overlaying", "Internal structure change",
|
321 |
+
"External structure change", "Shift of center axis", "Balance point change", "Hierarchical structure change", "Support structure change",
|
322 |
+
"Stress distribution structure", "Shock absorption structure", "Grid/matrix structure change", "Interconnectivity change"
|
323 |
+
],
|
324 |
+
"Spatial Movement": [
|
325 |
+
"Forward/backward movement", "Left/right movement", "Up/down movement", "Vertical axis rotation (nodding)",
|
326 |
+
"Horizontal axis rotation (shaking head)", "Longitudinal axis rotation (tilting sideways)", "Circular motion", "Spiral movement",
|
327 |
+
"Slipping due to inertia", "Change of rotation axis", "Irregular rotation", "Shaking movement", "Parabolic motion",
|
328 |
+
"Zero-gravity floating", "Floating on water surface", "Jump/leap", "Sliding", "Rolling", "Free fall",
|
329 |
+
"Reciprocating motion", "Elastic bouncing", "Penetration", "Evasive movement", "Zigzag movement", "Swinging movement"
|
330 |
+
],
|
331 |
+
"Time-Related Change": [
|
332 |
+
"Aging/weathering", "Wear/corrosion", "Fading/discoloration", "Damage/recovery", "Lifecycle change",
|
333 |
+
"Adaptation through user interaction", "Learning-based shape optimization", "Property change over time",
|
334 |
+
"Collective memory effect", "Cultural significance change", "Delayed response", "History-dependent change",
|
335 |
+
"Gradual time change", "Evolutionary change", "Periodic regeneration", "Seasonal adaptation",
|
336 |
+
"Circadian rhythm change", "Lifecycle stage", "Growth/decline", "Self-repair/regeneration",
|
337 |
+
"Natural cycle adaptation", "Persistence/transience", "Memory effect", "Delayed effect", "Cumulative effect"
|
338 |
+
],
|
339 |
+
"Light and Visual Effects": [
|
340 |
+
"Illumination/shutdown", "Light transmission/blocking", "Light scattering/concentration", "Color spectrum change", "Light diffraction",
|
341 |
+
"Light interference", "Hologram creation", "Laser effect", "Light polarization", "Fluorescence/phosphorescence",
|
342 |
+
"UV/IR emission", "Optical illusion", "Light refraction", "Shadow creation/removal",
|
343 |
+
"Chromatic aberration", "Rainbow effect", "Glow effect", "Flash effect", "Lighting pattern",
|
344 |
+
"Beam effect", "Light filter effect", "Change in light direction", "Projection effect", "Light detection/response",
|
345 |
+
"Luminance change"
|
346 |
],
|
347 |
+
"Sound and Vibration Effects": [
|
348 |
+
"Sound generation/cessation", "Pitch change", "Volume change", "Timbre change",
|
349 |
+
"Resonance/antiresonance", "Acoustic vibration", "Ultrasonic/infrasonic emission", "Sound concentration/distribution",
|
350 |
+
"Sound reflection/absorption", "Acoustic Doppler effect", "Sound wave interference", "Acoustic resonance",
|
351 |
+
"Vibration pattern change", "Percussive effect", "Audio feedback", "Sound shielding/amplification",
|
352 |
+
"Directional sound", "Sound distortion", "Beat generation", "Harmonics generation", "Frequency modulation",
|
353 |
+
"Acoustic shockwave", "Sound filtering"
|
354 |
+
],
|
355 |
+
"Thermal Changes": [
|
356 |
+
"Temperature rise/fall", "Thermal expansion/contraction", "Heat transfer/blocking", "Pressure increase/decrease",
|
357 |
+
"Magnetization due to heat change", "Entropy change", "Thermoelectric effect", "Magnetic-induced thermal change",
|
358 |
+
"Heat storage/release during phase change", "Thermal stress buildup/release", "Impact of rapid temperature change",
|
359 |
+
"Radiative cooling/heating", "Exothermic/endothermic", "Heat distribution change", "Heat reflection/absorption",
|
360 |
+
"Cooling condensation", "Thermal activation", "Thermal discoloration", "Coefficient of thermal expansion change", "Thermal stability change",
|
361 |
+
"Heat resistance/cold resistance", "Self-heating", "Thermal equilibrium/imbalance", "Thermal deformation", "Heat dispersion/concentration"
|
362 |
+
],
|
363 |
+
"Electrical and Magnetic Changes": [
|
364 |
+
"Magnetism creation/cessation", "Charge increase/decrease", "Electric field creation/cessation", "Magnetic field creation/cessation",
|
365 |
+
"Superconducting transition", "Ferroelectric property change", "Quantum state change", "Plasma formation/cessation",
|
366 |
+
"Spin wave transmission", "Electricity generation by light", "Electricity generation by pressure", "Current change in magnetic field",
|
367 |
+
"Electrical resistance change", "Electrical conductivity change", "Static electricity generation/discharge", "Electromagnetic induction",
|
368 |
+
"Electromagnetic wave emission/absorption", "Capacitance change", "Magnetic hysteresis", "Electrical polarization",
|
369 |
+
"Electron flow direction change", "Electrical resonance", "Electrical shielding/exposure", "Magnetic shielding/exposure",
|
370 |
+
"Magnetic field alignment"
|
371 |
+
],
|
372 |
+
"Chemical Change": [
|
373 |
+
"Surface coating change", "Material composition change", "Chemical reaction change", "Catalytic action start/stop",
|
374 |
+
"Light-induced chemical reaction", "Electricity-induced chemical reaction", "Monolayer formation", "Molecular-level structural change",
|
375 |
+
"Biomimetic surface change", "Environmentally responsive material change", "Periodic chemical reaction", "Oxidation", "Reduction",
|
376 |
+
"Polymerization", "Water splitting", "Compound formation", "Radiation effects", "Acid-base reaction", "Neutralization reaction",
|
377 |
+
"Ionization", "Chemical adsorption/desorption", "Catalytic efficiency change", "Enzyme activity change", "Colorimetric reaction",
|
378 |
+
"pH change", "Chemical equilibrium shift", "Bond formation/breakage", "Solubility change"
|
379 |
+
],
|
380 |
+
"Biological Change": [
|
381 |
+
"Growth/shrinkage", "Cell division/death", "Bioluminescence", "Metabolic change", "Immune response",
|
382 |
+
"Hormone secretion", "Neural response", "Genetic expression", "Adaptation/evolution", "Circadian rhythm change",
|
383 |
+
"Regeneration/healing", "Aging/maturation", "Biomimetic change", "Biofilm formation", "Biological degradation",
|
384 |
+
"Enzyme activation/inactivation", "Biological signaling", "Stress response", "Thermoregulation", "Biological clock change",
|
385 |
+
"Extracellular matrix change", "Biomechanical response", "Cell motility", "Cell polarity change", "Nutritional status change"
|
386 |
+
],
|
387 |
+
"Environmental Interaction": [
|
388 |
+
"Temperature response", "Humidity response", "Pressure response", "Gravity response", "Magnetic field response",
|
389 |
+
"Light response", "Sound response", "Chemical detection", "Mechanical stimulus detection", "Electrical stimulus response",
|
390 |
+
"Radiation response", "Vibration detection", "pH response", "Solvent response", "Gas exchange",
|
391 |
+
"Pollution response", "Weather response", "Seasonal response", "Circadian response", "Ecosystem interaction",
|
392 |
+
"Symbiotic/competitive interaction", "Predator/prey relationship", "Swarm formation", "Territorial behavior", "Migration/settlement pattern"
|
393 |
]
|
|
|
394 |
}
|
395 |
|
396 |
##############################################################################
|
397 |
+
# Gemini API Call Function (Language Independent)
|
398 |
##############################################################################
|
399 |
def query_gemini_api(prompt):
|
400 |
try:
|
|
|
424 |
return f"An error occurred while calling the API: {str(e)}"
|
425 |
|
426 |
##############################################################################
|
427 |
+
# Description Expansion Functions (LLM) - Korean and English Versions
|
428 |
##############################################################################
|
429 |
def enhance_with_llm(base_description, obj_name, category):
|
430 |
prompt = f"""
|
|
|
437 |
"""
|
438 |
return query_gemini_api(prompt)
|
439 |
|
440 |
+
def enhance_with_llm_en(base_description, obj_name, category):
|
441 |
+
prompt = f"""
|
442 |
+
Below is a brief description related to '{category}' for '{obj_name}':
|
443 |
+
"{base_description}"
|
444 |
+
Please expand the above content into a more detailed explanation, focusing on:
|
445 |
+
1) Creative transformation of the model/concept/shape,
|
446 |
+
2) Innovative aspects and functionality,
|
447 |
+
in 3-4 sentences.
|
448 |
+
"""
|
449 |
+
return query_gemini_api(prompt)
|
450 |
+
|
451 |
##############################################################################
|
452 |
+
# Transformation Idea Generation Functions for Both Languages
|
453 |
##############################################################################
|
454 |
+
def generate_single_object_transformation_for_category_lang(obj, selected_category, categories_dict, lang="ko"):
|
455 |
+
transformations = categories_dict.get(selected_category)
|
456 |
if not transformations:
|
457 |
return {}
|
458 |
transformation = choose_alternative(random.choice(transformations))
|
459 |
+
if lang == "ko":
|
460 |
+
base_description = f"{obj}μ΄(κ°) {transformation} νμμ 보μΈλ€"
|
461 |
+
else:
|
462 |
+
base_description = f"{obj} exhibits {transformation}"
|
463 |
return {selected_category: {"base": base_description, "enhanced": None}}
|
464 |
|
465 |
+
def generate_two_objects_interaction_for_category_lang(obj1, obj2, selected_category, categories_dict, lang="ko"):
|
466 |
+
transformations = categories_dict.get(selected_category)
|
467 |
if not transformations:
|
468 |
return {}
|
469 |
transformation = choose_alternative(random.choice(transformations))
|
470 |
+
if lang == "ko":
|
471 |
+
template = random.choice([
|
472 |
+
"{obj1}μ΄(κ°) {obj2}μ κ²°ν©νμ¬ {change}κ° λ°μνλ€",
|
473 |
+
"{obj1}κ³Ό(μ) {obj2}μ΄(κ°) μΆ©λνλ©΄μ {change}κ° μΌμ΄λ¬λ€"
|
474 |
+
])
|
475 |
+
else:
|
476 |
+
template = random.choice([
|
477 |
+
"{obj1} combined with {obj2} resulted in {change}",
|
478 |
+
"A collision between {obj1} and {obj2} led to {change}"
|
479 |
+
])
|
480 |
base_description = template.format(obj1=obj1, obj2=obj2, change=transformation)
|
481 |
return {selected_category: {"base": base_description, "enhanced": None}}
|
482 |
|
483 |
+
def generate_three_objects_interaction_for_category_lang(obj1, obj2, obj3, selected_category, categories_dict, lang="ko"):
|
484 |
+
transformations = categories_dict.get(selected_category)
|
485 |
if not transformations:
|
486 |
return {}
|
487 |
transformation = choose_alternative(random.choice(transformations))
|
488 |
+
if lang == "ko":
|
489 |
+
template = random.choice([
|
490 |
+
"{obj1}, {obj2}, {obj3}μ΄(κ°) μΌκ°ν κ΅¬μ‘°λ‘ κ²°ν©νμ¬ {change}κ° λ°μνλ€",
|
491 |
+
"{obj1}μ΄(κ°) {obj2}μ(κ³Ό) {obj3} μ¬μ΄μμ λ§€κ°μ²΄ μν μ νλ©° {change}λ₯Ό μ΄μ§νλ€"
|
492 |
+
])
|
493 |
+
else:
|
494 |
+
template = random.choice([
|
495 |
+
"{obj1}, {obj2}, and {obj3} formed a triangular structure resulting in {change}",
|
496 |
+
"{obj1} acted as an intermediary between {obj2} and {obj3}, facilitating {change}"
|
497 |
+
])
|
498 |
base_description = template.format(obj1=obj1, obj2=obj2, obj3=obj3, change=transformation)
|
499 |
return {selected_category: {"base": base_description, "enhanced": None}}
|
500 |
|
501 |
+
def enhance_descriptions_lang(results, objects, lang="ko"):
|
502 |
+
obj_name = " λ° ".join([obj for obj in objects if obj]) if lang=="ko" else " and ".join([obj for obj in objects if obj])
|
|
|
|
|
|
|
503 |
for category, result in results.items():
|
504 |
+
if lang == "ko":
|
505 |
+
result["enhanced"] = enhance_with_llm(result["base"], obj_name, category)
|
506 |
+
else:
|
507 |
+
result["enhanced"] = enhance_with_llm_en(result["base"], obj_name, category)
|
508 |
return results
|
509 |
|
510 |
+
def generate_transformations_lang(text1, text2, text3, selected_category, categories_dict, lang="ko"):
|
|
|
|
|
|
|
511 |
if text2 and text3:
|
512 |
+
results = generate_three_objects_interaction_for_category_lang(text1, text2, text3, selected_category, categories_dict, lang)
|
513 |
objects = [text1, text2, text3]
|
514 |
elif text2:
|
515 |
+
results = generate_two_objects_interaction_for_category_lang(text1, text2, selected_category, categories_dict, lang)
|
516 |
objects = [text1, text2]
|
517 |
else:
|
518 |
+
results = generate_single_object_transformation_for_category_lang(text1, selected_category, categories_dict, lang)
|
519 |
objects = [text1]
|
520 |
+
return enhance_descriptions_lang(results, objects, lang)
|
521 |
|
522 |
+
def format_results_lang(results, lang="ko"):
|
|
|
|
|
|
|
523 |
formatted = ""
|
524 |
+
if lang == "ko":
|
525 |
+
for category, result in results.items():
|
526 |
+
formatted += f"## {category}\n**κΈ°λ³Έ μμ΄λμ΄**: {result['base']}\n\n**νμ₯λ μμ΄λμ΄**: {result['enhanced']}\n\n---\n\n"
|
527 |
+
else:
|
528 |
+
for category, result in results.items():
|
529 |
+
formatted += f"## {category}\n**Base Idea**: {result['base']}\n\n**Expanded Idea**: {result['enhanced']}\n\n---\n\n"
|
530 |
return formatted
|
531 |
|
532 |
+
def process_inputs_lang(text1, text2, text3, selected_category, categories_dict, lang="ko", progress=gr.Progress()):
|
|
|
|
|
|
|
533 |
text1 = text1.strip() if text1 else None
|
534 |
text2 = text2.strip() if text2 else None
|
535 |
text3 = text3.strip() if text3 else None
|
536 |
|
537 |
if not text1:
|
538 |
+
return "μ€λ₯: μ΅μ νλμ ν€μλλ₯Ό μ
λ ₯ν΄μ£ΌμΈμ." if lang=="ko" else "Error: Please enter at least one keyword."
|
539 |
|
540 |
+
if lang == "ko":
|
541 |
+
progress(0.05, desc="μμ΄λμ΄ μμ± μ€λΉ μ€...")
|
542 |
+
time.sleep(0.3)
|
543 |
+
progress(0.1, desc="μ°½μμ μΈ μμ΄λμ΄ μμ± μμ...")
|
544 |
+
else:
|
545 |
+
progress(0.05, desc="Preparing idea generation...")
|
546 |
+
time.sleep(0.3)
|
547 |
+
progress(0.1, desc="Generating creative idea...")
|
548 |
|
549 |
+
results = generate_transformations_lang(text1, text2, text3, selected_category, categories_dict, lang)
|
550 |
|
551 |
+
if lang == "ko":
|
552 |
+
progress(0.8, desc="κ²°κ³Ό ν¬λ§·ν
μ€...")
|
553 |
+
formatted = format_results_lang(results, lang)
|
554 |
+
progress(1.0, desc="μλ£!")
|
555 |
+
else:
|
556 |
+
progress(0.8, desc="Formatting results...")
|
557 |
+
formatted = format_results_lang(results, lang)
|
558 |
+
progress(1.0, desc="Done!")
|
559 |
return formatted
|
560 |
|
561 |
+
def process_all_lang(text1, text2, text3, selected_category, categories_dict, lang="ko", progress=gr.Progress()):
|
562 |
+
idea_result = process_inputs_lang(text1, text2, text3, selected_category, categories_dict, lang, progress)
|
|
|
|
|
|
|
563 |
image_result = generate_design_image(
|
564 |
idea_result,
|
565 |
seed=42,
|
|
|
571 |
return idea_result, image_result
|
572 |
|
573 |
##############################################################################
|
574 |
+
# Warning Message Function for API Key (Language Specific)
|
575 |
##############################################################################
|
576 |
+
def get_warning_message_lang(lang="ko"):
|
577 |
if not GEMINI_API_KEY:
|
578 |
+
return "β οΈ νκ²½ λ³μ GEMINI_API_KEYκ° μ€μ λμ§ μμμ΅λλ€. Gemini API ν€λ₯Ό μ€μ νμΈμ." if lang=="ko" else "β οΈ The GEMINI_API_KEY environment variable is not set. Please set your Gemini API key."
|
579 |
return ""
|
580 |
|
581 |
+
|
582 |
##############################################################################
|
583 |
+
# Gradio UI with Two Tabs: English (Main Home) and Korean
|
584 |
##############################################################################
|
585 |
with gr.Blocks(
|
586 |
+
title="Idea Transformer",
|
587 |
theme=gr.themes.Soft(primary_hue="teal", secondary_hue="slate", neutral_hue="neutral")
|
588 |
) as demo:
|
589 |
|
|
|
625 |
</style>
|
626 |
""")
|
627 |
|
628 |
+
with gr.Tabs():
|
629 |
+
with gr.Tab(label="English"):
|
630 |
+
gr.Markdown("# π Idea Transformer")
|
631 |
+
gr.Markdown("Based on up to **three keywords** and a **selected category**, this tool generates a creative transformation idea and a design image using the expanded idea as a prompt.")
|
632 |
+
|
633 |
+
warning_en = gr.Markdown(get_warning_message_lang("en"))
|
634 |
+
|
635 |
+
with gr.Row():
|
636 |
+
with gr.Column(scale=1):
|
637 |
+
text_input1_en = gr.Textbox(label="Keyword 1 (required)", placeholder="e.g., Smartphone")
|
638 |
+
text_input2_en = gr.Textbox(label="Keyword 2 (optional)", placeholder="e.g., Artificial Intelligence")
|
639 |
+
text_input3_en = gr.Textbox(label="Keyword 3 (optional)", placeholder="e.g., Healthcare")
|
640 |
+
category_radio_en = gr.Radio(
|
641 |
+
label="Select Category",
|
642 |
+
choices=list(physical_transformation_categories_en.keys()),
|
643 |
+
value=list(physical_transformation_categories_en.keys())[0],
|
644 |
+
info="Select a category."
|
645 |
+
)
|
646 |
+
status_msg_en = gr.Markdown("π‘ Click the 'Generate Idea' button to create an idea and design image based on the selected category.")
|
647 |
+
|
648 |
+
processing_indicator_en = gr.HTML("""
|
649 |
+
<div style="display: flex; justify-content: center; align-items: center; margin: 10px 0;">
|
650 |
+
<div style="border: 5px solid #f3f3f3; border-top: 5px solid #3498db; border-radius: 50%; width: 30px; height: 30px; animation: spin 2s linear infinite;"></div>
|
651 |
+
<p style="margin-left: 10px; font-weight: bold; color: #3498db;">Processing...</p>
|
652 |
+
</div>
|
653 |
+
<style>
|
654 |
+
@keyframes spin {
|
655 |
+
0% { transform: rotate(0deg); }
|
656 |
+
100% { transform: rotate(360deg); }
|
657 |
+
}
|
658 |
+
</style>
|
659 |
+
""", visible=False)
|
660 |
+
|
661 |
+
submit_button_en = gr.Button("Generate Idea", variant="primary")
|
662 |
+
|
663 |
+
with gr.Column(scale=2):
|
664 |
+
idea_output_en = gr.Markdown(label="Idea Output")
|
665 |
+
generated_image_en = gr.Image(label="Generated Design Image", type="pil")
|
666 |
+
|
667 |
+
gr.Examples(
|
668 |
+
examples=[
|
669 |
+
["Smartphone", "", "", "Sensor Functions"],
|
670 |
+
["Car", "", "", "Size and Shape Change"],
|
671 |
+
["Car", "Artificial Intelligence", "", "Surface and Appearance Change"],
|
672 |
+
["Drone", "Artificial Intelligence", "", "Material State Change"],
|
673 |
+
["Sneakers", "Wearable", "Health", "Structural Change"],
|
674 |
+
],
|
675 |
+
inputs=[text_input1_en, text_input2_en, text_input3_en, category_radio_en],
|
676 |
)
|
|
|
677 |
|
678 |
+
def show_processing_indicator_en():
|
679 |
+
return gr.update(visible=True)
|
680 |
+
|
681 |
+
def hide_processing_indicator_en():
|
682 |
+
return gr.update(visible=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
683 |
|
684 |
+
submit_button_en.click(
|
685 |
+
fn=show_processing_indicator_en,
|
686 |
+
inputs=None,
|
687 |
+
outputs=processing_indicator_en
|
688 |
+
).then(
|
689 |
+
fn=process_all_lang,
|
690 |
+
inputs=[text_input1_en, text_input2_en, text_input3_en, category_radio_en, gr.State(physical_transformation_categories_en), gr.State("en")],
|
691 |
+
outputs=[idea_output_en, generated_image_en]
|
692 |
+
).then(
|
693 |
+
fn=hide_processing_indicator_en,
|
694 |
+
inputs=None,
|
695 |
+
outputs=processing_indicator_en
|
696 |
+
)
|
697 |
|
698 |
+
with gr.Tab(label="νκ΅μ΄"):
|
699 |
+
gr.Markdown("# π μμ΄λμ΄ νΈλμ€ν¬λ¨Έ")
|
700 |
+
gr.Markdown("μ
λ ₯ν **ν€μλ**(μ΅λ 3κ°)μ **μΉ΄ν
κ³ λ¦¬**λ₯Ό λ°νμΌλ‘, μ°½μμ μΈ λͺ¨λΈ/컨μ
/νμ λ³ν μμ΄λμ΄λ₯Ό μμ±νκ³ , ν΄λΉ νμ₯ μμ΄λμ΄λ₯Ό ν둬ννΈλ‘ νμ¬ λμμΈ μ΄λ―Έμ§λ₯Ό μμ±ν©λλ€.")
|
701 |
+
|
702 |
+
warning_ko = gr.Markdown(get_warning_message_lang("ko"))
|
703 |
+
|
704 |
+
with gr.Row():
|
705 |
+
with gr.Column(scale=1):
|
706 |
+
text_input1_ko = gr.Textbox(label="ν€μλ 1 (νμ)", placeholder="μ: μ€λ§νΈν°")
|
707 |
+
text_input2_ko = gr.Textbox(label="ν€μλ 2 (μ ν)", placeholder="μ: μΈκ³΅μ§λ₯")
|
708 |
+
text_input3_ko = gr.Textbox(label="ν€μλ 3 (μ ν)", placeholder="μ: ν¬μ€μΌμ΄")
|
709 |
+
category_radio_ko = gr.Radio(
|
710 |
+
label="μΉ΄ν
κ³ λ¦¬ μ ν",
|
711 |
+
choices=list(physical_transformation_categories.keys()),
|
712 |
+
value=list(physical_transformation_categories.keys())[0],
|
713 |
+
info="μΆλ ₯ν μΉ΄ν
κ³ λ¦¬λ₯Ό μ ννμΈμ."
|
714 |
+
)
|
715 |
+
status_msg_ko = gr.Markdown("π‘ 'μμ΄λμ΄ μμ±νκΈ°' λ²νΌμ ν΄λ¦νλ©΄ μ νν μΉ΄ν
κ³ λ¦¬μ ν΄λΉνλ μμ΄λμ΄μ λμμΈ μ΄λ―Έμ§κ° μμ±λ©λλ€.")
|
716 |
+
|
717 |
+
processing_indicator_ko = gr.HTML("""
|
718 |
+
<div style="display: flex; justify-content: center; align-items: center; margin: 10px 0;">
|
719 |
+
<div style="border: 5px solid #f3f3f3; border-top: 5px solid #3498db; border-radius: 50%; width: 30px; height: 30px; animation: spin 2s linear infinite;"></div>
|
720 |
+
<p style="margin-left: 10px; font-weight: bold; color: #3498db;">μ²λ¦¬ μ€μ
λλ€...</p>
|
721 |
+
</div>
|
722 |
+
<style>
|
723 |
+
@keyframes spin {
|
724 |
+
0% { transform: rotate(0deg); }
|
725 |
+
100% { transform: rotate(360deg); }
|
726 |
+
}
|
727 |
+
</style>
|
728 |
+
""", visible=False)
|
729 |
+
|
730 |
+
submit_button_ko = gr.Button("μμ΄λμ΄ μμ±νκΈ°", variant="primary")
|
731 |
+
|
732 |
+
with gr.Column(scale=2):
|
733 |
+
idea_output_ko = gr.Markdown(label="μμ΄λμ΄ κ²°κ³Ό")
|
734 |
+
generated_image_ko = gr.Image(label="μμ±λ λμμΈ μ΄λ―Έμ§", type="pil")
|
735 |
+
|
736 |
+
gr.Examples(
|
737 |
+
examples=[
|
738 |
+
["μ€λ§νΈν°", "", "", "μΌμ κΈ°λ₯"],
|
739 |
+
["μλμ°¨", "", "", "ν¬κΈ°μ νν λ³ν"],
|
740 |
+
["μλμ°¨", "μΈκ³΅μ§λ₯", "", "νλ©΄ λ° μΈκ΄ λ³ν"],
|
741 |
+
["λλ‘ ", "μΈκ³΅μ§λ₯", "", "λ¬Όμ§μ μν λ³ν"],
|
742 |
+
["μ΄λν", "μ¨μ΄λ¬λΈ", "건κ°", "ꡬ쑰μ λ³ν"],
|
743 |
+
],
|
744 |
+
inputs=[text_input1_ko, text_input2_ko, text_input3_ko, category_radio_ko],
|
745 |
+
)
|
746 |
+
|
747 |
+
def show_processing_indicator_ko():
|
748 |
+
return gr.update(visible=True)
|
749 |
+
|
750 |
+
def hide_processing_indicator_ko():
|
751 |
+
return gr.update(visible=False)
|
752 |
+
|
753 |
+
submit_button_ko.click(
|
754 |
+
fn=show_processing_indicator_ko,
|
755 |
+
inputs=None,
|
756 |
+
outputs=processing_indicator_ko
|
757 |
+
).then(
|
758 |
+
fn=process_all_lang,
|
759 |
+
inputs=[text_input1_ko, text_input2_ko, text_input3_ko, category_radio_ko, gr.State(physical_transformation_categories), gr.State("ko")],
|
760 |
+
outputs=[idea_output_ko, generated_image_ko]
|
761 |
+
).then(
|
762 |
+
fn=hide_processing_indicator_ko,
|
763 |
+
inputs=None,
|
764 |
+
outputs=processing_indicator_ko
|
765 |
+
)
|
766 |
|
767 |
if __name__ == "__main__":
|
768 |
demo.launch(debug=True)
|