openfree commited on
Commit
2f8cbca
Β·
verified Β·
1 Parent(s): e738762

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -57
app.py CHANGED
@@ -954,8 +954,8 @@ def analyze_single_space(space: dict, source_code: str) -> str:
954
 
955
 
956
 
957
- def create_editable_space_analysis(progress=gr.Progress()) -> Tuple[str, str]:
958
- """νŽΈμ§‘ κ°€λŠ₯ν•œ 24개 슀페이슀 뢄석"""
959
  try:
960
  progress(0, desc="슀페이슀 데이터 κ°€μ Έμ˜€λŠ” 쀑...")
961
 
@@ -963,66 +963,51 @@ def create_editable_space_analysis(progress=gr.Progress()) -> Tuple[str, str]:
963
  response = requests.get(url, params={'full': 'true', 'limit': 24})
964
  response.raise_for_status()
965
  spaces = response.json()[:24]
966
-
967
- html_content = """
968
- <div style='padding: 20px; background: #ffffff;'>
969
- <!-- 인트둜 ν…μŠ€νŠΈ λ°•μŠ€ -->
970
- <div style='margin-bottom: 30px;'>
971
- <textarea id='intro_text' class='editable-text' rows='4' style='
972
- width: 100%;
973
- padding: 15px;
974
- border: 1px solid #ddd;
975
- border-radius: 10px;
976
- font-size: 1.1em;
977
- line-height: 1.5;
978
- resize: vertical;
979
- background: #f8f9fa;
980
- '>μ•ˆλ…•ν•˜μ„Έμš”. 맀일 κΈ€λ‘œλ²Œ μ΅œμ‹  AI 인기 νŠΈλ Œλ“œ μ„œλΉ„μŠ€λ₯Ό μ•Œμ•„λ³΄λŠ” '데일리 AI νŠΈλ Œλ”©' λ‰΄μŠ€μž…λ‹ˆλ‹€. 였늘의 ν—ˆκΉ…νŽ˜μ΄μŠ€ 인기 μˆœμœ„ 1μœ„λΆ€ν„° 24μœ„κΉŒμ§€, 뢄석과 핡심 λ‚΄μš©μ„ μ‚΄νŽ΄λ³΄κ² μŠ΅λ‹ˆλ‹€.</textarea>
981
- </div>
982
- """
983
 
984
- # 각 μŠ€νŽ˜μ΄μŠ€λ³„ νŽΈμ§‘ κ°€λŠ₯ν•œ ν…μŠ€νŠΈ λ°•μŠ€ 생성
 
985
  for idx, space in enumerate(spaces):
986
- project_name = space['id'].split('/')[-1]
987
- default_text = f"였늘의 μΈκΈ°μˆœμœ„ {idx + 1}μœ„μΈ {project_name}μž…λ‹ˆλ‹€. "
988
-
989
- html_content += f"""
990
- <div class='script-card' style='margin-bottom: 20px;'>
991
- <textarea id='space_text_{idx}' class='editable-text' rows='3' style='
992
- width: 100%;
993
- padding: 15px;
994
- border: 1px solid #ddd;
995
- border-radius: 10px;
996
- font-size: 1em;
997
- line-height: 1.5;
998
- resize: vertical;
999
- background: #fff;
1000
- '>{default_text}</textarea>
1001
- </div>
1002
- """
1003
 
1004
- # 생성 λ²„νŠΌ μΆ”κ°€
1005
- html_content += """
1006
- <div style='text-align: center; margin-top: 30px;'>
1007
- <button id='generate_video' onclick='generateVideo()' style='
1008
- padding: 15px 40px;
1009
- font-size: 1.2em;
1010
- background: linear-gradient(135deg, #7b61ff, #6366f1);
1011
- color: white;
1012
- border: none;
1013
- border-radius: 10px;
1014
- cursor: pointer;
1015
- transition: all 0.3s ease;
1016
- '>μ˜μƒ 생성</button>
1017
- </div>
1018
- </div>
1019
- """
 
 
 
 
 
1020
 
1021
- return html_content, "νŽΈμ§‘ κ°€λŠ₯ν•œ 24개 슀페이슀 뢄석 μ€€λΉ„ μ™„λ£Œ"
1022
 
1023
  except Exception as e:
1024
- error_msg = f"Error: {str(e)}"
1025
- return f"<div style='color: red; padding: 20px;'>{error_msg}</div>", error_msg
 
1026
 
1027
  def generate_video(texts: List[str], progress=gr.Progress()) -> str:
1028
  """μ˜μƒ 생성"""
