Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -131,699 +131,4 @@ class ConceptAnalyzer:
|
|
131 |
trends = data.get("trends", [])
|
132 |
female_appeal = data.get("female_appeal", [])
|
133 |
|
134 |
-
for i in range(min(10, len
|
135 |
-
if i < len(special_days):
|
136 |
-
concept_name = f"{special_days[i]} 이벤트"
|
137 |
-
theme = f"{special_days[i]}를 테마로 한 참여형 이벤트"
|
138 |
-
keywords = [special_days[i]] + female_appeal[:2]
|
139 |
-
score = 8.8 - (i * 0.1)
|
140 |
-
is_recommended = i < 3
|
141 |
-
else:
|
142 |
-
trend_idx = i - len(special_days)
|
143 |
-
if trend_idx < len(trends):
|
144 |
-
trend = trends[trend_idx]
|
145 |
-
concept_name = f"{trend} 챌린지"
|
146 |
-
theme = f"{trend} 참여형 챌린지 이벤트"
|
147 |
-
keywords = [trend] + trends[trend_idx+1:trend_idx+3]
|
148 |
-
score = 8.0 - (trend_idx * 0.1)
|
149 |
-
is_recommended = trend_idx < 2
|
150 |
-
|
151 |
-
concepts.append({
|
152 |
-
"name": concept_name,
|
153 |
-
"theme": theme,
|
154 |
-
"score": round(score, 1),
|
155 |
-
"reason": f"20-40대 여성에게 인기 높은 {concept_name.split()[0]} 테마",
|
156 |
-
"target": "20-40대 여성",
|
157 |
-
"colors": data.get("colors", ["#FF69B4"]),
|
158 |
-
"keywords": keywords,
|
159 |
-
"is_recommended": is_recommended
|
160 |
-
})
|
161 |
-
|
162 |
-
concepts.sort(key=lambda x: (x.get("is_recommended", False), x["score"]), reverse=True)
|
163 |
-
|
164 |
-
recommended_concept = next((c for c in concepts if c.get("is_recommended", False)), concepts[0])
|
165 |
-
|
166 |
-
result = f"# 🎯 {month} 20-40대 여성 맞춤 컨셉 분석\n\n"
|
167 |
-
result += f"## 🏆 이달의 추천 컨셉: {recommended_concept['name']}\n"
|
168 |
-
result += f"**⭐ 추천 이유:** {recommended_concept['reason']}\n"
|
169 |
-
result += f"**📊 예상 참여도:** {recommended_concept['score']}/10점\n\n"
|
170 |
-
result += "---\n\n"
|
171 |
-
|
172 |
-
concept_names = []
|
173 |
-
|
174 |
-
for i, concept in enumerate(concepts, 1):
|
175 |
-
is_recommended_mark = " 🏆 **추천**" if concept.get("is_recommended", False) else ""
|
176 |
-
result += f"## {i}. {concept['name']}{is_recommended_mark}\n"
|
177 |
-
result += f"**🏷️ 테마:** {concept['theme']}\n"
|
178 |
-
result += f"**⭐ 참여도 점수:** {concept['score']}/10점\n"
|
179 |
-
result += f"**💡 선정 이유:** {concept['reason']}\n"
|
180 |
-
result += f"**🎯 주요 타겟:** {concept['target']}\n"
|
181 |
-
result += f"**🔑 핵심 키워드:** {', '.join(concept['keywords'])}\n"
|
182 |
-
result += f"**🎨 추천 색상:** {', '.join(concept['colors'])}\n\n"
|
183 |
-
result += "---\n\n"
|
184 |
-
|
185 |
-
concept_names.append(concept['name'])
|
186 |
-
|
187 |
-
return result, concept_names False) else ""
|
188 |
-
result += f"## {i}. {concept['name']}{is_recommended_mark}\n"
|
189 |
-
result += f"**🏷️ 테마:** {concept['theme']}\n"
|
190 |
-
result += f"**⭐ 참여도 점수:** {concept['score']}/10점\n"
|
191 |
-
result += f"**💡 선정 이유:** {concept['reason']}\n"
|
192 |
-
result += f"**🎯 주요 타겟:** {concept['target']}\n"
|
193 |
-
result += f"**🔑 핵심 키워드:** {', '.join(concept['keywords'])}\n"
|
194 |
-
result += f"**🎨 추천 색상:** {', '.join(concept['colors'])}\n\n"
|
195 |
-
result += "---\n\n"
|
196 |
-
|
197 |
-
concept_names.append(concept['name'])
|
198 |
-
|
199 |
-
return result, concept_names
|
200 |
-
|
201 |
-
# ================== 이벤트 관리 모듈 ==================
|
202 |
-
class EventManager:
|
203 |
-
def __init__(self):
|
204 |
-
self.reward_types = [
|
205 |
-
"네이버페이 금액권",
|
206 |
-
"배달의민족 상품권",
|
207 |
-
"스타벅스 기프트카드",
|
208 |
-
"CGV 영화관람권",
|
209 |
-
"올리브영 상품권"
|
210 |
-
]
|
211 |
-
|
212 |
-
def calculate_event_duration(self, start_date, end_date):
|
213 |
-
try:
|
214 |
-
start = datetime.strptime(start_date, "%Y-%m-%d")
|
215 |
-
end = datetime.strptime(end_date, "%Y-%m-%d")
|
216 |
-
duration = (end - start).days + 1
|
217 |
-
month = start.month
|
218 |
-
|
219 |
-
start_weekday = start.strftime("(%a)")
|
220 |
-
end_weekday = end.strftime("(%a)")
|
221 |
-
|
222 |
-
return duration, month, start_weekday, end_weekday, start, end
|
223 |
-
except:
|
224 |
-
return 0, 0, "", "", None, None
|
225 |
-
|
226 |
-
def generate_detailed_comment_event(self, start_date, end_date, concept, reward_structure, kakao_id, phone_number):
|
227 |
-
if not concept:
|
228 |
-
return "먼저 이벤트 컨셉을 입력해주세요."
|
229 |
-
|
230 |
-
duration_info, month, start_weekday, end_weekday, start_dt, end_dt = self.calculate_event_duration(start_date, end_date)
|
231 |
-
|
232 |
-
if duration_info == 0:
|
233 |
-
return "날짜 형식을 확인해주세요."
|
234 |
-
|
235 |
-
formatted_start = f"{start_dt.year}년 {start_dt.month}월 {start_dt.day}일 {start_weekday} 00:00"
|
236 |
-
formatted_end = f"{end_dt.year}년 {end_dt.month}월 {end_dt.day}일 {end_weekday} 23:59"
|
237 |
-
|
238 |
-
template = f"""댓글 남기면 1시간마다 선물이!
|
239 |
-
🎉 {concept} 이벤트
|
240 |
-
|
241 |
-
{formatted_start} - {formatted_end} ({duration_info}일간)
|
242 |
-
|
243 |
-
========================
|
244 |
-
EVENT
|
245 |
-
<커뮤니티>에 작성된 글에 유익하고 착한 댓글을 남기면
|
246 |
-
1시간마다 1명씩! 하루 24명에게 선물을드려요!
|
247 |
-
|
248 |
-
{formatted_start} - {formatted_end} ({duration_info}일간)
|
249 |
-
|
250 |
-
=====================
|
251 |
-
STEP 1
|
252 |
-
회사명 <커뮤니티>에 작성된 글에
|
253 |
-
유익하고 착한 댓글 작성
|
254 |
-
* 이쁘고 좋은 말 많이 해주는 회원님들이 되길 부탁드려요
|
255 |
-
|
256 |
-
STEP 2
|
257 |
-
댓글 작성 후 선물 당첨 팝업이 나타나면
|
258 |
-
화면캡쳐 또는 사진촬영하기!
|
259 |
-
*당첨팝업은 이벤트 기간동안 1시간마다 1명씩!
|
260 |
-
하루 24명에게 나타나요!
|
261 |
-
|
262 |
-
STEP 3
|
263 |
-
당첨팝업 캡쳐 & 촬영했으면
|
264 |
-
카카오톡 또는 고객센터로 연락하기!
|
265 |
-
|
266 |
-
=================
|
267 |
-
당첨혜택
|
268 |
-
{reward_structure}
|
269 |
-
|
270 |
-
========================
|
271 |
-
이벤트 대상
|
272 |
-
일반 여성회원이라면 누구나!
|
273 |
-
(*회원, 비회원 모두 참여가능 / 기업회원제외)
|
274 |
-
|
275 |
-
========================
|
276 |
-
수령방법
|
277 |
-
댓글 작성 후 랜덤하게뜨는 이미지를 캡처 or 사진 촬영하기!
|
278 |
-
꼭 캡처후 팝업을 닫아주세요!
|
279 |
-
|
280 |
-
1.상단 당첨 날짜와 시간이 함께 나오도록
|
281 |
-
화면캡쳐 또는 사진촬영
|
282 |
-
|
283 |
-
2.카카오톡 ({kakao_id}) 로 캡쳐 사진 보내기
|
284 |
-
|
285 |
-
3.카카오톡으로 연락처를 남기거나
|
286 |
-
고객센터 운영시간에 맞춰 전화하기
|
287 |
-
|
288 |
-
4. 고객센터와 여성회원 확인 통화 후
|
289 |
-
선물 받기!
|
290 |
-
|
291 |
-
=========================
|
292 |
-
꼭 확인하세요!
|
293 |
-
※본이벤트는 회사명 일반 여성회원만 참여가능합니다. (비회원도 가능)
|
294 |
-
※ pc에서 캡처가 어려운 경우, 카메라로 촬영하여 연락 주셔도 됩니다.
|
295 |
-
※이벤트 팝업 상품 이미지와 상단 당첨 날짜&시간을 함께
|
296 |
-
화면 캡처 또는 사진 촬영해야 수령 가능합니다.
|
297 |
-
※ 화면 캡처 전에 팝업을 닫을 시, 상품 지급이 어려우니 반드시 캡처 또는
|
298 |
-
촬영 후 팝업을 닫아주세요!
|
299 |
-
※당첨 시 여성확인절차가 있음으로 고객센터로 연락 주시기 바랍니다. (통화로 여성확인)
|
300 |
-
※ 고객센터와 여성 확인 통화 후 상품 수령가능합니다.
|
301 |
-
※ 상품은 1인 1일 최대 1회까지 수령이 가능합니다. 같은 날 재당첨되어도
|
302 |
-
지급되지 않습니다. 단, 날짜가 다를 시 중복 수령 가능합니다.
|
303 |
-
※ 상품 수령 가능 기간은 당첨 일로부터 영업일 기준 다음 날까지 가능합니다.
|
304 |
-
ex) 주말 당첨시, 고객센터 영업일(월) 업무 종료시간 19:00시까지 수령가능
|
305 |
-
|
306 |
-
===========================
|
307 |
-
{phone_number}
|
308 |
-
※ 대표번호는 문자수신이 불가합니다
|
309 |
-
고객센터 운영시간
|
310 |
-
(평일 09:30~19:00 / 점심 12:00~13:30)
|
311 |
-
※ 주말 및 공휴일은 운영하지 않습니다.
|
312 |
-
카카오톡 ID: {kakao_id}
|
313 |
-
"""
|
314 |
-
|
315 |
-
return template
|
316 |
-
|
317 |
-
def generate_design_advice(self, concept):
|
318 |
-
advice = f"""🎨 디자인 조언 ({concept} 테마)
|
319 |
-
|
320 |
-
🎯 컬러 팔레트
|
321 |
-
- 20-40대 여성에게 어필하는 따뜻하고 친근한 색상
|
322 |
-
- 메인 컬러: 브랜드 컬러와 조화
|
323 |
-
- 서브 컬러: 가독성을 높이는 대비 색상
|
324 |
-
|
325 |
-
📐 레이아웃 구조
|
326 |
-
1. **메인 제목**: 임팩트 있는 큰 폰트 + 이모티콘
|
327 |
-
2. **날짜 정보**: 박스로 구분하여 명확하게 표시
|
328 |
-
3. **EVENT 섹션**: 굵은 구분선으로 강조
|
329 |
-
4. **STEP 가이드**: 숫자와 함께 단계별 명확한 구분
|
330 |
-
5. **당첨혜택**: 상품 이미지와 함께 시각적으로 강조
|
331 |
-
6. **주의사항**: 읽기 쉽게 ※ 기호로 구분
|
332 |
-
|
333 |
-
👀 가독성 향상 포인트
|
334 |
-
- 구분선(=====) 활용으로 섹션 명확히 분리
|
335 |
-
- 중요 정보는 박스 처리 또는 배경색 변경
|
336 |
-
- 단계별 가이드는 아이콘과 함께 시각화
|
337 |
-
- 모바일에서도 스크롤하며 읽기 편하게 구성
|
338 |
-
|
339 |
-
🔥 핵심 강조 요소
|
340 |
-
- "1시간마다 1명씩" - 긴급성 강조
|
341 |
-
- "하루 24명" - 기회의 많음 어필
|
342 |
-
- 상품 이미지 - 실제 혜택 시각화
|
343 |
-
- 참여 방법 - 간단함 강조"""
|
344 |
-
|
345 |
-
return advice
|
346 |
-
|
347 |
-
# ================== API 연동 모듈 ==================
|
348 |
-
class APIIntegrations:
|
349 |
-
def __init__(self):
|
350 |
-
self.api_status = {}
|
351 |
-
|
352 |
-
def test_instagram_api(self, access_token):
|
353 |
-
try:
|
354 |
-
if not access_token:
|
355 |
-
return {"status": "error", "message": "Access Token이 필요합니다"}
|
356 |
-
|
357 |
-
url = f"https://graph.instagram.com/me?fields=id,username&access_token={access_token}"
|
358 |
-
response = requests.get(url, timeout=10)
|
359 |
-
|
360 |
-
if response.status_code == 200:
|
361 |
-
data = response.json()
|
362 |
-
return {
|
363 |
-
"status": "success",
|
364 |
-
"message": f"Instagram 연결 성공 - @{data.get('username', 'unknown')}"
|
365 |
-
}
|
366 |
-
else:
|
367 |
-
return {"status": "error", "message": "Instagram API 인증 실패"}
|
368 |
-
|
369 |
-
except Exception as e:
|
370 |
-
return {"status": "error", "message": f"Instagram 연결 오류: {str(e)}"}
|
371 |
-
|
372 |
-
def test_analytics_api(self, tracking_id):
|
373 |
-
try:
|
374 |
-
if not tracking_id:
|
375 |
-
return {"status": "error", "message": "Tracking ID가 필요합니다"}
|
376 |
-
|
377 |
-
if tracking_id.startswith("G-"):
|
378 |
-
return {"status": "success", "message": f"Google Analytics 설정 확인됨 - {tracking_id}"}
|
379 |
-
else:
|
380 |
-
return {"status": "error", "message": "올바른 GA4 Tracking ID 형식이 아닙니다 (G-XXXXXXXXX)"}
|
381 |
-
|
382 |
-
except Exception as e:
|
383 |
-
return {"status": "error", "message": f"Analytics 연결 오류: {str(e)}"}
|
384 |
-
|
385 |
-
def test_openai_api(self, api_key):
|
386 |
-
try:
|
387 |
-
if not api_key:
|
388 |
-
return {"status": "error", "message": "API Key가 필요합니다"}
|
389 |
-
|
390 |
-
headers = {
|
391 |
-
"Authorization": f"Bearer {api_key}",
|
392 |
-
"Content-Type": "application/json"
|
393 |
-
}
|
394 |
-
|
395 |
-
url = "https://api.openai.com/v1/models"
|
396 |
-
response = requests.get(url, headers=headers, timeout=10)
|
397 |
-
|
398 |
-
if response.status_code == 200:
|
399 |
-
return {"status": "success", "message": "OpenAI API 연결 성공"}
|
400 |
-
else:
|
401 |
-
return {"status": "error", "message": "OpenAI API 인증 실패"}
|
402 |
-
|
403 |
-
except Exception as e:
|
404 |
-
return {"status": "error", "message": f"OpenAI API 연결 오류: {str(e)}"}
|
405 |
-
|
406 |
-
def test_all_connections(self, enable_instagram, instagram_token, enable_analytics, ga_tracking_id, enable_chatgpt, openai_api_key):
|
407 |
-
results = []
|
408 |
-
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
409 |
-
|
410 |
-
results.append(f"🔍 API 연결 테스트 결과 - {timestamp}\n" + "="*50 + "\n")
|
411 |
-
|
412 |
-
if enable_instagram:
|
413 |
-
instagram_result = self.test_instagram_api(instagram_token)
|
414 |
-
status_icon = "✅" if instagram_result["status"] == "success" else "❌"
|
415 |
-
results.append(f"{status_icon} Instagram: {instagram_result['message']}")
|
416 |
-
|
417 |
-
if enable_analytics:
|
418 |
-
analytics_result = self.test_analytics_api(ga_tracking_id)
|
419 |
-
status_icon = "✅" if analytics_result["status"] == "success" else "❌"
|
420 |
-
results.append(f"{status_icon} Analytics: {analytics_result['message']}")
|
421 |
-
|
422 |
-
if enable_chatgpt:
|
423 |
-
openai_result = self.test_openai_api(openai_api_key)
|
424 |
-
status_icon = "✅" if openai_result["status"] == "success" else "❌"
|
425 |
-
results.append(f"{status_icon} OpenAI: {openai_result['message']}")
|
426 |
-
|
427 |
-
if len(results) == 1:
|
428 |
-
results.append("⚠️ 설정된 API가 없습니다. API를 활성화해주세요.")
|
429 |
-
|
430 |
-
return "\n".join(results)
|
431 |
-
|
432 |
-
def generate_enhanced_concept_with_chatgpt(self, month, api_key):
|
433 |
-
try:
|
434 |
-
headers = {
|
435 |
-
"Authorization": f"Bearer {api_key}",
|
436 |
-
"Content-Type": "application/json"
|
437 |
-
}
|
438 |
-
|
439 |
-
prompt = f"""
|
440 |
-
{month}에 진행할 20-40대 여성 대상 이벤트의 창의적인 컨셉을 3개 제안해주세요.
|
441 |
-
각 컨셉은 다음을 포함해야 합니다:
|
442 |
-
- 컨셉명
|
443 |
-
- 핵심 아이디어
|
444 |
-
- 예상 참여도 (1-10점)
|
445 |
-
- 타겟층 특징
|
446 |
-
- 트렌디한 해시태그 3개
|
447 |
-
- 실행 방법
|
448 |
-
|
449 |
-
현재 유행하는 소셜미디어 트렌드와 MZ세대 관심사를 반영해주세요.
|
450 |
-
2024년 하반기 트렌드를 고려하여 답변해주세요.
|
451 |
-
"""
|
452 |
-
|
453 |
-
data = {
|
454 |
-
"model": "gpt-3.5-turbo",
|
455 |
-
"messages": [
|
456 |
-
{"role": "user", "content": prompt}
|
457 |
-
],
|
458 |
-
"max_tokens": 1500,
|
459 |
-
"temperature": 0.8
|
460 |
-
}
|
461 |
-
|
462 |
-
response = requests.post(
|
463 |
-
"https://api.openai.com/v1/chat/completions",
|
464 |
-
headers=headers,
|
465 |
-
json=data,
|
466 |
-
timeout=30
|
467 |
-
)
|
468 |
-
|
469 |
-
if response.status_code == 200:
|
470 |
-
result = response.json()
|
471 |
-
enhanced_content = result["choices"][0]["message"]["content"]
|
472 |
-
|
473 |
-
return f"""🤖 AI로 강화된 {month} 이벤트 컨셉
|
474 |
-
|
475 |
-
{enhanced_content}
|
476 |
-
|
477 |
-
---
|
478 |
-
💡 이 컨셉들을 기본 컨셉과 결합하여 더욱 창의적인 이벤트를 만들어보세요!
|
479 |
-
📊 각 컨셉의 예상 참여도를 참고하여 최적의 컨셉을 선택하실 수 있습니다."""
|
480 |
-
else:
|
481 |
-
return "ChatGPT API 요청 실패. API Key와 네트워크 연결�� 확인해주세요."
|
482 |
-
|
483 |
-
except Exception as e:
|
484 |
-
return f"ChatGPT API 오류: {str(e)}"
|
485 |
-
|
486 |
-
# ================== 메인 애플리케이션 ==================
|
487 |
-
def create_interface():
|
488 |
-
concept_analyzer = ConceptAnalyzer()
|
489 |
-
event_manager = EventManager()
|
490 |
-
api_integrations = APIIntegrations()
|
491 |
-
|
492 |
-
with gr.Blocks(title="통합 이벤트 관리 시스템", theme=gr.themes.Soft()) as demo:
|
493 |
-
|
494 |
-
gr.Markdown("# 🎉 통합 이벤트 관리 시스템")
|
495 |
-
gr.Markdown("### 컨셉 분석 + 이벤트 생성 + API 연동을 한 번에!")
|
496 |
-
|
497 |
-
with gr.Tabs():
|
498 |
-
with gr.Tab("🎯 컨셉 분석"):
|
499 |
-
with gr.Row():
|
500 |
-
with gr.Column():
|
501 |
-
gr.Markdown("## 📅 이벤트 기간 설정")
|
502 |
-
concept_event_period = gr.Textbox(
|
503 |
-
label="이벤트 기간",
|
504 |
-
placeholder="예: 2025.8.1 ~ 2025.8.10",
|
505 |
-
info="기간을 입력하면 자동으로 월별 컨셉 분석"
|
506 |
-
)
|
507 |
-
|
508 |
-
concept_month = gr.Dropdown(
|
509 |
-
choices=[f"{i}월" for i in range(1, 13)],
|
510 |
-
label="월 선택",
|
511 |
-
value="8월"
|
512 |
-
)
|
513 |
-
|
514 |
-
analyze_concept_btn = gr.Button("🔍 컨셉 분석하기", variant="primary")
|
515 |
-
|
516 |
-
selected_concept = gr.Dropdown(
|
517 |
-
label="분석된 컨셉 선택",
|
518 |
-
visible=False
|
519 |
-
)
|
520 |
-
|
521 |
-
# 추가: 직접 입력란
|
522 |
-
custom_concept_input = gr.Textbox(
|
523 |
-
label="직접 컨셉 입력",
|
524 |
-
placeholder="원하는 컨셉을 직접 입력하세요",
|
525 |
-
visible=False,
|
526 |
-
info="분석된 컨셉 외에 다른 아이디어가 있다면 입력해주세요"
|
527 |
-
)
|
528 |
-
|
529 |
-
with gr.Column():
|
530 |
-
concept_result = gr.Textbox(
|
531 |
-
label="컨셉 분석 결과",
|
532 |
-
lines=25,
|
533 |
-
placeholder="'컨셉 분석하기' 버튼을 클릭하세요"
|
534 |
-
)
|
535 |
-
|
536 |
-
with gr.Tab("📋 이벤트 생성"):
|
537 |
-
with gr.Row():
|
538 |
-
with gr.Column():
|
539 |
-
gr.Markdown("## 📅 기본 정보")
|
540 |
-
event_start_date = gr.Textbox(
|
541 |
-
label="시작일",
|
542 |
-
placeholder="YYYY-MM-DD",
|
543 |
-
value="2025-08-01"
|
544 |
-
)
|
545 |
-
|
546 |
-
event_end_date = gr.Textbox(
|
547 |
-
label="종료일",
|
548 |
-
placeholder="YYYY-MM-DD",
|
549 |
-
value="2025-08-10"
|
550 |
-
)
|
551 |
-
|
552 |
-
event_concept_input = gr.Textbox(
|
553 |
-
label="이벤트 컨셉",
|
554 |
-
placeholder="분석된 컨셉을 선택하거나 직접 입력",
|
555 |
-
info="컨셉 분석 탭에서 선택된 컨셉이 자동 입력됩니다"
|
556 |
-
)
|
557 |
-
|
558 |
-
gr.Markdown("## 🎁 상품 설정")
|
559 |
-
reward_type_selector = gr.Radio(
|
560 |
-
choices=[
|
561 |
-
"단일 상품",
|
562 |
-
"등급별 상품 (1,2,3등)",
|
563 |
-
"선택형 상품",
|
564 |
-
"직접 입력"
|
565 |
-
],
|
566 |
-
label="상품 구성 방식",
|
567 |
-
value="단일 상품"
|
568 |
-
)
|
569 |
-
|
570 |
-
with gr.Group(visible=True) as single_group:
|
571 |
-
single_type = gr.Dropdown(
|
572 |
-
choices=["네이버페이 금액권", "배달의민족 상품권", "스타벅스 기프트카드", "CGV 영화관람권"],
|
573 |
-
label="상품 종류",
|
574 |
-
value="네이버페이 금액권"
|
575 |
-
)
|
576 |
-
single_amount = gr.Number(label="금액 (원)", value=20000, step=1000)
|
577 |
-
single_frequency = gr.Textbox(
|
578 |
-
label="당첨 주기",
|
579 |
-
value="1시간마다 1명씩 하루 24명"
|
580 |
-
)
|
581 |
-
|
582 |
-
with gr.Group(visible=False) as grade_group:
|
583 |
-
with gr.Row():
|
584 |
-
grade1_amount = gr.Number(label="1등 금액", value=50000)
|
585 |
-
grade1_count = gr.Number(label="1등 인원", value=5)
|
586 |
-
with gr.Row():
|
587 |
-
grade2_amount = gr.Number(label="2등 금액", value=30000)
|
588 |
-
grade2_count = gr.Number(label="2등 인원", value=10)
|
589 |
-
with gr.Row():
|
590 |
-
grade3_amount = gr.Number(label="3등 금액", value=20000)
|
591 |
-
grade3_count = gr.Number(label="3등 인원", value=20)
|
592 |
-
|
593 |
-
with gr.Group(visible=False) as choice_group:
|
594 |
-
choice_amount = gr.Number(label="금액 (원)", value=20000)
|
595 |
-
choice_frequency = gr.Textbox(
|
596 |
-
label="당첨 주기",
|
597 |
-
value="1시간마다 1명씩 하루 24명"
|
598 |
-
)
|
599 |
-
|
600 |
-
with gr.Group(visible=False) as custom_group:
|
601 |
-
custom_reward = gr.Textbox(
|
602 |
-
label="상품 정보 직접 입력",
|
603 |
-
lines=5,
|
604 |
-
placeholder="상품 정보를 자유롭게 입력하세요"
|
605 |
-
)
|
606 |
-
|
607 |
-
gr.Markdown("## 📞 연락처")
|
608 |
-
phone_number = gr.Textbox(label="고객센터", value="1544-1234")
|
609 |
-
kakao_id = gr.Textbox(label="카카오톡 ID", value="company_kakao")
|
610 |
-
|
611 |
-
generate_event_btn = gr.Button("✨ 이벤트 생성하기", variant="primary")
|
612 |
-
|
613 |
-
with gr.Column():
|
614 |
-
with gr.Tabs():
|
615 |
-
with gr.Tab("📋 공지사항"):
|
616 |
-
event_result = gr.Textbox(
|
617 |
-
label="생성된 이벤트 공지사항",
|
618 |
-
lines=30,
|
619 |
-
interactive=False
|
620 |
-
)
|
621 |
-
|
622 |
-
with gr.Tab("🎨 디자인 가이드"):
|
623 |
-
design_result = gr.Textbox(
|
624 |
-
label="디자인 가이드",
|
625 |
-
lines=20,
|
626 |
-
interactive=False
|
627 |
-
)
|
628 |
-
|
629 |
-
with gr.Tab("🔗 API 연동"):
|
630 |
-
with gr.Row():
|
631 |
-
with gr.Column():
|
632 |
-
gr.Markdown("## 🌐 외부 API 설정")
|
633 |
-
|
634 |
-
with gr.Group():
|
635 |
-
gr.Markdown("### 📱 소셜미디어 API")
|
636 |
-
enable_instagram = gr.Checkbox(label="Instagram API 연동", value=False)
|
637 |
-
instagram_token = gr.Textbox(
|
638 |
-
label="Instagram Access Token",
|
639 |
-
type="password",
|
640 |
-
visible=False
|
641 |
-
)
|
642 |
-
|
643 |
-
with gr.Group():
|
644 |
-
gr.Markdown("### 📊 분석 & AI API")
|
645 |
-
enable_analytics = gr.Checkbox(label="Google Analytics", value=False)
|
646 |
-
ga_tracking_id = gr.Textbox(
|
647 |
-
label="GA Tracking ID",
|
648 |
-
visible=False
|
649 |
-
)
|
650 |
-
|
651 |
-
enable_chatgpt = gr.Checkbox(label="ChatGPT API (컨셉 생성)", value=False)
|
652 |
-
openai_api_key = gr.Textbox(
|
653 |
-
label="OpenAI API Key",
|
654 |
-
type="password",
|
655 |
-
visible=False
|
656 |
-
)
|
657 |
-
|
658 |
-
test_api_btn = gr.Button("🔍 API 연결 테스트", variant="secondary")
|
659 |
-
enhance_concept_btn = gr.Button("✨ AI로 컨셉 강화", variant="primary")
|
660 |
-
|
661 |
-
with gr.Column():
|
662 |
-
api_status = gr.Textbox(
|
663 |
-
label="API 연동 상태",
|
664 |
-
lines=15,
|
665 |
-
placeholder="API 설정 후 연결 테스트를 진행하세요"
|
666 |
-
)
|
667 |
-
|
668 |
-
ai_enhanced_result = gr.Textbox(
|
669 |
-
label="AI 강화 컨셉",
|
670 |
-
lines=15,
|
671 |
-
placeholder="ChatGPT API로 컨셉을 더욱 창의적으로 발전시킬 수 있습니다"
|
672 |
-
)
|
673 |
-
|
674 |
-
concepts_state = gr.State([])
|
675 |
-
|
676 |
-
def handle_period_change(period_text):
|
677 |
-
month = concept_analyzer.extract_month_from_period(period_text)
|
678 |
-
if month:
|
679 |
-
return gr.update(value=month)
|
680 |
-
return gr.update()
|
681 |
-
|
682 |
-
def handle_concept_analysis(month):
|
683 |
-
result, concepts = concept_analyzer.analyze_concepts(month)
|
684 |
-
return (
|
685 |
-
result,
|
686 |
-
gr.update(choices=concepts, visible=True, value=concepts[0] if concepts else ""),
|
687 |
-
gr.update(visible=True),
|
688 |
-
concepts
|
689 |
-
)
|
690 |
-
|
691 |
-
def handle_concept_selection(concept):
|
692 |
-
return gr.update(value=concept)
|
693 |
-
|
694 |
-
def handle_custom_concept_change(custom_concept):
|
695 |
-
return gr.update(value=custom_concept)
|
696 |
-
|
697 |
-
def update_reward_ui(reward_type):
|
698 |
-
return (
|
699 |
-
gr.update(visible=(reward_type == "단일 상품")),
|
700 |
-
gr.update(visible=(reward_type == "등급별 상품 (1,2,3등)")),
|
701 |
-
gr.update(visible=(reward_type == "선택형 상품")),
|
702 |
-
gr.update(visible=(reward_type == "직접 입력"))
|
703 |
-
)
|
704 |
-
|
705 |
-
def generate_event_template(start_date, end_date, concept, reward_type,
|
706 |
-
single_type, single_amount, single_frequency,
|
707 |
-
g1_amount, g1_count, g2_amount, g2_count, g3_amount, g3_count,
|
708 |
-
choice_amount, choice_frequency, custom_reward,
|
709 |
-
phone, kakao):
|
710 |
-
|
711 |
-
if reward_type == "단일 상품":
|
712 |
-
reward_structure = f"{single_type} {int(single_amount):,}원\n{single_frequency}"
|
713 |
-
elif reward_type == "등급별 상품 (1,2,3등)":
|
714 |
-
reward_structure = f"🥇 1등: {int(g1_amount):,}원 ({int(g1_count)}명)\n🥈 2등: {int(g2_amount):,}원 ({int(g2_count)}명)\n🥉 3등: {int(g3_amount):,}원 ({int(g3_count)}명)"
|
715 |
-
elif reward_type == "선택형 상품":
|
716 |
-
reward_structure = f"네이버페이 or 배달의민족 {int(choice_amount):,}원\n{choice_frequency}"
|
717 |
-
else:
|
718 |
-
reward_structure = custom_reward
|
719 |
-
|
720 |
-
# 컨셉에 따른 트렌디한 카피 생성
|
721 |
-
month = concept_month.value if hasattr(concept_month, 'value') else "8월"
|
722 |
-
copy_data = concept_analyzer.generate_trendy_copy(concept, month)
|
723 |
-
|
724 |
-
# 기본 이벤트 템플릿 생성
|
725 |
-
event_template = event_manager.generate_detailed_comment_event(
|
726 |
-
start_date, end_date, concept, reward_structure, kakao, phone
|
727 |
-
)
|
728 |
-
|
729 |
-
# 트렌디한 카피를 템플릿 상단에 추가
|
730 |
-
trendy_intro = f"""{copy_data['sub1']}
|
731 |
-
|
732 |
-
💫 {copy_data['main']} 💫
|
733 |
-
|
734 |
-
{copy_data['sub2']}
|
735 |
-
|
736 |
-
{' '.join(copy_data['hashtags'])}
|
737 |
-
|
738 |
-
---
|
739 |
-
|
740 |
-
"""
|
741 |
-
|
742 |
-
final_template = trendy_intro + event_template
|
743 |
-
|
744 |
-
# 디자인 가이드 생성
|
745 |
-
design_guide = event_manager.generate_design_advice(concept)
|
746 |
-
|
747 |
-
return final_template, design_guide
|
748 |
-
|
749 |
-
def toggle_api_inputs(instagram, analytics, chatgpt):
|
750 |
-
return (
|
751 |
-
gr.update(visible=instagram),
|
752 |
-
gr.update(visible=analytics),
|
753 |
-
gr.update(visible=chatgpt)
|
754 |
-
)
|
755 |
-
|
756 |
-
def test_api_connections(enable_instagram, instagram_token, enable_analytics, ga_tracking_id, enable_chatgpt, openai_api_key):
|
757 |
-
return api_integrations.test_all_connections(enable_instagram, instagram_token, enable_analytics, ga_tracking_id, enable_chatgpt, openai_api_key)
|
758 |
-
|
759 |
-
def enhance_with_ai(month, openai_key):
|
760 |
-
if not openai_key:
|
761 |
-
return "OpenAI API Key를 입력해주세요."
|
762 |
-
return api_integrations.generate_enhanced_concept_with_chatgpt(month, openai_key)
|
763 |
-
|
764 |
-
concept_event_period.change(
|
765 |
-
handle_period_change,
|
766 |
-
inputs=[concept_event_period],
|
767 |
-
outputs=[concept_month]
|
768 |
-
)
|
769 |
-
|
770 |
-
analyze_concept_btn.click(
|
771 |
-
handle_concept_analysis,
|
772 |
-
inputs=[concept_month],
|
773 |
-
outputs=[concept_result, selected_concept, custom_concept_input, concepts_state]
|
774 |
-
)
|
775 |
-
|
776 |
-
selected_concept.change(
|
777 |
-
handle_concept_selection,
|
778 |
-
inputs=[selected_concept],
|
779 |
-
outputs=[event_concept_input]
|
780 |
-
)
|
781 |
-
|
782 |
-
custom_concept_input.change(
|
783 |
-
handle_custom_concept_change,
|
784 |
-
inputs=[custom_concept_input],
|
785 |
-
outputs=[event_concept_input]
|
786 |
-
)
|
787 |
-
|
788 |
-
reward_type_selector.change(
|
789 |
-
update_reward_ui,
|
790 |
-
inputs=[reward_type_selector],
|
791 |
-
outputs=[single_group, grade_group, choice_group, custom_group]
|
792 |
-
)
|
793 |
-
|
794 |
-
generate_event_btn.click(
|
795 |
-
generate_event_template,
|
796 |
-
inputs=[
|
797 |
-
event_start_date, event_end_date, event_concept_input, reward_type_selector,
|
798 |
-
single_type, single_amount, single_frequency,
|
799 |
-
grade1_amount, grade1_count, grade2_amount, grade2_count, grade3_amount, grade3_count,
|
800 |
-
choice_amount, choice_frequency, custom_reward,
|
801 |
-
phone_number, kakao_id
|
802 |
-
],
|
803 |
-
outputs=[event_result, design_result]
|
804 |
-
)
|
805 |
-
|
806 |
-
for checkbox in [enable_instagram, enable_analytics, enable_chatgpt]:
|
807 |
-
checkbox.change(
|
808 |
-
toggle_api_inputs,
|
809 |
-
inputs=[enable_instagram, enable_analytics, enable_chatgpt],
|
810 |
-
outputs=[instagram_token, ga_tracking_id, openai_api_key]
|
811 |
-
)
|
812 |
-
|
813 |
-
test_api_btn.click(
|
814 |
-
test_api_connections,
|
815 |
-
inputs=[enable_instagram, instagram_token, enable_analytics, ga_tracking_id, enable_chatgpt, openai_api_key],
|
816 |
-
outputs=[api_status]
|
817 |
-
)
|
818 |
-
|
819 |
-
enhance_concept_btn.click(
|
820 |
-
enhance_with_ai,
|
821 |
-
inputs=[concept_month, openai_api_key],
|
822 |
-
outputs=[ai_enhanced_result]
|
823 |
-
)
|
824 |
-
|
825 |
-
return demo
|
826 |
-
|
827 |
-
if __name__ == "__main__":
|
828 |
-
demo = create_interface()
|
829 |
-
demo.launch()
|
|
|
131 |
trends = data.get("trends", [])
|
132 |
female_appeal = data.get("female_appeal", [])
|
133 |
|
134 |
+
for i in range(min(10, len
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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