Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -30,6 +30,7 @@ except Exception as e:
|
|
30 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
31 |
|
32 |
dtype = torch.bfloat16 if device == "cuda" else torch.float32
|
|
|
33 |
print(f"Using device: {device}, dtype: {dtype}")
|
34 |
|
35 |
##############################################################################
|
@@ -41,15 +42,18 @@ try:
|
|
41 |
model="Helsinki-NLP/opus-mt-ko-en",
|
42 |
device=0 if device == "cuda" else -1
|
43 |
)
|
|
|
44 |
pipe = DiffusionPipeline.from_pretrained(
|
45 |
"black-forest-labs/FLUX.1-schnell",
|
46 |
torch_dtype=dtype
|
47 |
).to(device)
|
|
|
48 |
print("Models loaded successfully")
|
49 |
except Exception as e:
|
50 |
print(f"Error loading models: {e}")
|
51 |
def dummy_translator(text):
|
52 |
return [{'translation_text': text}]
|
|
|
53 |
class DummyPipe:
|
54 |
def __call__(self, **kwargs):
|
55 |
from PIL import Image
|
@@ -59,6 +63,7 @@ except Exception as e:
|
|
59 |
def __init__(self, img):
|
60 |
self.images = [img]
|
61 |
return DummyResult(dummy_img)
|
|
|
62 |
translator = dummy_translator
|
63 |
pipe = DummyPipe()
|
64 |
|
@@ -97,19 +102,25 @@ def log_unexpected_characters(text):
|
|
97 |
def generate_design_image(prompt, seed=42, randomize_seed=True, width=1024, height=1024, num_inference_steps=4):
|
98 |
original_prompt = prompt
|
99 |
translated = False
|
|
|
100 |
# Clean the input text
|
101 |
prompt = clean_input_text(prompt)
|
|
|
102 |
# Pre-process: if input is too long, trim to 1000 characters
|
103 |
if len(prompt) > 1000:
|
104 |
prompt = prompt[:1000]
|
|
|
105 |
if contains_korean(prompt):
|
106 |
# When calling translation, add max_length and truncation options to avoid length issues
|
107 |
translation = translator(prompt, max_length=400, truncation=True)
|
108 |
prompt = translation[0]['translation_text']
|
109 |
translated = True
|
|
|
110 |
if randomize_seed:
|
111 |
seed = random.randint(0, MAX_SEED)
|
|
|
112 |
generator = torch.Generator(device=device).manual_seed(seed)
|
|
|
113 |
image = pipe(
|
114 |
prompt=prompt,
|
115 |
width=width,
|
@@ -118,6 +129,7 @@ def generate_design_image(prompt, seed=42, randomize_seed=True, width=1024, heig
|
|
118 |
generator=generator,
|
119 |
guidance_scale=0.0
|
120 |
).images[0]
|
|
|
121 |
return image
|
122 |
|
123 |
##############################################################################
|
@@ -245,6 +257,271 @@ physical_transformation_categories = {
|
|
245 |
"광도 변화"
|
246 |
],
|
247 |
"소리와 진동 효과": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
248 |
"Sound generation/cessation", "Pitch change", "Volume change", "Timbre change",
|
249 |
"Resonance/antiresonance", "Acoustic vibration", "Ultrasonic/infrasonic emission", "Sound concentration/distribution",
|
250 |
"Sound reflection/absorption", "Acoustic Doppler effect", "Sound wave interference", "Acoustic resonance",
|
@@ -290,7 +567,20 @@ physical_transformation_categories = {
|
|
290 |
"Radiation response", "Vibration detection", "pH response", "Solvent response", "Gas exchange",
|
291 |
"Pollution response", "Weather response", "Seasonal response", "Circadian response", "Ecosystem interaction",
|
292 |
"Symbiotic/competitive interaction", "Predator/prey relationship", "Swarm formation", "Territorial behavior", "Migration/settlement pattern"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
293 |
]
|
|
|
294 |
}
|
295 |
|
296 |
##############################################################################
|
@@ -433,8 +723,10 @@ def process_inputs_lang(text1, text2, text3, selected_category, categories_dict,
|
|
433 |
text1 = text1.strip() if text1 else None
|
434 |
text2 = text2.strip() if text2 else None
|
435 |
text3 = text3.strip() if text3 else None
|
|
|
436 |
if not text1:
|
437 |
return "오류: 최소 하나의 키워드를 입력해주세요." if lang=="ko" else "Error: Please enter at least one keyword."
|
|
|
438 |
if lang == "ko":
|
439 |
progress(0.05, desc="아이디어 생성 준비 중...")
|
440 |
time.sleep(0.3)
|
@@ -443,7 +735,9 @@ def process_inputs_lang(text1, text2, text3, selected_category, categories_dict,
|
|
443 |
progress(0.05, desc="Preparing idea generation...")
|
444 |
time.sleep(0.3)
|
445 |
progress(0.1, desc="Generating creative idea...")
|
|
|
446 |
results = generate_transformations_lang(text1, text2, text3, selected_category, categories_dict, lang)
|
|
|
447 |
if lang == "ko":
|
448 |
progress(0.8, desc="결과 포맷팅 중...")
|
449 |
formatted = format_results_lang(results, lang)
|
@@ -474,41 +768,6 @@ def get_warning_message_lang(lang="ko"):
|
|
474 |
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."
|
475 |
return ""
|
476 |
|
477 |
-
##############################################################################
|
478 |
-
# Add "Business Ideas" category to each dictionary
|
479 |
-
##############################################################################
|
480 |
-
physical_transformation_categories["비즈니스 아이디어"] = [
|
481 |
-
"시장 재정의/신규 시장 개척",
|
482 |
-
"비즈니스 모델 혁신/디지털 전환",
|
483 |
-
"고객 경험 혁신/서비스 혁신",
|
484 |
-
"협력 및 파트너십 강화/생태계 구축",
|
485 |
-
"글로벌 확장/지역화 전략",
|
486 |
-
"운영 효율성 증대/원가 절감",
|
487 |
-
"브랜드 리포지셔닝/이미지 전환",
|
488 |
-
"지속 가능한 성장/사회적 가치 창출",
|
489 |
-
"데이터 기반 의사결정/AI 도입",
|
490 |
-
"신기술 융합/혁신 투자"
|
491 |
-
]
|
492 |
-
|
493 |
-
physical_transformation_categories_en["Business Ideas"] = [
|
494 |
-
"Market redefinition/new market creation",
|
495 |
-
"Business model innovation/digital transformation",
|
496 |
-
"Customer experience and service innovation",
|
497 |
-
"Enhanced partnerships and ecosystem building",
|
498 |
-
"Global expansion and localization strategy",
|
499 |
-
"Operational efficiency improvement/cost reduction",
|
500 |
-
"Brand repositioning/image transformation",
|
501 |
-
"Sustainable growth and social value creation",
|
502 |
-
"Data-driven decision making/AI adoption",
|
503 |
-
"Convergence of new technologies/innovative investments"
|
504 |
-
]
|
505 |
-
|
506 |
-
##############################################################################
|
507 |
-
# Helper function for caching examples in the English tab
|
508 |
-
##############################################################################
|
509 |
-
def process_all_lang_example(text1, text2, text3, selected_category):
|
510 |
-
# 고정된 state값(physical_transformation_categories_en, "en")으로 호출
|
511 |
-
return process_all_lang(text1, text2, text3, selected_category, physical_transformation_categories_en, "en")
|
512 |
|
513 |
##############################################################################
|
514 |
# Gradio UI with Two Tabs: English (Main Home) and Korean
|
@@ -517,6 +776,7 @@ with gr.Blocks(
|
|
517 |
title="Idea Transformer",
|
518 |
theme=gr.themes.Soft(primary_hue="teal", secondary_hue="slate", neutral_hue="neutral")
|
519 |
) as demo:
|
|
|
520 |
gr.HTML("""
|
521 |
<style>
|
522 |
body {
|
@@ -559,7 +819,9 @@ with gr.Blocks(
|
|
559 |
with gr.Tab(label="English"):
|
560 |
gr.Markdown("# 🚀 Idea Transformer")
|
561 |
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. https://discord.gg/openfreeai")
|
|
|
562 |
warning_en = gr.Markdown(get_warning_message_lang("en"))
|
|
|
563 |
with gr.Row():
|
564 |
with gr.Column(scale=1):
|
565 |
text_input1_en = gr.Textbox(label="Keyword 1 (required)", placeholder="e.g., Smartphone")
|
@@ -572,6 +834,7 @@ with gr.Blocks(
|
|
572 |
info="Select a category."
|
573 |
)
|
574 |
status_msg_en = gr.Markdown("💡 Click the 'Generate Idea' button to create an idea and design image based on the selected category.")
|
|
|
575 |
processing_indicator_en = gr.HTML("""
|
576 |
<div style="display: flex; justify-content: center; align-items: center; margin: 10px 0;">
|
577 |
<div style="border: 5px solid #f3f3f3; border-top: 5px solid #3498db; border-radius: 50%; width: 30px; height: 30px; animation: spin 2s linear infinite;"></div>
|
@@ -584,10 +847,13 @@ with gr.Blocks(
|
|
584 |
}
|
585 |
</style>
|
586 |
""", visible=False)
|
|
|
587 |
submit_button_en = gr.Button("Generate Idea", variant="primary")
|
|
|
588 |
with gr.Column(scale=2):
|
589 |
idea_output_en = gr.Markdown(label="Idea Output")
|
590 |
generated_image_en = gr.Image(label="Generated Design Image", type="pil")
|
|
|
591 |
gr.Examples(
|
592 |
examples=[
|
593 |
["Smartphone", "", "", "Sensor Functions"],
|
@@ -597,14 +863,14 @@ with gr.Blocks(
|
|
597 |
["Sneakers", "Wearable", "Health", "Structural Change"],
|
598 |
],
|
599 |
inputs=[text_input1_en, text_input2_en, text_input3_en, category_radio_en],
|
600 |
-
fn=process_all_lang_example,
|
601 |
-
outputs=[idea_output_en, generated_image_en],
|
602 |
-
cache_examples=True
|
603 |
)
|
|
|
604 |
def show_processing_indicator_en():
|
605 |
return gr.update(visible=True)
|
|
|
606 |
def hide_processing_indicator_en():
|
607 |
return gr.update(visible=False)
|
|
|
608 |
submit_button_en.click(
|
609 |
fn=show_processing_indicator_en,
|
610 |
inputs=None,
|
@@ -618,10 +884,13 @@ with gr.Blocks(
|
|
618 |
inputs=None,
|
619 |
outputs=processing_indicator_en
|
620 |
)
|
|
|
621 |
with gr.Tab(label="한국어"):
|
622 |
gr.Markdown("# 🚀 아이디어 트랜스포머")
|
623 |
gr.Markdown("입력한 **키워드**(최대 3개)와 **카테고리**를 바탕으로, 창의적인 모델/컨셉/형상 변화 아이디어를 생성하고, 해당 확장 아이디어를 프롬프트로 하여 디자인 이미지를 생성합니다. https://discord.gg/openfreeai")
|
|
|
624 |
warning_ko = gr.Markdown(get_warning_message_lang("ko"))
|
|
|
625 |
with gr.Row():
|
626 |
with gr.Column(scale=1):
|
627 |
text_input1_ko = gr.Textbox(label="키워드 1 (필수)", placeholder="예: 스마트폰")
|
@@ -634,6 +903,7 @@ with gr.Blocks(
|
|
634 |
info="출력할 카테고리를 선택하세요."
|
635 |
)
|
636 |
status_msg_ko = gr.Markdown("💡 '아이디어 생성하기' 버튼을 클릭하면 선택한 카테고리에 해당하는 아이디어와 디자인 이미지가 생성됩니다.")
|
|
|
637 |
processing_indicator_ko = gr.HTML("""
|
638 |
<div style="display: flex; justify-content: center; align-items: center; margin: 10px 0;">
|
639 |
<div style="border: 5px solid #f3f3f3; border-top: 5px solid #3498db; border-radius: 50%; width: 30px; height: 30px; animation: spin 2s linear infinite;"></div>
|
@@ -646,10 +916,13 @@ with gr.Blocks(
|
|
646 |
}
|
647 |
</style>
|
648 |
""", visible=False)
|
|
|
649 |
submit_button_ko = gr.Button("아이디어 생성하기", variant="primary")
|
|
|
650 |
with gr.Column(scale=2):
|
651 |
idea_output_ko = gr.Markdown(label="아이디어 결과")
|
652 |
generated_image_ko = gr.Image(label="생성된 디자인 이미지", type="pil")
|
|
|
653 |
gr.Examples(
|
654 |
examples=[
|
655 |
["스마트폰", "", "", "센서 기능"],
|
@@ -658,12 +931,15 @@ with gr.Blocks(
|
|
658 |
["드론", "인공지능", "", "물질의 상태 변화"],
|
659 |
["운동화", "웨어러블", "건강", "구조적 변화"],
|
660 |
],
|
661 |
-
inputs=[text_input1_ko, text_input2_ko, text_input3_ko, category_radio_ko]
|
662 |
)
|
|
|
663 |
def show_processing_indicator_ko():
|
664 |
return gr.update(visible=True)
|
|
|
665 |
def hide_processing_indicator_ko():
|
666 |
return gr.update(visible=False)
|
|
|
667 |
submit_button_ko.click(
|
668 |
fn=show_processing_indicator_ko,
|
669 |
inputs=None,
|
@@ -679,4 +955,4 @@ with gr.Blocks(
|
|
679 |
)
|
680 |
|
681 |
if __name__ == "__main__":
|
682 |
-
demo.launch(debug=True)
|
|
|
30 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
31 |
|
32 |
dtype = torch.bfloat16 if device == "cuda" else torch.float32
|
33 |
+
|
34 |
print(f"Using device: {device}, dtype: {dtype}")
|
35 |
|
36 |
##############################################################################
|
|
|
42 |
model="Helsinki-NLP/opus-mt-ko-en",
|
43 |
device=0 if device == "cuda" else -1
|
44 |
)
|
45 |
+
|
46 |
pipe = DiffusionPipeline.from_pretrained(
|
47 |
"black-forest-labs/FLUX.1-schnell",
|
48 |
torch_dtype=dtype
|
49 |
).to(device)
|
50 |
+
|
51 |
print("Models loaded successfully")
|
52 |
except Exception as e:
|
53 |
print(f"Error loading models: {e}")
|
54 |
def dummy_translator(text):
|
55 |
return [{'translation_text': text}]
|
56 |
+
|
57 |
class DummyPipe:
|
58 |
def __call__(self, **kwargs):
|
59 |
from PIL import Image
|
|
|
63 |
def __init__(self, img):
|
64 |
self.images = [img]
|
65 |
return DummyResult(dummy_img)
|
66 |
+
|
67 |
translator = dummy_translator
|
68 |
pipe = DummyPipe()
|
69 |
|
|
|
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
|
118 |
+
|
119 |
if randomize_seed:
|
120 |
seed = random.randint(0, MAX_SEED)
|
121 |
+
|
122 |
generator = torch.Generator(device=device).manual_seed(seed)
|
123 |
+
|
124 |
image = pipe(
|
125 |
prompt=prompt,
|
126 |
width=width,
|
|
|
129 |
generator=generator,
|
130 |
guidance_scale=0.0
|
131 |
).images[0]
|
132 |
+
|
133 |
return image
|
134 |
|
135 |
##############################################################################
|
|
|
257 |
"광도 변화"
|
258 |
],
|
259 |
"소리와 진동 효과": [
|
260 |
+
"소리 발생/소멸", "소리 높낮이 변화", "소리 크기 변화", "음색 변화",
|
261 |
+
"공명/반공명", "음향 진동", "초음파/저음파 발생", "음향 집중/분산",
|
262 |
+
"음향 반사/흡수", "음향 도플러 효과", "음파 간섭", "음향 공진",
|
263 |
+
"진동 패턴 변화", "타악 효과", "음향 피드백", "음향 차폐/증폭",
|
264 |
+
"소리 지향성", "음향 왜곡", "비트 생성", "하모닉스 생성", "주파수 변조",
|
265 |
+
"음향 충격파", "음향 필터링"
|
266 |
+
],
|
267 |
+
"소리와 진동 효과": [
|
268 |
+
"소리 발생/소멸",
|
269 |
+
"음 높낮이 변화",
|
270 |
+
"음량 변화",
|
271 |
+
"음색 변화",
|
272 |
+
"공명/반공명",
|
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 |
+
"전기장 생성/소멸",
|
323 |
+
"자기장 생성/소멸",
|
324 |
+
"초전도 상태 전환",
|
325 |
+
"강유전체 특성 변화",
|
326 |
+
"양자 상태 변화",
|
327 |
+
"플라즈마 형성/소멸",
|
328 |
+
"스핀파 전달",
|
329 |
+
"빛에 의한 전기 발생",
|
330 |
+
"압력에 의한 전기 발생",
|
331 |
+
"자기장 내 전류 변화",
|
332 |
+
"전기 저항 변화",
|
333 |
+
"전기 전도성 변화",
|
334 |
+
"정��기 발생/방전",
|
335 |
+
"전자기 유도",
|
336 |
+
"전자기파 방출/흡수",
|
337 |
+
"전기 용량 변화",
|
338 |
+
"자기 이력 현상",
|
339 |
+
"전기적 분극",
|
340 |
+
"전자 흐름 방향 변화",
|
341 |
+
"전기적 공명",
|
342 |
+
"전기적 차폐/노출",
|
343 |
+
"자기 차폐/노출",
|
344 |
+
"자기장 정렬"
|
345 |
+
],
|
346 |
+
"화학적 변화": [
|
347 |
+
"표면 코팅 변화",
|
348 |
+
"물질 성분 변화",
|
349 |
+
"화학 반응 변화",
|
350 |
+
"촉매 작용 시작/중단",
|
351 |
+
"빛에 의한 화학 반응",
|
352 |
+
"전기에 의한 화학 반응",
|
353 |
+
"단분자막 형성",
|
354 |
+
"분자 수준 구조 변화",
|
355 |
+
"생체 모방 표면 변화",
|
356 |
+
"환경 반응형 물질 변화",
|
357 |
+
"주기적 화학 반응",
|
358 |
+
"산화",
|
359 |
+
"환원",
|
360 |
+
"고분자화",
|
361 |
+
"물 분해",
|
362 |
+
"화합",
|
363 |
+
"방사선 영향",
|
364 |
+
"산-염기 반응",
|
365 |
+
"중화 반응",
|
366 |
+
"이온화",
|
367 |
+
"화학적 흡착/탈착",
|
368 |
+
"촉매 효율 변화",
|
369 |
+
"효소 활성 변화",
|
370 |
+
"발색 반응",
|
371 |
+
"pH 변화",
|
372 |
+
"화학적 평형 이동",
|
373 |
+
"결합 형성/분해",
|
374 |
+
"용해도 변화"
|
375 |
+
],
|
376 |
+
"생물학적 변화": [
|
377 |
+
"성장/위축",
|
378 |
+
"세포 분열/사멸",
|
379 |
+
"생물 발광",
|
380 |
+
"신진대사 변화",
|
381 |
+
"면역 반응",
|
382 |
+
"호르몬 분비",
|
383 |
+
"신경 반응",
|
384 |
+
"유전적 발현",
|
385 |
+
"적응/진화",
|
386 |
+
"생체리듬 변화",
|
387 |
+
"재생/치유",
|
388 |
+
"노화/성숙",
|
389 |
+
"생체 모방 변화",
|
390 |
+
"바이오필름 형성",
|
391 |
+
"생물학적 분해",
|
392 |
+
"효소 활성화/비활성화",
|
393 |
+
"생물학적 신호 전달",
|
394 |
+
"스트레스 반응",
|
395 |
+
"체온 조절",
|
396 |
+
"생물학적 시계 변화",
|
397 |
+
"세포외 기질 변화",
|
398 |
+
"생체 역학적 반응",
|
399 |
+
"세포 운동성",
|
400 |
+
"세포 극성 변화",
|
401 |
+
"영양 상태 변화"
|
402 |
+
],
|
403 |
+
"환경 상호작용": [
|
404 |
+
"온도 반응",
|
405 |
+
"습도 반응",
|
406 |
+
"기압 반응",
|
407 |
+
"중력 반응",
|
408 |
+
"자기장 반응",
|
409 |
+
"빛 반응",
|
410 |
+
"소리 반응",
|
411 |
+
"화학 물질 감지",
|
412 |
+
"기계적 자극 감지",
|
413 |
+
"전기 자극 반응",
|
414 |
+
"방사선 반응",
|
415 |
+
"진동 감지",
|
416 |
+
"pH 반응",
|
417 |
+
"용매 반응",
|
418 |
+
"기체 교환",
|
419 |
+
"환경 오염 반응",
|
420 |
+
"날씨 반응",
|
421 |
+
"계절 반응",
|
422 |
+
"일주기 반응",
|
423 |
+
"생태계 상호작용",
|
424 |
+
"공생/경쟁 반응",
|
425 |
+
"포식/피식 관계",
|
426 |
+
"군집 형성",
|
427 |
+
"영역 설정",
|
428 |
+
"이주/정착 패턴"
|
429 |
+
],
|
430 |
+
|
431 |
+
"비즈니스 아이디어: [
|
432 |
+
"시장 재정의/신규 시장 개척",
|
433 |
+
"비즈니스 모델 혁신/디지털 전환",
|
434 |
+
"고객 경험 혁신/서비스 혁신",
|
435 |
+
"협력 및 파트너십 강화/생태계 구축",
|
436 |
+
"글로벌 확장/지역화 전략",
|
437 |
+
"운영 효율성 증대/원가 절감",
|
438 |
+
"브랜드 리포지셔닝/이미지 전환",
|
439 |
+
"지속 가능한 성장/사회적 가치 창출",
|
440 |
+
"데이터 기반 의사결정/AI 도입",
|
441 |
+
"신기술 융합/혁신 투자"
|
442 |
+
]
|
443 |
+
|
444 |
+
}
|
445 |
+
|
446 |
+
# English version
|
447 |
+
physical_transformation_categories_en = {
|
448 |
+
"Sensor Functions": [
|
449 |
+
"Visual sensor/detection", "Auditory sensor/detection", "Tactile sensor/detection", "Taste sensor/detection", "Olfactory sensor/detection",
|
450 |
+
"Temperature sensor/detection", "Humidity sensor/detection", "Pressure sensor/detection", "Acceleration sensor/detection", "Rotational sensor/detection",
|
451 |
+
"Proximity sensor/detection", "Position sensor/detection", "Motion sensor/detection", "Gas sensor/detection", "Infrared sensor/detection",
|
452 |
+
"Ultraviolet sensor/detection", "Radiation sensor/detection", "Magnetic sensor/detection", "Electric field sensor/detection", "Chemical sensor/detection",
|
453 |
+
"Biosignal sensor/detection", "Vibration sensor/detection", "Noise sensor/detection", "Light intensity sensor/detection", "Light wavelength sensor/detection",
|
454 |
+
"Tilt sensor/detection", "pH sensor/detection", "Current sensor/detection", "Voltage sensor/detection", "Image sensor/detection",
|
455 |
+
"Distance sensor/detection", "Depth sensor/detection", "Gravity sensor/detection", "Speed sensor/detection", "Flow sensor/detection",
|
456 |
+
"Water level sensor/detection", "Turbidity sensor/detection", "Salinity sensor/detection", "Metal detection", "Piezoelectric sensor/detection",
|
457 |
+
"Photovoltaic sensor/detection", "Thermocouple sensor/detection", "Hall effect sensor/detection", "Ultrasonic sensor/detection", "Radar sensor/detection",
|
458 |
+
"Lidar sensor/detection", "Touch sensor/detection", "Gesture sensor/detection", "Heart rate sensor/detection", "Blood pressure sensor/detection"
|
459 |
+
],
|
460 |
+
"Size and Shape Change": [
|
461 |
+
"Volume increase/decrease", "Length increase/decrease", "Width increase/decrease", "Height increase/decrease",
|
462 |
+
"Density change", "Weight increase/decrease", "Shape deformation", "State change", "Uneven deformation",
|
463 |
+
"Complex shape deformation", "Twisting/entwining", "Non-uniform expansion/contraction", "Rounded/sharpened edges",
|
464 |
+
"Cracking/splitting", "Fragmentation", "Water resistance", "Dust resistance", "Denting/recovery",
|
465 |
+
"Folding/unfolding", "Compression/expansion", "Stretching/contraction", "Wrinkling/flattening", "Crushing/hardening",
|
466 |
+
"Rolling/unrolling", "Bending/curving"
|
467 |
+
],
|
468 |
+
"Surface and Appearance Change": [
|
469 |
+
"Color change", "Texture change", "Transparency change", "Glossy/matte change",
|
470 |
+
"Light reflection variation", "Pattern change", "Angle-dependent color change", "Light-induced color change",
|
471 |
+
"Temperature-dependent color change", "Holographic effect", "Angle-specific light reflection", "Surface shape alteration",
|
472 |
+
"Nano-scale surface structure change", "Self-cleaning effect", "Stain/pattern formation", "Blurriness/clarity change",
|
473 |
+
"Luster/shine change", "Hue/saturation change", "Luminescence/fluorescence", "Light scattering effect",
|
474 |
+
"Light absorption change", "Translucency effect", "Shadow effect change", "UV response change",
|
475 |
+
"Glow effect"
|
476 |
+
],
|
477 |
+
"Material State Change": [
|
478 |
+
"Solid/liquid/gas transition", "Crystallization/dissolution", "Oxidation/corrosion", "Hardening/softening",
|
479 |
+
"Special state transition", "Amorphous/crystalline transition", "Component separation", "Particle formation/disintegration",
|
480 |
+
"Gel formation/dissolution", "Metastable state change", "Molecular self-assembly/disintegration", "Delayed state change",
|
481 |
+
"Melting", "Solidification", "Evaporation/condensation", "Sublimation/deposition", "Precipitation/suspension", "Dispersion/aggregation",
|
482 |
+
"Drying/moistening", "Swelling/shrinkage", "Freezing/thawing", "Weathering/erosion", "Charging/discharging",
|
483 |
+
"Bonding/separation", "Fermentation/decay"
|
484 |
+
],
|
485 |
+
"Movement Characteristics Change": [
|
486 |
+
"Acceleration/deceleration", "Maintaining constant speed", "Vibration/vibration reduction", "Collision/bouncing",
|
487 |
+
"Increase/decrease in rotational speed", "Change in rotational direction", "Irregular movement", "Stop-and-slide phenomenon",
|
488 |
+
"Resonance/anti-resonance", "Resistance/lift change in fluid", "Change in movement resistance", "Complex vibrational movement",
|
489 |
+
"Movement in special fluid", "Rotational-translational movement", "Inertial stoppage", "Shock absorption",
|
490 |
+
"Shock transfer", "Conservation of momentum", "Friction change", "Overcoming inertia", "Unstable equilibrium",
|
491 |
+
"Dynamic stability", "Damping of oscillation", "Path predictability", "Evasive movement"
|
492 |
+
],
|
493 |
+
"Structural Change": [
|
494 |
+
"Addition/removal of components", "Assembly/disassembly", "Folding/unfolding", "Deformation/recovery", "Optimal structural change",
|
495 |
+
"Self-rearrangement", "Natural pattern formation/disappearance", "Regular pattern change", "Modular transformation",
|
496 |
+
"Increased structural complexity", "Memory of original shape effect", "Shape change over time", "Partial removal",
|
497 |
+
"Partial replacement", "Bonding", "Separation", "Division/integration", "Overlaying", "Internal structure change",
|
498 |
+
"External structure change", "Shift of center axis", "Balance point change", "Hierarchical structure change", "Support structure change",
|
499 |
+
"Stress distribution structure", "Shock absorption structure", "Grid/matrix structure change", "Interconnectivity change"
|
500 |
+
],
|
501 |
+
"Spatial Movement": [
|
502 |
+
"Forward/backward movement", "Left/right movement", "Up/down movement", "Vertical axis rotation (nodding)",
|
503 |
+
"Horizontal axis rotation (shaking head)", "Longitudinal axis rotation (tilting sideways)", "Circular motion", "Spiral movement",
|
504 |
+
"Slipping due to inertia", "Change of rotation axis", "Irregular rotation", "Shaking movement", "Parabolic motion",
|
505 |
+
"Zero-gravity floating", "Floating on water surface", "Jump/leap", "Sliding", "Rolling", "Free fall",
|
506 |
+
"Reciprocating motion", "Elastic bouncing", "Penetration", "Evasive movement", "Zigzag movement", "Swinging movement"
|
507 |
+
],
|
508 |
+
"Time-Related Change": [
|
509 |
+
"Aging/weathering", "Wear/corrosion", "Fading/discoloration", "Damage/recovery", "Lifecycle change",
|
510 |
+
"Adaptation through user interaction", "Learning-based shape optimization", "Property change over time",
|
511 |
+
"Collective memory effect", "Cultural significance change", "Delayed response", "History-dependent change",
|
512 |
+
"Gradual time change", "Evolutionary change", "Periodic regeneration", "Seasonal adaptation",
|
513 |
+
"Circadian rhythm change", "Lifecycle stage", "Growth/decline", "Self-repair/regeneration",
|
514 |
+
"Natural cycle adaptation", "Persistence/transience", "Memory effect", "Delayed effect", "Cumulative effect"
|
515 |
+
],
|
516 |
+
"Light and Visual Effects": [
|
517 |
+
"Illumination/shutdown", "Light transmission/blocking", "Light scattering/concentration", "Color spectrum change", "Light diffraction",
|
518 |
+
"Light interference", "Hologram creation", "Laser effect", "Light polarization", "Fluorescence/phosphorescence",
|
519 |
+
"UV/IR emission", "Optical illusion", "Light refraction", "Shadow creation/removal",
|
520 |
+
"Chromatic aberration", "Rainbow effect", "Glow effect", "Flash effect", "Lighting pattern",
|
521 |
+
"Beam effect", "Light filter effect", "Change in light direction", "Projection effect", "Light detection/response",
|
522 |
+
"Luminance change"
|
523 |
+
],
|
524 |
+
"Sound and Vibration Effects": [
|
525 |
"Sound generation/cessation", "Pitch change", "Volume change", "Timbre change",
|
526 |
"Resonance/antiresonance", "Acoustic vibration", "Ultrasonic/infrasonic emission", "Sound concentration/distribution",
|
527 |
"Sound reflection/absorption", "Acoustic Doppler effect", "Sound wave interference", "Acoustic resonance",
|
|
|
567 |
"Radiation response", "Vibration detection", "pH response", "Solvent response", "Gas exchange",
|
568 |
"Pollution response", "Weather response", "Seasonal response", "Circadian response", "Ecosystem interaction",
|
569 |
"Symbiotic/competitive interaction", "Predator/prey relationship", "Swarm formation", "Territorial behavior", "Migration/settlement pattern"
|
570 |
+
],
|
571 |
+
"Business Ideas": [
|
572 |
+
"Market redefinition / New market creation",
|
573 |
+
"Business model innovation / Digital transformation",
|
574 |
+
"Customer experience innovation / Service innovation",
|
575 |
+
"Strengthened collaboration and partnerships / Ecosystem building",
|
576 |
+
"Global expansion / Localization strategy",
|
577 |
+
"Increased operational efficiency / Cost reduction",
|
578 |
+
"Brand repositioning / Image transformation",
|
579 |
+
"Sustainable growth / Social value creation",
|
580 |
+
"Data-driven decision making / AI adoption",
|
581 |
+
"Convergence of new technologies / Innovative investments"
|
582 |
]
|
583 |
+
|
584 |
}
|
585 |
|
586 |
##############################################################################
|
|
|
723 |
text1 = text1.strip() if text1 else None
|
724 |
text2 = text2.strip() if text2 else None
|
725 |
text3 = text3.strip() if text3 else None
|
726 |
+
|
727 |
if not text1:
|
728 |
return "오류: 최소 하나의 키워드를 입력해주세요." if lang=="ko" else "Error: Please enter at least one keyword."
|
729 |
+
|
730 |
if lang == "ko":
|
731 |
progress(0.05, desc="아이디어 생성 준비 중...")
|
732 |
time.sleep(0.3)
|
|
|
735 |
progress(0.05, desc="Preparing idea generation...")
|
736 |
time.sleep(0.3)
|
737 |
progress(0.1, desc="Generating creative idea...")
|
738 |
+
|
739 |
results = generate_transformations_lang(text1, text2, text3, selected_category, categories_dict, lang)
|
740 |
+
|
741 |
if lang == "ko":
|
742 |
progress(0.8, desc="결과 포맷팅 중...")
|
743 |
formatted = format_results_lang(results, lang)
|
|
|
768 |
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."
|
769 |
return ""
|
770 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
771 |
|
772 |
##############################################################################
|
773 |
# Gradio UI with Two Tabs: English (Main Home) and Korean
|
|
|
776 |
title="Idea Transformer",
|
777 |
theme=gr.themes.Soft(primary_hue="teal", secondary_hue="slate", neutral_hue="neutral")
|
778 |
) as demo:
|
779 |
+
|
780 |
gr.HTML("""
|
781 |
<style>
|
782 |
body {
|
|
|
819 |
with gr.Tab(label="English"):
|
820 |
gr.Markdown("# 🚀 Idea Transformer")
|
821 |
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. https://discord.gg/openfreeai")
|
822 |
+
|
823 |
warning_en = gr.Markdown(get_warning_message_lang("en"))
|
824 |
+
|
825 |
with gr.Row():
|
826 |
with gr.Column(scale=1):
|
827 |
text_input1_en = gr.Textbox(label="Keyword 1 (required)", placeholder="e.g., Smartphone")
|
|
|
834 |
info="Select a category."
|
835 |
)
|
836 |
status_msg_en = gr.Markdown("💡 Click the 'Generate Idea' button to create an idea and design image based on the selected category.")
|
837 |
+
|
838 |
processing_indicator_en = gr.HTML("""
|
839 |
<div style="display: flex; justify-content: center; align-items: center; margin: 10px 0;">
|
840 |
<div style="border: 5px solid #f3f3f3; border-top: 5px solid #3498db; border-radius: 50%; width: 30px; height: 30px; animation: spin 2s linear infinite;"></div>
|
|
|
847 |
}
|
848 |
</style>
|
849 |
""", visible=False)
|
850 |
+
|
851 |
submit_button_en = gr.Button("Generate Idea", variant="primary")
|
852 |
+
|
853 |
with gr.Column(scale=2):
|
854 |
idea_output_en = gr.Markdown(label="Idea Output")
|
855 |
generated_image_en = gr.Image(label="Generated Design Image", type="pil")
|
856 |
+
|
857 |
gr.Examples(
|
858 |
examples=[
|
859 |
["Smartphone", "", "", "Sensor Functions"],
|
|
|
863 |
["Sneakers", "Wearable", "Health", "Structural Change"],
|
864 |
],
|
865 |
inputs=[text_input1_en, text_input2_en, text_input3_en, category_radio_en],
|
|
|
|
|
|
|
866 |
)
|
867 |
+
|
868 |
def show_processing_indicator_en():
|
869 |
return gr.update(visible=True)
|
870 |
+
|
871 |
def hide_processing_indicator_en():
|
872 |
return gr.update(visible=False)
|
873 |
+
|
874 |
submit_button_en.click(
|
875 |
fn=show_processing_indicator_en,
|
876 |
inputs=None,
|
|
|
884 |
inputs=None,
|
885 |
outputs=processing_indicator_en
|
886 |
)
|
887 |
+
|
888 |
with gr.Tab(label="한국어"):
|
889 |
gr.Markdown("# 🚀 아이디어 트랜스포머")
|
890 |
gr.Markdown("입력한 **키워드**(최대 3개)와 **카테고리**를 바탕으로, 창의적인 모델/컨셉/형상 변화 아이디어를 생성하고, 해당 확장 아이디어를 프롬프트로 하여 디자인 이미지를 생성합니다. https://discord.gg/openfreeai")
|
891 |
+
|
892 |
warning_ko = gr.Markdown(get_warning_message_lang("ko"))
|
893 |
+
|
894 |
with gr.Row():
|
895 |
with gr.Column(scale=1):
|
896 |
text_input1_ko = gr.Textbox(label="키워드 1 (필수)", placeholder="예: 스마트폰")
|
|
|
903 |
info="출력할 카테고리를 선택하세요."
|
904 |
)
|
905 |
status_msg_ko = gr.Markdown("💡 '아이디어 생성하기' 버튼을 클릭하면 선택한 카테고리에 해당하는 아이디어와 디자인 이미지가 생성됩니다.")
|
906 |
+
|
907 |
processing_indicator_ko = gr.HTML("""
|
908 |
<div style="display: flex; justify-content: center; align-items: center; margin: 10px 0;">
|
909 |
<div style="border: 5px solid #f3f3f3; border-top: 5px solid #3498db; border-radius: 50%; width: 30px; height: 30px; animation: spin 2s linear infinite;"></div>
|
|
|
916 |
}
|
917 |
</style>
|
918 |
""", visible=False)
|
919 |
+
|
920 |
submit_button_ko = gr.Button("아이디어 생성하기", variant="primary")
|
921 |
+
|
922 |
with gr.Column(scale=2):
|
923 |
idea_output_ko = gr.Markdown(label="아이디어 결과")
|
924 |
generated_image_ko = gr.Image(label="생성된 디자인 이미지", type="pil")
|
925 |
+
|
926 |
gr.Examples(
|
927 |
examples=[
|
928 |
["스마트폰", "", "", "센서 기능"],
|
|
|
931 |
["드론", "인공지능", "", "물질의 상태 변화"],
|
932 |
["운동화", "웨어러블", "건강", "구조적 변화"],
|
933 |
],
|
934 |
+
inputs=[text_input1_ko, text_input2_ko, text_input3_ko, category_radio_ko],
|
935 |
)
|
936 |
+
|
937 |
def show_processing_indicator_ko():
|
938 |
return gr.update(visible=True)
|
939 |
+
|
940 |
def hide_processing_indicator_ko():
|
941 |
return gr.update(visible=False)
|
942 |
+
|
943 |
submit_button_ko.click(
|
944 |
fn=show_processing_indicator_ko,
|
945 |
inputs=None,
|
|
|
955 |
)
|
956 |
|
957 |
if __name__ == "__main__":
|
958 |
+
demo.launch(debug=True)
|