@@ -1241,7 +1226,12 @@ def create_interface():
1241
  video_output = gr.Video(label="μƒμ„±λœ μ˜μƒ")
1242
 
1243
  def on_analyze(progress=gr.Progress()):
1244
- return create_editable_space_analysis(progress)
 
 
 
 
 
1245
 
1246
  def on_generate_video(intro, *texts, progress=gr.Progress()):
1247
  all_texts = [intro] + list(texts)
 
954
 
955
 
956
 
957
+ def create_editable_space_analysis(progress=gr.Progress()) -> List[str]:
958
+ """24개 슀페이슀 뢄석 ν…μŠ€νŠΈ 생성"""
959
  try:
960
  progress(0, desc="슀페이슀 데이터 κ°€μ Έμ˜€λŠ” 쀑...")
961
 
 
963
  response = requests.get(url, params={'full': 'true', 'limit': 24})
964
  response.raise_for_status()
965
  spaces = response.json()[:24]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
966
 
967
+ analysis_texts = []
968
+
969
  for idx, space in enumerate(spaces):
970
+ progress((idx + 1) / 24, desc=f"뢄석 쀑... {idx+1}/24")
971
+ try:
972
+ source = get_space_source(space['id'])
973
+ source_code = source["app.py"] or source["index.html"]
974
+
975
+ # ν”„λ‘œμ νŠΈλͺ…λ§Œ μΆ”μΆœ
976
+ project_name = space['id'].split('/')[-1]
977
+
978
+ prompt = f"""
979
+ λ‹€μŒ HuggingFace 슀페이슀λ₯Ό λΆ„μ„ν•˜μ—¬ λ‰΄μŠ€ 리포트 ν˜•μ‹μœΌλ‘œ μ„€λͺ…ν•΄μ£Όμ„Έμš”:
980
+ μ‹œμž‘μ€ λ°˜λ“œμ‹œ "였늘의 μΈκΈ°μˆœμœ„ {idx + 1}μœ„μΈ {project_name}μž…λ‹ˆλ‹€."둜 μ‹œμž‘ν•˜κ³ ,
981
+ μ΄μ–΄μ„œ μ£Όμš” κΈ°λŠ₯, νŠΉμ§•, ν™œμš©λ°©μ•ˆμ„ μžμ—°μŠ€λŸ½κ²Œ μ„€λͺ…ν•΄μ£Όμ„Έμš”.
 
 
 
 
 
982
 
983
+ μ†ŒμŠ€μ½”λ“œ:
984
+ ```
985
+ {source_code[:1500]}
986
+ ```
987
+ """
988
+
989
+ messages = [
990
+ {"role": "system", "content": "AI 기술 μ „λ¬Έ λ‰΄μŠ€ λ¦¬ν¬ν„°μž…λ‹ˆλ‹€."},
991
+ {"role": "user", "content": prompt}
992
+ ]
993
+
994
+ response = hf_client.chat_completion(
995
+ messages,
996
+ max_tokens=200,
997
+ temperature=0.7
998
+ )
999
+
1000
+ analysis_texts.append(response.choices[0].message.content.strip())
1001
+
1002
+ except Exception as e:
1003
+ analysis_texts.append(f"였늘의 μΈκΈ°μˆœμœ„ {idx + 1}μœ„μΈ {project_name}μž…λ‹ˆλ‹€.")
1004
 
1005
+ return analysis_texts
1006
 
1007
  except Exception as e:
1008
+ return [f"μˆœμœ„ {i+1}μœ„ 뢄석을 μ€€λΉ„μ€‘μž…λ‹ˆλ‹€." for i in range(24)]
1009
+
1010
+
1011
 
1012
  def generate_video(texts: List[str], progress=gr.Progress()) -> str:
1013
  """μ˜μƒ 생성"""
 
1226
  video_output = gr.Video(label="μƒμ„±λœ μ˜μƒ")
1227
 
1228
  def on_analyze(progress=gr.Progress()):
1229
+ """뢄석 μ‹€ν–‰ 및 ν…μŠ€νŠΈλ°•μŠ€ μ—…λ°μ΄νŠΈ"""
1230
+ texts = create_editable_space_analysis(progress)
1231
+ # μ •ν™•νžˆ 24개의 값을 λ°˜ν™˜
1232
+ if len(texts) < 24:
1233
+ texts.extend(["뢄석 쀀비쀑..." for _ in range(24 - len(texts))])
1234
+ return texts[:24] # μ •ν™•νžˆ 24개 λ°˜ν™˜
1235
 
1236
  def on_generate_video(intro, *texts, progress=gr.Progress()):
1237
  all_texts = [intro] + list(texts)