Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import logging
|
|
| 5 |
import openai
|
| 6 |
import os
|
| 7 |
import re
|
|
|
|
| 8 |
|
| 9 |
# λ‘κΉ
μ€μ
|
| 10 |
logging.basicConfig(filename='youtube_script_extractor.log', level=logging.DEBUG,
|
|
@@ -86,12 +87,13 @@ def summarize_text(title, description, text):
|
|
| 86 |
[μμ]
|
| 87 |
(λ³κ²½μ )
|
| 88 |
- μ νλΈλ₯Ό μ²μ μμνλ μ¬λλ€μ ꡬλ
μ μμ μ‘°νμμ ν° κ΄μ¬μ λκ³ λ§€μΌ μ νλΈ μ€νλμ€λ₯Ό νμΈνκ² λλ€. κ·Έλ¬λ ꡬλ
μκ° 100λͺ
, 1,000λͺ
μ λλ¬νλ κ²λ§μΌλ‘λ μ§μμ μΈ μ±μ₯μ λμμ΄ λμ§ μλλ€. ꡬλ
μ μκ° λμ΄λ νμλ μ νλΈ μ±λ μ΄μμ λν κ°μ μ‘μ§ λͺ»ν΄ ν¬κΈ°νλ κ²½μ°κ° λ§λ€.
|
| 89 |
-
|
| 90 |
(λ³κ²½ν)
|
| 91 |
- μ νλΈλ₯Ό μ²μ μμνλ μ¬λλ€μ ꡬλ
μ μμ μ‘°νμμ ν° κ΄μ¬μ λκ³ λ§€μΌ μ νλΈ μ€νλμ€λ₯Ό νμΈνκ² λλ€.
|
| 92 |
- κ·Έλ¬λ ꡬλ
μκ° 100λͺ
, 1,000λͺ
μ λλ¬νλ κ²λ§μΌλ‘λ μ§μμ μΈ μ±μ₯μ λμμ΄ λμ§ μλλ€.
|
| 93 |
- ꡬλ
μ μκ° λμ΄λ νμλ μ νλΈ μ±λ μ΄μμ λν κ°μ μ‘μ§ λͺ»ν΄ ν¬κΈ°νλ κ²½μ°κ° λ§λ€.
|
| 94 |
-
17. λ°λμ **κ° λ¬Έμ₯μμ ν΅μ¬ λΆλΆμ
|
|
|
|
|
|
|
| 95 |
|
| 96 |
μ λͺ©: {title}
|
| 97 |
μ€λͺ
: {description}
|
|
@@ -153,27 +155,45 @@ def analyze(url):
|
|
| 153 |
# μμ½ μμ±
|
| 154 |
summary = summarize_text(title, description, script)
|
| 155 |
|
| 156 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
lines = summary.split('\n')
|
| 158 |
formatted_lines = []
|
| 159 |
for line in lines:
|
| 160 |
if line.startswith('# '):
|
| 161 |
-
line = f"<h1>{line[2:]}</h1>"
|
| 162 |
elif line.startswith('## '):
|
| 163 |
-
line = f"<h2>{line[3:]}</h2>"
|
| 164 |
elif line.startswith('### '):
|
| 165 |
-
line = f"<h3>{line[4:]}</h3>"
|
| 166 |
else:
|
| 167 |
-
|
| 168 |
-
line = line.replace('[[', '<span style="background-color: #FFDAB9; font-weight: bold;">').replace(']]', '</span>')
|
| 169 |
-
line = f"<p>{line}</p>"
|
| 170 |
formatted_lines.append(line)
|
| 171 |
|
| 172 |
formatted_summary = '\n'.join(formatted_lines)
|
| 173 |
|
| 174 |
summary_content = f"""<div style="background-color: #e6f3ff; padding: 20px; border-radius: 10px; margin-top: 20px;">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
<h3>μμ½</h3>
|
| 176 |
-
<h2>{title}</h2>
|
| 177 |
{formatted_summary}
|
| 178 |
</div>"""
|
| 179 |
|
|
|
|
| 5 |
import openai
|
| 6 |
import os
|
| 7 |
import re
|
| 8 |
+
import html
|
| 9 |
|
| 10 |
# λ‘κΉ
μ€μ
|
| 11 |
logging.basicConfig(filename='youtube_script_extractor.log', level=logging.DEBUG,
|
|
|
|
| 87 |
[μμ]
|
| 88 |
(λ³κ²½μ )
|
| 89 |
- μ νλΈλ₯Ό μ²μ μμνλ μ¬λλ€μ ꡬλ
μ μμ μ‘°νμμ ν° κ΄μ¬μ λκ³ λ§€μΌ μ νλΈ μ€νλμ€λ₯Ό νμΈνκ² λλ€. κ·Έλ¬λ ꡬλ
μκ° 100λͺ
, 1,000λͺ
μ λλ¬νλ κ²λ§μΌλ‘λ μ§μμ μΈ μ±μ₯μ λμμ΄ λμ§ μλλ€. ꡬλ
μ μκ° λμ΄λ νμλ μ νλΈ μ±λ μ΄μμ λν κ°μ μ‘μ§ λͺ»ν΄ ν¬κΈ°νλ κ²½μ°κ° λ§λ€.
|
|
|
|
| 90 |
(λ³κ²½ν)
|
| 91 |
- μ νλΈλ₯Ό μ²μ μμνλ μ¬λλ€μ ꡬλ
μ μμ μ‘°νμμ ν° κ΄μ¬μ λκ³ λ§€μΌ μ νλΈ μ€νλμ€λ₯Ό νμΈνκ² λλ€.
|
| 92 |
- κ·Έλ¬λ ꡬλ
μκ° 100λͺ
, 1,000λͺ
μ λλ¬νλ κ²λ§μΌλ‘λ μ§μμ μΈ μ±μ₯μ λμμ΄ λμ§ μλλ€.
|
| 93 |
- ꡬλ
μ μκ° λμ΄λ νμλ μ νλΈ μ±λ μ΄μμ λν κ°μ μ‘μ§ λͺ»ν΄ ν¬κΈ°νλ κ²½μ°κ° λ§λ€.
|
| 94 |
+
17. λ°λμ **κ° λ¬Έμ₯μμ ν΅μ¬ λΆλΆμ <highlight>μ€μ λ΄μ©</highlight> ννλ‘ νμνλΌ**
|
| 95 |
+
[μμ]
|
| 96 |
+
- μΉ΄λ©λΌλ [[2μ΅ νμ]]κ° νμ¬λ κ°λ₯μ±μ΄ μμΌλ©°, κ°κ²©μ [[μ½ 280λ§μ]]μΌλ‘ μμλλ€.
|
| 97 |
|
| 98 |
μ λͺ©: {title}
|
| 99 |
μ€λͺ
: {description}
|
|
|
|
| 155 |
# μμ½ μμ±
|
| 156 |
summary = summarize_text(title, description, script)
|
| 157 |
|
| 158 |
+
# HTML λ³ν λ° μ΄μ€μΌμ΄ν μ²λ¦¬
|
| 159 |
+
def escape_html_except_highlights(text):
|
| 160 |
+
parts = text.split('<highlight>')
|
| 161 |
+
escaped_parts = []
|
| 162 |
+
for i, part in enumerate(parts):
|
| 163 |
+
if i % 2 == 0: # νμ΄λΌμ΄νΈ νκ·Έ μΈλΆ
|
| 164 |
+
escaped_parts.append(html.escape(part))
|
| 165 |
+
else: # νμ΄λΌμ΄νΈ νκ·Έ λ΄λΆ
|
| 166 |
+
highlight_parts = part.split('</highlight>')
|
| 167 |
+
if len(highlight_parts) > 1:
|
| 168 |
+
escaped_parts.append(f'<span class="highlight">{html.escape(highlight_parts[0])}</span>{html.escape(highlight_parts[1])}')
|
| 169 |
+
else:
|
| 170 |
+
escaped_parts.append(html.escape(part))
|
| 171 |
+
return ''.join(escaped_parts)
|
| 172 |
+
|
| 173 |
lines = summary.split('\n')
|
| 174 |
formatted_lines = []
|
| 175 |
for line in lines:
|
| 176 |
if line.startswith('# '):
|
| 177 |
+
line = f"<h1>{escape_html_except_highlights(line[2:])}</h1>"
|
| 178 |
elif line.startswith('## '):
|
| 179 |
+
line = f"<h2>{escape_html_except_highlights(line[3:])}</h2>"
|
| 180 |
elif line.startswith('### '):
|
| 181 |
+
line = f"<h3>{escape_html_except_highlights(line[4:])}</h3>"
|
| 182 |
else:
|
| 183 |
+
line = f"<p>{escape_html_except_highlights(line)}</p>"
|
|
|
|
|
|
|
| 184 |
formatted_lines.append(line)
|
| 185 |
|
| 186 |
formatted_summary = '\n'.join(formatted_lines)
|
| 187 |
|
| 188 |
summary_content = f"""<div style="background-color: #e6f3ff; padding: 20px; border-radius: 10px; margin-top: 20px;">
|
| 189 |
+
<style>
|
| 190 |
+
.highlight {{
|
| 191 |
+
background-color: #FFDAB9;
|
| 192 |
+
font-weight: bold;
|
| 193 |
+
}}
|
| 194 |
+
</style>
|
| 195 |
<h3>μμ½</h3>
|
| 196 |
+
<h2>{html.escape(title)}</h2>
|
| 197 |
{formatted_summary}
|
| 198 |
</div>"""
|
| 199 |
|