Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,580 +1,35 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import replicate
|
3 |
import os
|
4 |
-
|
5 |
-
import
|
6 |
-
from
|
7 |
-
import time
|
8 |
-
import base64
|
9 |
-
import json
|
10 |
|
11 |
-
|
12 |
-
os.environ['REPLICATE_API_TOKEN'] = os.getenv('REPLICATE_API_TOKEN')
|
13 |
-
FIREWORKS_API_KEY = os.getenv('FIREWORKS_API_KEY', '')
|
14 |
-
BRAVE_API_KEY = os.getenv('BRAVE_API_KEY', '') # Add Brave API key
|
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"
|
28 |
-
headers = {
|
29 |
-
"Accept": "application/json",
|
30 |
-
"X-Subscription-Token": BRAVE_API_KEY
|
31 |
-
}
|
32 |
-
params = {
|
33 |
-
"q": query,
|
34 |
-
"count": 5
|
35 |
-
}
|
36 |
-
|
37 |
-
response = requests.get(url, headers=headers, params=params, timeout=10)
|
38 |
-
|
39 |
-
if response.status_code == 200:
|
40 |
-
data = response.json()
|
41 |
-
results = []
|
42 |
-
|
43 |
-
if 'web' in data and 'results' in data['web']:
|
44 |
-
for item in data['web']['results'][:3]:
|
45 |
-
results.append(f"- {item.get('title', '')}: {item.get('description', '')[:150]}")
|
46 |
-
|
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": [
|
135 |
-
{
|
136 |
-
"role": "system",
|
137 |
-
"content": system_prompt
|
138 |
-
},
|
139 |
-
{
|
140 |
-
"role": "user",
|
141 |
-
"content": user_prompt
|
142 |
-
}
|
143 |
-
]
|
144 |
-
}
|
145 |
-
|
146 |
-
headers = {
|
147 |
-
"Accept": "application/json",
|
148 |
-
"Content-Type": "application/json",
|
149 |
-
"Authorization": f"Bearer {FIREWORKS_API_KEY}"
|
150 |
-
}
|
151 |
-
|
152 |
-
response = requests.post(url, headers=headers, data=json.dumps(payload), timeout=30)
|
153 |
-
|
154 |
-
if response.status_code == 200:
|
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 |
-
#
|
204 |
-
|
205 |
-
image.save(buffered, format="PNG")
|
206 |
-
buffered.seek(0)
|
207 |
-
img_base64 = base64.b64encode(buffered.getvalue()).decode()
|
208 |
|
209 |
-
|
210 |
-
"
|
211 |
-
|
212 |
-
'key': '6d207e02198a847aa98d0a2a901485a5',
|
213 |
-
'image': img_base64,
|
214 |
-
},
|
215 |
-
timeout=10
|
216 |
-
)
|
217 |
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
except:
|
223 |
-
pass
|
224 |
-
|
225 |
-
# base64๋ก ํด๋ฐฑ
|
226 |
-
buffered = BytesIO()
|
227 |
-
image.save(buffered, format="PNG")
|
228 |
-
buffered.seek(0)
|
229 |
-
img_base64 = base64.b64encode(buffered.getvalue()).decode()
|
230 |
-
return f"data:image/png;base64,{img_base64}"
|
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 |
-
|
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 |
-
|
265 |
-
if image1:
|
266 |
-
url1 = upload_image_to_hosting(image1)
|
267 |
-
image_urls.append(url1)
|
268 |
-
|
269 |
-
if image2:
|
270 |
-
url2 = upload_image_to_hosting(image2)
|
271 |
-
image_urls.append(url2)
|
272 |
-
|
273 |
-
model_input["image_input"] = image_urls
|
274 |
-
status_msg = "โ
์คํ์ผ ์ฐธ์กฐ์ ํจ๊ป ์ ํ ๋์์ธ ์์ฑ ์๋ฃ!"
|
275 |
-
else:
|
276 |
-
status_msg = "โ
์ ํ ๋์์ธ์ด ์ฑ๊ณต์ ์ผ๋ก ์์ฑ๋์์ต๋๋ค!"
|
277 |
|
278 |
-
#
|
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(
|
284 |
-
"black-forest-labs/flux-schnell", # Alternative model that works better
|
285 |
-
input={
|
286 |
-
"prompt": annotated_prompt,
|
287 |
-
"num_outputs": 1,
|
288 |
-
"aspect_ratio": "1:1",
|
289 |
-
"output_format": "webp",
|
290 |
-
"output_quality": 90
|
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(
|
298 |
-
"stability-ai/sdxl:39ed52f2a78e934b3ba6e2a89f5b1c712de7dfea535525255b1aa35c5565e08b",
|
299 |
-
input={
|
300 |
-
"prompt": annotated_prompt,
|
301 |
-
"negative_prompt": "low quality, blurry, distorted, unreadable text, messy labels",
|
302 |
-
"width": 1024,
|
303 |
-
"height": 1024,
|
304 |
-
"num_outputs": 1
|
305 |
-
}
|
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
|
315 |
-
elif isinstance(output, list) and len(output) > 0:
|
316 |
-
output_url = output[0]
|
317 |
-
elif hasattr(output, 'url'):
|
318 |
-
output_url = output.url
|
319 |
-
|
320 |
-
if output_url:
|
321 |
-
response = requests.get(output_url, timeout=30)
|
322 |
-
if response.status_code == 200:
|
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 |
-
|
330 |
-
|
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 {
|
340 |
-
background: linear-gradient(135deg, #2d2d2d 0%, #0f0f0f 100%);
|
341 |
-
padding: 2rem;
|
342 |
-
border-radius: 20px;
|
343 |
-
margin-bottom: 2rem;
|
344 |
-
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
|
345 |
-
border: 1px solid rgba(255, 215, 0, 0.2);
|
346 |
-
}
|
347 |
-
.logo-text {
|
348 |
-
font-size: 2.8rem;
|
349 |
-
font-weight: 800;
|
350 |
-
color: #ffd700;
|
351 |
-
text-align: center;
|
352 |
-
margin: 0;
|
353 |
-
letter-spacing: -1px;
|
354 |
-
text-shadow: 2px 2px 4px rgba(0,0,0,0.8);
|
355 |
-
}
|
356 |
-
.subtitle {
|
357 |
-
color: #b0b0b0;
|
358 |
-
text-align: center;
|
359 |
-
font-size: 1rem;
|
360 |
-
margin-top: 0.5rem;
|
361 |
-
font-weight: 400;
|
362 |
-
letter-spacing: 0.5px;
|
363 |
-
}
|
364 |
-
.mode-indicator {
|
365 |
-
background: rgba(255, 215, 0, 0.1);
|
366 |
-
border: 1px solid rgba(255, 215, 0, 0.3);
|
367 |
-
border-radius: 10px;
|
368 |
-
padding: 0.6rem 1.2rem;
|
369 |
-
margin: 1rem auto;
|
370 |
-
text-align: center;
|
371 |
-
font-weight: 500;
|
372 |
-
color: #ffd700;
|
373 |
-
max-width: 600px;
|
374 |
-
font-size: 0.9rem;
|
375 |
-
}
|
376 |
-
.main-content {
|
377 |
-
background: rgba(255, 255, 255, 0.98);
|
378 |
-
border-radius: 20px;
|
379 |
-
padding: 2rem;
|
380 |
-
box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
|
381 |
-
}
|
382 |
-
.gr-button-primary {
|
383 |
-
background: linear-gradient(135deg, #2d2d2d 0%, #0f0f0f 100%) !important;
|
384 |
-
border: 1px solid #ffd700 !important;
|
385 |
-
color: #ffd700 !important;
|
386 |
-
font-weight: 600 !important;
|
387 |
-
font-size: 1rem !important;
|
388 |
-
padding: 1rem 2rem !important;
|
389 |
-
border-radius: 10px !important;
|
390 |
-
transition: all 0.3s ease !important;
|
391 |
-
text-transform: uppercase;
|
392 |
-
letter-spacing: 0.5px;
|
393 |
-
width: 100%;
|
394 |
-
margin-top: 1rem !important;
|
395 |
-
}
|
396 |
-
.gr-button-primary:hover {
|
397 |
-
transform: translateY(-2px) !important;
|
398 |
-
box-shadow: 0 8px 25px rgba(255, 215, 0, 0.25) !important;
|
399 |
-
background: linear-gradient(135deg, #ffd700 0%, #ffed4e 100%) !important;
|
400 |
-
color: #000 !important;
|
401 |
-
}
|
402 |
-
.info-box {
|
403 |
-
background: linear-gradient(135deg, #fff3cd 0%, #ffeaa7 100%);
|
404 |
-
border-radius: 10px;
|
405 |
-
padding: 1rem;
|
406 |
-
margin-bottom: 1.5rem;
|
407 |
-
border-left: 4px solid #ffd700;
|
408 |
-
color: #333;
|
409 |
-
font-size: 0.9rem;
|
410 |
-
}
|
411 |
-
.team-discussion {
|
412 |
-
background: #f8f9fa;
|
413 |
-
border-radius: 10px;
|
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;
|
426 |
-
border-radius: 10px;
|
427 |
-
padding: 1rem;
|
428 |
-
margin-top: 0.5rem;
|
429 |
-
border-left: 3px solid #ffd700;
|
430 |
-
font-size: 0.9rem;
|
431 |
-
}
|
432 |
-
.gr-input, .gr-textarea {
|
433 |
-
background: #ffffff !important;
|
434 |
-
border: 1px solid #d0d0d0 !important;
|
435 |
-
border-radius: 8px !important;
|
436 |
-
font-size: 0.95rem !important;
|
437 |
-
padding: 0.7rem !important;
|
438 |
-
}
|
439 |
-
.gr-input:focus, .gr-textarea:focus {
|
440 |
-
border-color: #ffd700 !important;
|
441 |
-
box-shadow: 0 0 0 3px rgba(255, 215, 0, 0.1) !important;
|
442 |
-
}
|
443 |
-
.image-container {
|
444 |
-
border-radius: 10px !important;
|
445 |
-
overflow: hidden;
|
446 |
-
border: 1px solid #e0e0e0 !important;
|
447 |
-
}
|
448 |
-
footer {
|
449 |
-
display: none !important;
|
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():
|
533 |
-
team_discussion_display = gr.Markdown(
|
534 |
-
value="",
|
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 |
-
|
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 |
-
)
|
|
|
|
|
|
|
1 |
import os
|
2 |
+
import sys
|
3 |
+
import streamlit as st
|
4 |
+
from tempfile import NamedTemporaryFile
|
|
|
|
|
|
|
5 |
|
6 |
+
def main():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
try:
|
8 |
+
# Get the code from secrets
|
9 |
+
code = os.environ.get("MAIN_CODE")
|
|
|
|
|
|
|
10 |
|
11 |
+
if not code:
|
12 |
+
st.error("โ ๏ธ The application code wasn't found in secrets. Please add the MAIN_CODE secret.")
|
13 |
+
return
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
+
# Create a temporary Python file
|
16 |
+
with NamedTemporaryFile(suffix='.py', delete=False, mode='w') as tmp:
|
17 |
+
tmp.write(code)
|
18 |
+
tmp_path = tmp.name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
+
# Execute the code
|
21 |
+
exec(compile(code, tmp_path, 'exec'), globals())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
+
# Clean up the temporary file
|
24 |
try:
|
25 |
+
os.unlink(tmp_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
except:
|
27 |
+
pass
|
|
|
28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
except Exception as e:
|
30 |
+
st.error(f"โ ๏ธ Error loading or executing the application: {str(e)}")
|
31 |
+
import traceback
|
32 |
+
st.code(traceback.format_exc())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
|
|
34 |
if __name__ == "__main__":
|
35 |
+
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|