Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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()) ->
|
958 |
-
"""
|
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 |
-
|
987 |
-
|
988 |
-
|
989 |
-
|
990 |
-
|
991 |
-
|
992 |
-
|
993 |
-
|
994 |
-
|
995 |
-
|
996 |
-
|
997 |
-
|
998 |
-
resize: vertical;
|
999 |
-
background: #fff;
|
1000 |
-
'>{default_text}</textarea>
|
1001 |
-
</div>
|
1002 |
-
"""
|
1003 |
|
1004 |
-
|
1005 |
-
|
1006 |
-
|
1007 |
-
|
1008 |
-
|
1009 |
-
|
1010 |
-
|
1011 |
-
|
1012 |
-
|
1013 |
-
|
1014 |
-
|
1015 |
-
|
1016 |
-
|
1017 |
-
|
1018 |
-
|
1019 |
-
|
|
|
|
|
|
|
|
|
|
|
1020 |
|
1021 |
-
return
|
1022 |
|
1023 |
except Exception as e:
|
1024 |
-
|
1025 |
-
|
|
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
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)
|