Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,13 +15,13 @@ BRAVE_API_KEY = os.getenv('BRAVE_API_KEY', '') # Add Brave API key
|
|
| 15 |
|
| 16 |
def search_design_trends(product_type):
|
| 17 |
"""
|
| 18 |
-
|
| 19 |
"""
|
| 20 |
if not BRAVE_API_KEY:
|
| 21 |
-
return "
|
| 22 |
|
| 23 |
try:
|
| 24 |
-
#
|
| 25 |
query = f"{product_type} design trends 2024 2025 materials technology innovation"
|
| 26 |
|
| 27 |
url = "https://api.search.brave.com/res/v1/web/search"
|
|
@@ -47,84 +47,88 @@ def search_design_trends(product_type):
|
|
| 47 |
if results:
|
| 48 |
return "\n".join(results)
|
| 49 |
else:
|
| 50 |
-
return "
|
| 51 |
else:
|
| 52 |
-
return "
|
| 53 |
|
| 54 |
except Exception as e:
|
| 55 |
-
print(f"Brave
|
| 56 |
-
return "
|
| 57 |
|
| 58 |
def enhance_prompt_with_team(user_input):
|
| 59 |
"""
|
| 60 |
-
|
| 61 |
"""
|
| 62 |
if not FIREWORKS_API_KEY:
|
| 63 |
-
#
|
| 64 |
-
return create_basic_design_prompt(user_input)
|
| 65 |
|
| 66 |
try:
|
| 67 |
-
#
|
| 68 |
search_results = search_design_trends(user_input)
|
| 69 |
|
| 70 |
url = "https://api.fireworks.ai/inference/v1/chat/completions"
|
| 71 |
|
| 72 |
-
#
|
| 73 |
-
system_prompt = """
|
| 74 |
|
| 75 |
-
##
|
| 76 |
|
| 77 |
-
### 1.
|
| 78 |
-
-
|
| 79 |
-
-
|
| 80 |
-
-
|
| 81 |
|
| 82 |
-
### 2.
|
| 83 |
-
-
|
| 84 |
-
-
|
| 85 |
-
-
|
| 86 |
-
-
|
| 87 |
|
| 88 |
-
### 3.
|
| 89 |
-
-
|
| 90 |
-
-
|
| 91 |
-
-
|
| 92 |
-
-
|
| 93 |
|
| 94 |
-
##
|
| 95 |
|
| 96 |
-
|
| 97 |
-
[
|
| 98 |
|
| 99 |
-
|
| 100 |
-
[
|
| 101 |
|
| 102 |
-
|
| 103 |
-
[
|
| 104 |
-
-
|
| 105 |
-
-
|
| 106 |
-
-
|
| 107 |
-
-
|
| 108 |
-
|
| 109 |
|
| 110 |
-
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
-
#
|
| 113 |
-
user_prompt = f"""
|
| 114 |
|
| 115 |
-
|
| 116 |
{search_results}
|
| 117 |
|
| 118 |
-
|
| 119 |
-
1.
|
| 120 |
-
2.
|
| 121 |
-
3.
|
|
|
|
| 122 |
|
| 123 |
-
|
| 124 |
|
| 125 |
payload = {
|
| 126 |
"model": "accounts/fireworks/models/qwen3-235b-a22b-instruct-2507", # Original model maintained
|
| 127 |
-
"max_tokens":
|
| 128 |
"top_p": 0.9,
|
| 129 |
"temperature": 0.7,
|
| 130 |
"messages": [
|
|
@@ -151,51 +155,52 @@ Focus on creating a manufacturable, innovative product design with clear text ov
|
|
| 151 |
result = response.json()
|
| 152 |
enhanced = result.get('choices', [{}])[0].get('message', {}).get('content', '')
|
| 153 |
if enhanced:
|
| 154 |
-
#
|
| 155 |
-
if "DESIGNER'S FINAL PROMPT:" in enhanced:
|
| 156 |
-
parts = enhanced.split("DESIGNER'S FINAL PROMPT:")
|
| 157 |
if len(parts) > 1:
|
| 158 |
-
#
|
| 159 |
-
|
|
|
|
| 160 |
return enhanced, enhanced
|
| 161 |
|
| 162 |
-
#
|
| 163 |
-
return create_basic_design_prompt(user_input), "
|
| 164 |
|
| 165 |
except requests.exceptions.Timeout:
|
| 166 |
-
print("Fireworks API
|
| 167 |
-
return create_basic_design_prompt(user_input), "API
|
| 168 |
except Exception as e:
|
| 169 |
-
print(f"
|
| 170 |
-
return create_basic_design_prompt(user_input), f"
|
| 171 |
|
| 172 |
def create_basic_design_prompt(user_input):
|
| 173 |
"""
|
| 174 |
-
|
| 175 |
"""
|
| 176 |
product_name = user_input.upper().replace(" ", "-")
|
| 177 |
-
return f"""
|
| 178 |
-
-
|
| 179 |
-
-
|
| 180 |
-
* "
|
| 181 |
-
* "
|
| 182 |
-
* "
|
| 183 |
-
* "
|
| 184 |
-
-
|
| 185 |
-
*
|
| 186 |
-
-
|
| 187 |
-
-
|
| 188 |
-
-
|
| 189 |
-
-
|
| 190 |
-
-
|
| 191 |
-
-
|
| 192 |
|
| 193 |
def upload_image_to_hosting(image):
|
| 194 |
"""
|
| 195 |
-
|
| 196 |
"""
|
| 197 |
try:
|
| 198 |
-
#
|
| 199 |
buffered = BytesIO()
|
| 200 |
image.save(buffered, format="PNG")
|
| 201 |
buffered.seek(0)
|
|
@@ -217,7 +222,7 @@ def upload_image_to_hosting(image):
|
|
| 217 |
except:
|
| 218 |
pass
|
| 219 |
|
| 220 |
-
#
|
| 221 |
buffered = BytesIO()
|
| 222 |
image.save(buffered, format="PNG")
|
| 223 |
buffered.seek(0)
|
|
@@ -226,34 +231,34 @@ def upload_image_to_hosting(image):
|
|
| 226 |
|
| 227 |
def process_product_design(prompt, enhance_prompt_flag, image1, image2=None):
|
| 228 |
"""
|
| 229 |
-
|
| 230 |
"""
|
| 231 |
if not os.getenv('REPLICATE_API_TOKEN'):
|
| 232 |
-
return None, prompt, "โ ๏ธ
|
| 233 |
|
| 234 |
try:
|
| 235 |
team_discussion = ""
|
| 236 |
final_prompt = prompt
|
| 237 |
|
| 238 |
-
#
|
| 239 |
if enhance_prompt_flag:
|
| 240 |
result = enhance_prompt_with_team(prompt)
|
| 241 |
if isinstance(result, tuple):
|
| 242 |
final_prompt, team_discussion = result
|
| 243 |
else:
|
| 244 |
final_prompt = result
|
| 245 |
-
team_discussion = "
|
| 246 |
|
| 247 |
-
#
|
| 248 |
-
if "DIRECTOR'S VISION:" in team_discussion:
|
| 249 |
-
team_discussion = f"### ๐ฌ
|
| 250 |
|
| 251 |
-
#
|
| 252 |
model_input = {
|
| 253 |
"prompt": final_prompt
|
| 254 |
}
|
| 255 |
|
| 256 |
-
#
|
| 257 |
if image1 or image2:
|
| 258 |
image_urls = []
|
| 259 |
|
|
@@ -266,13 +271,13 @@ def process_product_design(prompt, enhance_prompt_flag, image1, image2=None):
|
|
| 266 |
image_urls.append(url2)
|
| 267 |
|
| 268 |
model_input["image_input"] = image_urls
|
| 269 |
-
status_msg = "โ
|
| 270 |
else:
|
| 271 |
-
status_msg = "โ
|
| 272 |
|
| 273 |
-
#
|
| 274 |
try:
|
| 275 |
-
#
|
| 276 |
annotated_prompt = f"{final_prompt}. Include clear text labels, feature callouts with arrows, product name/model as title, technical specifications overlay, component annotations in clean modern typography"
|
| 277 |
|
| 278 |
output = replicate.run(
|
|
@@ -286,7 +291,7 @@ def process_product_design(prompt, enhance_prompt_flag, image1, image2=None):
|
|
| 286 |
}
|
| 287 |
)
|
| 288 |
except:
|
| 289 |
-
#
|
| 290 |
annotated_prompt = f"{final_prompt}. With text overlays showing product name, key features with arrow callouts, specifications, and component labels in professional typography"
|
| 291 |
|
| 292 |
output = replicate.run(
|
|
@@ -301,9 +306,9 @@ def process_product_design(prompt, enhance_prompt_flag, image1, image2=None):
|
|
| 301 |
)
|
| 302 |
|
| 303 |
if output is None:
|
| 304 |
-
return None, final_prompt, "โ
|
| 305 |
|
| 306 |
-
#
|
| 307 |
output_url = None
|
| 308 |
if isinstance(output, str):
|
| 309 |
output_url = output
|
|
@@ -318,17 +323,17 @@ def process_product_design(prompt, enhance_prompt_flag, image1, image2=None):
|
|
| 318 |
img = Image.open(BytesIO(response.content))
|
| 319 |
return img, final_prompt, status_msg, team_discussion
|
| 320 |
|
| 321 |
-
return None, final_prompt, "โ
|
| 322 |
|
| 323 |
except Exception as e:
|
| 324 |
error_msg = str(e)
|
| 325 |
-
return None, prompt, f"โ
|
| 326 |
|
| 327 |
-
#
|
| 328 |
css = """
|
| 329 |
.gradio-container {
|
| 330 |
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
|
| 331 |
-
font-family: '
|
| 332 |
min-height: 100vh;
|
| 333 |
}
|
| 334 |
.header-container {
|
|
@@ -365,7 +370,7 @@ css = """
|
|
| 365 |
text-align: center;
|
| 366 |
font-weight: 500;
|
| 367 |
color: #ffd700;
|
| 368 |
-
max-width:
|
| 369 |
font-size: 0.9rem;
|
| 370 |
}
|
| 371 |
.main-content {
|
|
@@ -409,11 +414,12 @@ css = """
|
|
| 409 |
padding: 1.2rem;
|
| 410 |
margin-top: 1rem;
|
| 411 |
border: 1px solid #dee2e6;
|
| 412 |
-
font-family: '
|
| 413 |
font-size: 0.85rem;
|
| 414 |
-
max-height:
|
| 415 |
overflow-y: auto;
|
| 416 |
white-space: pre-wrap;
|
|
|
|
| 417 |
}
|
| 418 |
.enhanced-prompt-box {
|
| 419 |
background: #f0f0f0;
|
|
@@ -444,83 +450,83 @@ footer {
|
|
| 444 |
}
|
| 445 |
"""
|
| 446 |
|
| 447 |
-
#
|
| 448 |
with gr.Blocks(css=css, theme=gr.themes.Base()) as demo:
|
| 449 |
with gr.Column(elem_classes="header-container"):
|
| 450 |
gr.HTML("""
|
| 451 |
-
<h1 class="logo-text">๐ญ
|
| 452 |
-
<p class="subtitle">AI-
|
| 453 |
<div class="mode-indicator">
|
| 454 |
-
๐ฅ
|
| 455 |
</div>
|
| 456 |
""")
|
| 457 |
|
| 458 |
with gr.Column(elem_classes="main-content"):
|
| 459 |
gr.HTML("""
|
| 460 |
<div class="info-box">
|
| 461 |
-
<strong>๐ฏ
|
| 462 |
-
โข <b
|
| 463 |
-
โข <b
|
| 464 |
-
โข <b
|
| 465 |
-
โข <b
|
| 466 |
-
โข <b
|
| 467 |
</div>
|
| 468 |
""")
|
| 469 |
|
| 470 |
with gr.Row(equal_height=True):
|
| 471 |
with gr.Column(scale=1):
|
| 472 |
prompt = gr.Textbox(
|
| 473 |
-
label="๐
|
| 474 |
-
placeholder="
|
| 475 |
lines=2,
|
| 476 |
-
value="
|
| 477 |
elem_classes="prompt-input"
|
| 478 |
)
|
| 479 |
|
| 480 |
enhance_prompt_checkbox = gr.Checkbox(
|
| 481 |
-
label="๐
|
| 482 |
value=True,
|
| 483 |
-
info="
|
| 484 |
)
|
| 485 |
|
| 486 |
with gr.Row():
|
| 487 |
image1 = gr.Image(
|
| 488 |
-
label="
|
| 489 |
type="pil",
|
| 490 |
height=180
|
| 491 |
)
|
| 492 |
image2 = gr.Image(
|
| 493 |
-
label="
|
| 494 |
type="pil",
|
| 495 |
height=180
|
| 496 |
)
|
| 497 |
|
| 498 |
generate_btn = gr.Button(
|
| 499 |
-
"๐จ
|
| 500 |
variant="primary",
|
| 501 |
size="lg"
|
| 502 |
)
|
| 503 |
|
| 504 |
with gr.Column(scale=1):
|
| 505 |
output_image = gr.Image(
|
| 506 |
-
label="
|
| 507 |
type="pil",
|
| 508 |
height=400,
|
| 509 |
elem_classes="image-container"
|
| 510 |
)
|
| 511 |
|
| 512 |
enhanced_prompt_display = gr.Textbox(
|
| 513 |
-
label="๐
|
| 514 |
interactive=False,
|
| 515 |
lines=3,
|
| 516 |
elem_classes="enhanced-prompt-box"
|
| 517 |
)
|
| 518 |
|
| 519 |
status = gr.Textbox(
|
| 520 |
-
label="
|
| 521 |
interactive=False,
|
| 522 |
elem_classes="status-text",
|
| 523 |
-
value="
|
| 524 |
)
|
| 525 |
|
| 526 |
with gr.Row():
|
|
@@ -529,42 +535,46 @@ with gr.Blocks(css=css, theme=gr.themes.Base()) as demo:
|
|
| 529 |
elem_classes="team-discussion"
|
| 530 |
)
|
| 531 |
|
| 532 |
-
#
|
| 533 |
generate_btn.click(
|
| 534 |
fn=process_product_design,
|
| 535 |
inputs=[prompt, enhance_prompt_checkbox, image1, image2],
|
| 536 |
outputs=[output_image, enhanced_prompt_display, status, team_discussion_display]
|
| 537 |
)
|
| 538 |
|
| 539 |
-
#
|
| 540 |
gr.Examples(
|
| 541 |
examples=[
|
| 542 |
-
["
|
| 543 |
-
["
|
| 544 |
-
["
|
| 545 |
-
["
|
| 546 |
-
["
|
| 547 |
-
["
|
| 548 |
-
["
|
| 549 |
-
["
|
|
|
|
|
|
|
|
|
|
|
|
|
| 550 |
],
|
| 551 |
inputs=[prompt, enhance_prompt_checkbox, image1, image2],
|
| 552 |
-
label="๐ก
|
| 553 |
)
|
| 554 |
|
| 555 |
-
#
|
| 556 |
if __name__ == "__main__":
|
| 557 |
-
#
|
| 558 |
if not os.getenv('REPLICATE_API_TOKEN'):
|
| 559 |
-
print("โ ๏ธ
|
| 560 |
if not os.getenv('FIREWORKS_API_KEY'):
|
| 561 |
-
print("โ ๏ธ
|
| 562 |
if not os.getenv('BRAVE_API_KEY'):
|
| 563 |
-
print("โ ๏ธ
|
| 564 |
|
| 565 |
demo.launch(
|
| 566 |
-
share=False, #
|
| 567 |
server_name="0.0.0.0",
|
| 568 |
server_port=7860,
|
| 569 |
-
ssr_mode=False #
|
| 570 |
)
|
|
|
|
| 15 |
|
| 16 |
def search_design_trends(product_type):
|
| 17 |
"""
|
| 18 |
+
Brave Search API๋ฅผ ์ฌ์ฉํ์ฌ ์ต์ ๋์์ธ ํธ๋ ๋์ ๊ธฐ์ ๊ฒ์
|
| 19 |
"""
|
| 20 |
if not BRAVE_API_KEY:
|
| 21 |
+
return "๊ฒ์ ๊ฒฐ๊ณผ ์์ (API ํค ๋ฏธ์ค์ )"
|
| 22 |
|
| 23 |
try:
|
| 24 |
+
# ์ ํ ๋์์ธ์ ์ํ ๊ฒ์ ์ฟผ๋ฆฌ ๊ตฌ์ฑ
|
| 25 |
query = f"{product_type} design trends 2024 2025 materials technology innovation"
|
| 26 |
|
| 27 |
url = "https://api.search.brave.com/res/v1/web/search"
|
|
|
|
| 47 |
if results:
|
| 48 |
return "\n".join(results)
|
| 49 |
else:
|
| 50 |
+
return "์ ํ๋ ๊ฒ์ ๊ฒฐ๊ณผ"
|
| 51 |
else:
|
| 52 |
+
return "ํ์ฌ ๊ฒ์ ๋ถ๊ฐ"
|
| 53 |
|
| 54 |
except Exception as e:
|
| 55 |
+
print(f"Brave ๊ฒ์ ์ค๋ฅ: {str(e)}")
|
| 56 |
+
return "๊ฒ์ ๊ฒฐ๊ณผ ์ด์ฉ ๋ถ๊ฐ"
|
| 57 |
|
| 58 |
def enhance_prompt_with_team(user_input):
|
| 59 |
"""
|
| 60 |
+
์ค์ ์น ๊ฒ์์ ํตํ ํ ํ์
๋ฐฉ์์ ํฅ์๋ ํ๋กฌํํธ ์์ฑ
|
| 61 |
"""
|
| 62 |
if not FIREWORKS_API_KEY:
|
| 63 |
+
# ๊ธฐ๋ณธ ํฅ์์ผ๋ก ํด๋ฐฑ
|
| 64 |
+
return create_basic_design_prompt(user_input), "API ํค๊ฐ ์ค์ ๋์ง ์์"
|
| 65 |
|
| 66 |
try:
|
| 67 |
+
# ๋จผ์ ์์ง๋์ด๋ฅผ ์ํ ์ค์ ๊ฒ์ ๊ฒฐ๊ณผ ํ๋
|
| 68 |
search_results = search_design_trends(user_input)
|
| 69 |
|
| 70 |
url = "https://api.fireworks.ai/inference/v1/chat/completions"
|
| 71 |
|
| 72 |
+
# ๊ฒ์ ํตํฉ๋ ํฅ์๋ ์์คํ
ํ๋กฌํํธ
|
| 73 |
+
system_prompt = """๋น์ ์ ์ธ ๊ฐ์ง ์ ๋ฌธ ์ญํ ๋ก ๊ตฌ์ฑ๋ ์ ํ ๋์์ธ ํ์
๋๋ค. ๋ชจ๋ ์๋ต์ ํ๊ตญ์ด๋ก ์์ฑํ์ธ์:
|
| 74 |
|
| 75 |
+
## ํ ์ญํ :
|
| 76 |
|
| 77 |
+
### 1. ๊ฐ๋
(ํฌ๋ฆฌ์์ดํฐ๋ธ ๋น์ ๋ฆฌ๋)
|
| 78 |
+
- ์ฌ์ฉ์ ์๊ตฌ์ฌํญ๊ณผ ์์ฅ ํฌ์ง์
๋ ๋ถ์
|
| 79 |
+
- ๋์์ธ ์ฒ ํ๊ณผ ์ ์ฝ ์กฐ๊ฑด ์ค์
|
| 80 |
+
- ๊ธฐ๋ฅ์ ๋ํ ์ต์ข
๊ฒฐ์
|
| 81 |
|
| 82 |
+
### 2. ์์ง๋์ด (์ฐ๊ตฌ ๋ฐ์ดํฐ๋ฅผ ํ์ฉํ ๊ธฐ์ ์ ๋ฌธ๊ฐ)
|
| 83 |
+
- ์ ๊ณต๋ ๊ฒ์ ๊ฒฐ๊ณผ๋ฅผ ํ์ฉํ ์์ฌ๊ฒฐ์
|
| 84 |
+
- ์ ์กฐ ๊ฐ๋ฅ์ฑ ํ๊ฐ
|
| 85 |
+
- ์ฌ๋ฃ์ ๊ธฐ์ ์ถ์ฒ
|
| 86 |
+
- ํธ๋ ๋ ๊ธฐ๋ฐ ํ์ ๊ธฐ๋ฅ ์ ์
|
| 87 |
|
| 88 |
+
### 3. ๋์์ด๋ (๋น์ฃผ์ผ ์ ๋ฌธ๊ฐ)
|
| 89 |
+
- ์์ธํ ์๊ฐ์ ์ฌ์ ์์ฑ
|
| 90 |
+
- ์ ํํ ์ฌ๋ฃ, ๋ง๊ฐ, ์์ ์ง์
|
| 91 |
+
- ๋ ๋๋ง ์คํ์ผ๊ณผ ๋ถ์๊ธฐ ์ ์
|
| 92 |
+
- ํ
์คํธ ๋ ์ด๋ธ๊ณผ ์ฃผ์ ํฌํจ ํ์
|
| 93 |
|
| 94 |
+
## ์ถ๋ ฅ ํ์:
|
| 95 |
|
| 96 |
+
**๊ฐ๋
์ ๋น์ :**
|
| 97 |
+
[๊ฐ๋ตํ ๋น์ ์ค๋ช
- 2-3๋ฌธ์ฅ]
|
| 98 |
|
| 99 |
+
**์์ง๋์ด์ ๊ธฐ์ ํ๊ฐ:**
|
| 100 |
+
[๊ฒ์ ๋ฐ์ดํฐ ๊ธฐ๋ฐ 3-4๊ฐ ๊ธฐ์ ๊ถ์ฅ์ฌํญ]
|
| 101 |
|
| 102 |
+
**๋์์ด๋์ ์ต์ข
ํ๋กฌํํธ:**
|
| 103 |
+
[ํ
์คํธ ๋ ์ด๋ธ๊ณผ ์ฃผ์์ ํฌํจํ ์์ธํ ์๊ฐ์ ์ค๋ช
. ๋ฐ๋์ ํฌํจ:
|
| 104 |
+
- ์ ํ๋ช
/๋ชจ๋ธ์ ํ์ดํ ํ
์คํธ๋ก
|
| 105 |
+
- ํ์ดํ ์ฃผ์๊ณผ ํจ๊ป ์ฃผ์ ๊ธฐ๋ฅ ์ค๋ช
|
| 106 |
+
- ์ค๋ฒ๋ ์ด ํ
์คํธ๋ก ๊ธฐ์ ์ฌ์
|
| 107 |
+
- ์ฌ๋ฃ/๊ตฌ์ฑ์์ ๋ ์ด๋ธ
|
| 108 |
+
์์: "์๋จ์ 'MODEL X-500' ํ
์คํธ ์ค๋ฒ๋ ์ด, 'ํฐํ๋ ํ๋ ์', 'OLED ๋์คํ๋ ์ด', '5000mAh ๋ฐฐํฐ๋ฆฌ'๋ฅผ ๊ฐ๋ฆฌํค๋ ํ์ดํ์ ๊ธฐ๋ฅ ์ค๋ช
"]
|
| 109 |
|
| 110 |
+
**์ต์ข
๋์์ธ ๋ณด๊ณ ์:**
|
| 111 |
+
[ํ๊ตญ์ด๋ก ์์ฑ๋ ์ ํ์ ํต์ฌ ํน์ง, ํ์ ํฌ์ธํธ, ํ๊ฒ ์์ฅ, ์์ ์ ์กฐ ๋น์ฉ ๋ฑ์ ํฌํจํ ์ข
ํฉ ๋ณด๊ณ ์ - 3-4๋ฌธ์ฅ]
|
| 112 |
+
|
| 113 |
+
๊ฐ๊ฒฐํ์ง๋ง ๊ตฌ์ฒด์ ์ผ๋ก ์์ฑ. ๋ฌผ๋ฆฌ์ ์ ํ์๋ง ์ง์คํ๋ฉฐ ํ
์คํธ ์ฃผ์ ํฌํจ."""
|
| 114 |
|
| 115 |
+
# ๊ฒ์ ๊ฒฐ๊ณผ์ ํจ๊ป ํ์
ํ๋กฌํํธ ์์ฑ
|
| 116 |
+
user_prompt = f"""์ ํ ์ปจ์
: {user_input}
|
| 117 |
|
| 118 |
+
์์ง๋์ด์ ์ฐ๊ตฌ ๋ฐ์ดํฐ:
|
| 119 |
{search_results}
|
| 120 |
|
| 121 |
+
์ ์
๋ ฅ๊ณผ ์ฐ๊ตฌ๋ฅผ ๋ฐํ์ผ๋ก ํ ํ์
์คํ:
|
| 122 |
+
1. ๊ฐ๋
์ด ๋น์ ์๋ฆฝ (๊ฐ๋ตํ)
|
| 123 |
+
2. ์์ง๋์ด๊ฐ ์ ์ฐ๊ตฌ ๋ฐ์ดํฐ๋ฅผ ํ์ฉํด ๊ธฐ๋ฅ ์ถ์ฒ
|
| 124 |
+
3. ๋์์ด๋๊ฐ ํ
์คํธ ๋ ์ด๋ธ๊ณผ ์ฃผ์์ด ํฌํจ๋ ์์ธํ ์๊ฐ์ ํ๋กฌํํธ ์์ฑ
|
| 125 |
+
4. ์ต์ข
๋์์ธ ๋ณด๊ณ ์ ์์ฑ (ํ๊ตญ์ด)
|
| 126 |
|
| 127 |
+
์ ์กฐ ๊ฐ๋ฅํ๊ณ ํ์ ์ ์ธ ์ ํ ๋์์ธ ์ฐฝ์ถ์ ์ง์คํ๋ฉฐ, ๋ช
ํํ ํ
์คํธ ์ค๋ฒ๋ ์ด๋ก ์ฃผ์ ๊ธฐ๋ฅ, ์ฌ์, ๊ตฌ์ฑ์์ ๋ ์ด๋ธ ํ์."""
|
| 128 |
|
| 129 |
payload = {
|
| 130 |
"model": "accounts/fireworks/models/qwen3-235b-a22b-instruct-2507", # Original model maintained
|
| 131 |
+
"max_tokens": 600,
|
| 132 |
"top_p": 0.9,
|
| 133 |
"temperature": 0.7,
|
| 134 |
"messages": [
|
|
|
|
| 155 |
result = response.json()
|
| 156 |
enhanced = result.get('choices', [{}])[0].get('message', {}).get('content', '')
|
| 157 |
if enhanced:
|
| 158 |
+
# ๋์์ด๋์ ์ต์ข
ํ๋กฌํํธ ์ถ์ถ
|
| 159 |
+
if "๋์์ด๋์ ์ต์ข
ํ๋กฌํํธ:" in enhanced or "DESIGNER'S FINAL PROMPT:" in enhanced:
|
| 160 |
+
parts = enhanced.split("๋์์ด๋์ ์ต์ข
ํ๋กฌํํธ:" if "๋์์ด๋์ ์ต์ข
ํ๋กฌํํธ:" in enhanced else "DESIGNER'S FINAL PROMPT:")
|
| 161 |
if len(parts) > 1:
|
| 162 |
+
# ์ต์ข
ํ๋กฌํํธ์ ์ ์ฒด ํ ๋ก ๋ชจ๋ ๋ฐํ
|
| 163 |
+
final_prompt = parts[1].split("**")[0].strip()
|
| 164 |
+
return final_prompt, enhanced
|
| 165 |
return enhanced, enhanced
|
| 166 |
|
| 167 |
+
# API ์คํจ ์ ํด๋ฐฑ
|
| 168 |
+
return create_basic_design_prompt(user_input), "ํ ํ์
๋ถ๊ฐ - ๊ธฐ๋ณธ ํ๋กฌํํธ ์ฌ์ฉ"
|
| 169 |
|
| 170 |
except requests.exceptions.Timeout:
|
| 171 |
+
print("Fireworks API ํ์์์ - ํด๋ฐฑ ์ฌ์ฉ")
|
| 172 |
+
return create_basic_design_prompt(user_input), "API ํ์์์ - ํด๋ฐฑ ํ๋กฌํํธ ์์ฑ ์ฌ์ฉ"
|
| 173 |
except Exception as e:
|
| 174 |
+
print(f"ํ ํ์
์ค๋ฅ: {str(e)}")
|
| 175 |
+
return create_basic_design_prompt(user_input), f"์ค๋ฅ: {str(e)[:100]}"
|
| 176 |
|
| 177 |
def create_basic_design_prompt(user_input):
|
| 178 |
"""
|
| 179 |
+
ํ
์คํธ ์ฃผ์์ด ํฌํจ๋ ๊ธฐ๋ณธ ๋์์ธ ํ๋กฌํํธ ์์ฑ์ ์ํ ํด๋ฐฑ ํจ์
|
| 180 |
"""
|
| 181 |
product_name = user_input.upper().replace(" ", "-")
|
| 182 |
+
return f"""์์ธํ ํ
์คํธ ์ฃผ์์ด ํฌํจ๋ {user_input}์ ์ ๋ฌธ ์ ํ ๋์์ธ ์ปจ์
:
|
| 183 |
+
- ์๋จ์ ๊ตต์ ๋ชจ๋ ํฐํธ๋ก ์ ํ ํ์ดํ ํ
์คํธ ์ค๋ฒ๋ ์ด: "{product_name} PRO 2025"
|
| 184 |
+
- ์ฃผ์ ๊ตฌ์ฑ์์๋ฅผ ๊ฐ๋ฆฌํค๋ ํ์ดํ์ ํจ๊ป ๊ธฐ๋ฅ ์ค๋ช
๋ ์ด๋ธ:
|
| 185 |
+
* "ํ๋ฆฌ๋ฏธ์ ์์ฌ" โ ๋ณธ์ฒด
|
| 186 |
+
* "์ธ์ฒด๊ณตํ์ ๋์์ธ" โ ํผ ํฉํฐ
|
| 187 |
+
* "์ค๋งํธ ํตํฉ" โ ์ ์ด ํจ๋
|
| 188 |
+
* "์ง์๊ฐ๋ฅํ ์ ์กฐ" โ ์นํ๊ฒฝ ์์
|
| 189 |
+
- ๋ชจ์๋ฆฌ์ ๊ธฐ์ ์ฌ์ ํ
์คํธ ์ค๋ฒ๋ ์ด:
|
| 190 |
+
* ์น์, ๋ฌด๊ฒ, ์ ๋ ฅ ์ฌ์
|
| 191 |
+
- ์ฃผ์์ด ํฌํจ๋ ๊น๋ํ ์ฐ์
๋์์ธ
|
| 192 |
+
- ์คํ๋์ค ์กฐ๋ช
๊ณผ ํจ๊ป ํฌํ ๋ฆฌ์ผ๋ฆฌ์คํฑ ๋ ๋๋ง
|
| 193 |
+
- ์ธํฌ๊ทธ๋ํฝ ์์๊ฐ ํฌํจ๋ ์ ๋ฌธ ์ ํ ์ฌ์ง ์คํ์ผ
|
| 194 |
+
- ๊น๋ํ ์ฐ์ธ๋ฆฌํ ํฐํธ(Helvetica/Arial ์คํ์ผ)์ ํ
์คํธ ๋ ์ด๋ธ
|
| 195 |
+
- ๊ฐ๋
์ฑ์ ์ํ ๋์ ๋๋น ํ
์คํธ
|
| 196 |
+
- ๋ชจ๋ ๋ ์ด๋ธ์ด ๋ช
ํํ ๋ณด์ด๋ 3/4 ๊ด์ ์์ ํ์"""
|
| 197 |
|
| 198 |
def upload_image_to_hosting(image):
|
| 199 |
"""
|
| 200 |
+
ํธ์คํ
์๋น์ค์ ์ด๋ฏธ์ง ์
๋ก๋
|
| 201 |
"""
|
| 202 |
try:
|
| 203 |
+
# imgbb ๋จผ์ ์๋
|
| 204 |
buffered = BytesIO()
|
| 205 |
image.save(buffered, format="PNG")
|
| 206 |
buffered.seek(0)
|
|
|
|
| 222 |
except:
|
| 223 |
pass
|
| 224 |
|
| 225 |
+
# base64๋ก ํด๋ฐฑ
|
| 226 |
buffered = BytesIO()
|
| 227 |
image.save(buffered, format="PNG")
|
| 228 |
buffered.seek(0)
|
|
|
|
| 231 |
|
| 232 |
def process_product_design(prompt, enhance_prompt_flag, image1, image2=None):
|
| 233 |
"""
|
| 234 |
+
ํ ํ์
์ ํตํ ์ ํ ๋์์ธ ์ฒ๋ฆฌ
|
| 235 |
"""
|
| 236 |
if not os.getenv('REPLICATE_API_TOKEN'):
|
| 237 |
+
return None, prompt, "โ ๏ธ REPLICATE_API_TOKEN์ ์ค์ ํ์ธ์", ""
|
| 238 |
|
| 239 |
try:
|
| 240 |
team_discussion = ""
|
| 241 |
final_prompt = prompt
|
| 242 |
|
| 243 |
+
# ํ์ฑํ๋ ๊ฒฝ์ฐ ํ ํ์
์ ์ฉ
|
| 244 |
if enhance_prompt_flag:
|
| 245 |
result = enhance_prompt_with_team(prompt)
|
| 246 |
if isinstance(result, tuple):
|
| 247 |
final_prompt, team_discussion = result
|
| 248 |
else:
|
| 249 |
final_prompt = result
|
| 250 |
+
team_discussion = "ํ ํ์
์๋ฃ"
|
| 251 |
|
| 252 |
+
# ํ์๋ฅผ ์ํ ํ ํ ๋ก ํ์ํ
|
| 253 |
+
if "๊ฐ๋
์ ๋น์ :" in team_discussion or "DIRECTOR'S VISION:" in team_discussion:
|
| 254 |
+
team_discussion = f"### ๐ฌ ํ ํ์
ํ๋ก์ธ์ค\n\n{team_discussion}"
|
| 255 |
|
| 256 |
+
# ๋ชจ๋ธ ์
๋ ฅ ์ค๋น
|
| 257 |
model_input = {
|
| 258 |
"prompt": final_prompt
|
| 259 |
}
|
| 260 |
|
| 261 |
+
# ์ ๊ณต๋ ๊ฒฝ์ฐ ์ฐธ์กฐ ์ด๋ฏธ์ง ์ถ๊ฐ
|
| 262 |
if image1 or image2:
|
| 263 |
image_urls = []
|
| 264 |
|
|
|
|
| 271 |
image_urls.append(url2)
|
| 272 |
|
| 273 |
model_input["image_input"] = image_urls
|
| 274 |
+
status_msg = "โ
์คํ์ผ ์ฐธ์กฐ์ ํจ๊ป ์ ํ ๋์์ธ ์์ฑ ์๋ฃ!"
|
| 275 |
else:
|
| 276 |
+
status_msg = "โ
์ ํ ๋์์ธ์ด ์ฑ๊ณต์ ์ผ๋ก ์์ฑ๋์์ต๋๋ค!"
|
| 277 |
|
| 278 |
+
# Replicate๋ก ์ด๋ฏธ์ง ์์ฑ
|
| 279 |
try:
|
| 280 |
+
# ํ๋กฌํํธ์ ํ
์คํธ ์ฃผ์ ๊ฐ์กฐ ์ถ๊ฐ
|
| 281 |
annotated_prompt = f"{final_prompt}. Include clear text labels, feature callouts with arrows, product name/model as title, technical specifications overlay, component annotations in clean modern typography"
|
| 282 |
|
| 283 |
output = replicate.run(
|
|
|
|
| 291 |
}
|
| 292 |
)
|
| 293 |
except:
|
| 294 |
+
# ํ
์คํธ ์ฃผ์๊ณผ ํจ๊ป ์๋ณธ ๋ชจ๋ธ๋ก ํด๋ฐฑ
|
| 295 |
annotated_prompt = f"{final_prompt}. With text overlays showing product name, key features with arrow callouts, specifications, and component labels in professional typography"
|
| 296 |
|
| 297 |
output = replicate.run(
|
|
|
|
| 306 |
)
|
| 307 |
|
| 308 |
if output is None:
|
| 309 |
+
return None, final_prompt, "โ ๋ชจ๋ธ๋ก๋ถํฐ ์ถ๋ ฅ์ ๋ฐ์ง ๋ชปํ์ต๋๋ค", team_discussion
|
| 310 |
|
| 311 |
+
# ์ถ๋ ฅ ์ฒ๋ฆฌ
|
| 312 |
output_url = None
|
| 313 |
if isinstance(output, str):
|
| 314 |
output_url = output
|
|
|
|
| 323 |
img = Image.open(BytesIO(response.content))
|
| 324 |
return img, final_prompt, status_msg, team_discussion
|
| 325 |
|
| 326 |
+
return None, final_prompt, "โ ์ถ๋ ฅ์ ์ฒ๋ฆฌํ ์ ์์ต๋๋ค", team_discussion
|
| 327 |
|
| 328 |
except Exception as e:
|
| 329 |
error_msg = str(e)
|
| 330 |
+
return None, prompt, f"โ ์ค๋ฅ: {error_msg[:200]}", ""
|
| 331 |
|
| 332 |
+
# ์ ๋ฌธ ์ ํ ๋์์ธ CSS
|
| 333 |
css = """
|
| 334 |
.gradio-container {
|
| 335 |
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
|
| 336 |
+
font-family: 'Pretendard', 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
|
| 337 |
min-height: 100vh;
|
| 338 |
}
|
| 339 |
.header-container {
|
|
|
|
| 370 |
text-align: center;
|
| 371 |
font-weight: 500;
|
| 372 |
color: #ffd700;
|
| 373 |
+
max-width: 600px;
|
| 374 |
font-size: 0.9rem;
|
| 375 |
}
|
| 376 |
.main-content {
|
|
|
|
| 414 |
padding: 1.2rem;
|
| 415 |
margin-top: 1rem;
|
| 416 |
border: 1px solid #dee2e6;
|
| 417 |
+
font-family: 'Pretendard', 'Noto Sans KR', monospace;
|
| 418 |
font-size: 0.85rem;
|
| 419 |
+
max-height: 400px;
|
| 420 |
overflow-y: auto;
|
| 421 |
white-space: pre-wrap;
|
| 422 |
+
line-height: 1.6;
|
| 423 |
}
|
| 424 |
.enhanced-prompt-box {
|
| 425 |
background: #f0f0f0;
|
|
|
|
| 450 |
}
|
| 451 |
"""
|
| 452 |
|
| 453 |
+
# Gradio ์ธํฐํ์ด์ค ์์ฑ
|
| 454 |
with gr.Blocks(css=css, theme=gr.themes.Base()) as demo:
|
| 455 |
with gr.Column(elem_classes="header-container"):
|
| 456 |
gr.HTML("""
|
| 457 |
+
<h1 class="logo-text">๐ญ ์ ํ ๋์์ธ ์คํ๋์ค</h1>
|
| 458 |
+
<p class="subtitle">AI ๊ธฐ๋ฐ ์ฐ์
๋์์ธ ์์คํ
- ์น ๋ฆฌ์์น์ ์ฃผ์ ๊ธฐ๋ฅ ํฌํจ</p>
|
| 459 |
<div class="mode-indicator">
|
| 460 |
+
๐ฅ ๊ฐ๋
โ ๐ ์์ง๋์ด (Brave ๊ฒ์) โ ๐จ ๋์์ด๋ (ํ
์คํธ ์ฃผ์ ํฌํจ)
|
| 461 |
</div>
|
| 462 |
""")
|
| 463 |
|
| 464 |
with gr.Column(elem_classes="main-content"):
|
| 465 |
gr.HTML("""
|
| 466 |
<div class="info-box">
|
| 467 |
+
<strong>๐ฏ ์ ๋ฌธ ์ ํ ๋์์ธ ํ๋ก์ธ์ค (์ฃผ์ ํฌํจ):</strong><br>
|
| 468 |
+
โข <b>๊ฐ๋
:</b> ๋น์ ๊ณผ ์๊ตฌ์ฌํญ ์๋ฆฝ<br>
|
| 469 |
+
โข <b>์์ง๋์ด:</b> Brave API๋ก ์ต์ ํธ๋ ๋์ ๊ธฐ์ ๊ฒ์<br>
|
| 470 |
+
โข <b>๋์์ด๋:</b> <b>ํ
์คํธ ๋ ์ด๋ธ๊ณผ ๊ธฐ๋ฅ ์ค๋ช
</b>์ด ํฌํจ๋ ์๊ฐ ์ฌ์ ์์ฑ<br>
|
| 471 |
+
โข <b>๊ฒฐ๊ณผ๋ฌผ:</b> ์ฃผ์ ๊ธฐ๋ฅ์ด ๊ฐ์กฐ๋ ์ฃผ์ ํฌํจ ์ ํ ๋์์ธ<br>
|
| 472 |
+
โข <b>์ง์ค ๋ถ์ผ:</b> ์ธํฌ๊ทธ๋ํฝ ์คํ์ผ ์ฃผ์์ด ํฌํจ๋ ๋ฌผ๋ฆฌ์ ์ ํ
|
| 473 |
</div>
|
| 474 |
""")
|
| 475 |
|
| 476 |
with gr.Row(equal_height=True):
|
| 477 |
with gr.Column(scale=1):
|
| 478 |
prompt = gr.Textbox(
|
| 479 |
+
label="๐ ์ ํ ์ปจ์
",
|
| 480 |
+
placeholder="์ ํ ์ ํ ์
๋ ฅ: '์ค๋งํธ ์ด๋ํ', '๋ฏธ๋ํ ์ฃผ๋ฐฉ์ฉํ', '์นํ๊ฒฝ ๊ฐ๋ฐฉ', '๋ชจ๋ํ ๊ฐ๊ตฌ'...",
|
| 481 |
lines=2,
|
| 482 |
+
value="์ฐจ์ธ๋ ๋ฌด์ ์ด์ดํฐ",
|
| 483 |
elem_classes="prompt-input"
|
| 484 |
)
|
| 485 |
|
| 486 |
enhance_prompt_checkbox = gr.Checkbox(
|
| 487 |
+
label="๐ ์น ๋ฆฌ์์น๋ฅผ ํตํ ํ ํ์
ํ์ฑํ",
|
| 488 |
value=True,
|
| 489 |
+
info="๊ฐ๋
+ ์์ง๋์ด(Brave ๊ฒ์) + ๋์์ด๋ ํ๋ก์ธ์ค ํ์ฑํ"
|
| 490 |
)
|
| 491 |
|
| 492 |
with gr.Row():
|
| 493 |
image1 = gr.Image(
|
| 494 |
+
label="์คํ์ผ ์ฐธ์กฐ 1 (์ ํ์ฌํญ)",
|
| 495 |
type="pil",
|
| 496 |
height=180
|
| 497 |
)
|
| 498 |
image2 = gr.Image(
|
| 499 |
+
label="์คํ์ผ ์ฐธ์กฐ 2 (์ ํ์ฌํญ)",
|
| 500 |
type="pil",
|
| 501 |
height=180
|
| 502 |
)
|
| 503 |
|
| 504 |
generate_btn = gr.Button(
|
| 505 |
+
"๐จ ์ ํ ๋์์ธ ์์ฑ",
|
| 506 |
variant="primary",
|
| 507 |
size="lg"
|
| 508 |
)
|
| 509 |
|
| 510 |
with gr.Column(scale=1):
|
| 511 |
output_image = gr.Image(
|
| 512 |
+
label="์์ฑ๋ ์ ํ ๋์์ธ",
|
| 513 |
type="pil",
|
| 514 |
height=400,
|
| 515 |
elem_classes="image-container"
|
| 516 |
)
|
| 517 |
|
| 518 |
enhanced_prompt_display = gr.Textbox(
|
| 519 |
+
label="๐ ์ต์ข
๋์์ธ ์ฌ์",
|
| 520 |
interactive=False,
|
| 521 |
lines=3,
|
| 522 |
elem_classes="enhanced-prompt-box"
|
| 523 |
)
|
| 524 |
|
| 525 |
status = gr.Textbox(
|
| 526 |
+
label="์ํ",
|
| 527 |
interactive=False,
|
| 528 |
elem_classes="status-text",
|
| 529 |
+
value="๋์์ธ ์ค๋น ์ค..."
|
| 530 |
)
|
| 531 |
|
| 532 |
with gr.Row():
|
|
|
|
| 535 |
elem_classes="team-discussion"
|
| 536 |
)
|
| 537 |
|
| 538 |
+
# ์ด๋ฒคํธ ํธ๋ค๋ฌ ์ฐ๊ฒฐ
|
| 539 |
generate_btn.click(
|
| 540 |
fn=process_product_design,
|
| 541 |
inputs=[prompt, enhance_prompt_checkbox, image1, image2],
|
| 542 |
outputs=[output_image, enhanced_prompt_display, status, team_discussion_display]
|
| 543 |
)
|
| 544 |
|
| 545 |
+
# ์ฐฝ์์ ์ธ ํ๊ธ ์ ํ ์์
|
| 546 |
gr.Examples(
|
| 547 |
examples=[
|
| 548 |
+
["๊ณต์ค ๋ถ์ ์คํผ์ปค", True, None, None],
|
| 549 |
+
["๋ณํ ๊ฐ๋ฅํ ๋ค๋ชฉ์ ๊ฐ๊ตฌ", True, None, None],
|
| 550 |
+
["์๊ฐ ์ถฉ์ ์ค๋งํธ ์ ๋ฐ", True, None, None],
|
| 551 |
+
["ํ๋ก๊ทธ๋จ ๋์คํ๋ ์ด ์๊ณ", True, None, None],
|
| 552 |
+
["์ ์ด์ ์ ๊ธฐ ์ค์ฟ ํฐ ํฌ๋ฉง", True, None, None],
|
| 553 |
+
["AI ์๋ฆฌ ๋์ฐ๋ฏธ ๋ก๋ด", True, None, None],
|
| 554 |
+
["ํฌ๋ช
OLED ๋
ธํธ๋ถ", True, None, None],
|
| 555 |
+
["์์ฒด์ธ์ ์ค๋งํธ ๋์ด๋ฝ", True, None, None],
|
| 556 |
+
["๋ชจ๋ํ ์บ ํ ์ฅ๋น ์์คํ
", True, None, None],
|
| 557 |
+
["์จ์ด๋ฌ๋ธ ๊ณต๊ธฐ์ฒญ์ ๊ธฐ", True, None, None],
|
| 558 |
+
["์๋ ์จ๋์กฐ์ ํ
๋ธ๋ฌ", True, None, None],
|
| 559 |
+
["๋ฏธ๋ํ ๋ฐ๋ ค๋๋ฌผ ์ผ์ด ์คํ
์ด์
", True, None, None],
|
| 560 |
],
|
| 561 |
inputs=[prompt, enhance_prompt_checkbox, image1, image2],
|
| 562 |
+
label="๐ก ์ฐฝ์์ ์ธ ์ ํ ๋์์ธ ์์"
|
| 563 |
)
|
| 564 |
|
| 565 |
+
# ์คํ ์ค์
|
| 566 |
if __name__ == "__main__":
|
| 567 |
+
# ํ์ํ API ํค ํ์ธ
|
| 568 |
if not os.getenv('REPLICATE_API_TOKEN'):
|
| 569 |
+
print("โ ๏ธ ๊ฒฝ๊ณ : REPLICATE_API_TOKEN์ด ์ค์ ๋์ง ์์")
|
| 570 |
if not os.getenv('FIREWORKS_API_KEY'):
|
| 571 |
+
print("โ ๏ธ ๊ฒฝ๊ณ : FIREWORKS_API_KEY๊ฐ ์ค์ ๋์ง ์์ - ํด๋ฐฑ ํ๋กฌํํธ ์ฌ์ฉ")
|
| 572 |
if not os.getenv('BRAVE_API_KEY'):
|
| 573 |
+
print("โ ๏ธ ๊ฒฝ๊ณ : BRAVE_API_KEY๊ฐ ์ค์ ๋์ง ์์ - ์น ๊ฒ์ ๋ถ๊ฐ")
|
| 574 |
|
| 575 |
demo.launch(
|
| 576 |
+
share=False, # Hugging Face Spaces์ฉ์ผ๋ก False ์ค์
|
| 577 |
server_name="0.0.0.0",
|
| 578 |
server_port=7860,
|
| 579 |
+
ssr_mode=False # ๊ฒฝ๊ณ ๋ฐฉ์ง๋ฅผ ์ํด SSR ๋นํ์ฑํ
|
| 580 |
)
|