Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,8 +14,25 @@ openai.api_key = os.getenv("OPENAI_API_KEY")
|
|
| 14 |
|
| 15 |
# λ¬Έμ₯ κ΅¬λΆ ν¨μ
|
| 16 |
def split_sentences(text):
|
| 17 |
-
sentences = re.split(r
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
def parse_api_response(response):
|
| 21 |
try:
|
|
@@ -99,13 +116,15 @@ def analyze(url, progress=gr.Progress()):
|
|
| 99 |
|
| 100 |
progress(33, desc="μλ¬Έ μ€ν¬λ¦½νΈ μ²λ¦¬ μ€...")
|
| 101 |
script_sentences = split_sentences(script)
|
| 102 |
-
script_content = f"# {title}\n\n" + "\n".join(
|
| 103 |
|
| 104 |
-
progress(
|
| 105 |
summary = summarize_text(title, description, script)
|
|
|
|
|
|
|
| 106 |
summary_content = f"# {title}\n\n{summary}"
|
| 107 |
|
| 108 |
-
progress(
|
| 109 |
return script_content, summary_content
|
| 110 |
except Exception as e:
|
| 111 |
error_msg = f"μ²λ¦¬ μ€ μ€λ₯ λ°μ: {str(e)}"
|
|
|
|
| 14 |
|
| 15 |
# λ¬Έμ₯ κ΅¬λΆ ν¨μ
|
| 16 |
def split_sentences(text):
|
| 17 |
+
sentences = re.split(r"(λλ€|μμ|ꡬλ|ν΄μ|κ΅°μ|κ² μ΄μ|μμ€|ν΄λΌ|μμ|μμ|λ°μ|λμ|μΈμ|μ΄μ|κ²μ|ꡬμ|κ³ μ|λμ|νμ£ )(?![\w])", text)
|
| 18 |
+
combined_sentences = []
|
| 19 |
+
current_sentence = ""
|
| 20 |
+
for i in range(0, len(sentences), 2):
|
| 21 |
+
if i + 1 < len(sentences):
|
| 22 |
+
sentence = sentences[i] + sentences[i + 1]
|
| 23 |
+
else:
|
| 24 |
+
sentence = sentences[i]
|
| 25 |
+
if len(current_sentence) + len(sentence) > 100: # 100μλ₯Ό μ΄κ³Όν κ²½μ°
|
| 26 |
+
combined_sentences.append(current_sentence.strip())
|
| 27 |
+
current_sentence = sentence.strip()
|
| 28 |
+
else:
|
| 29 |
+
current_sentence += sentence
|
| 30 |
+
if sentence.endswith(('.', '?', '!')):
|
| 31 |
+
combined_sentences.append(current_sentence.strip())
|
| 32 |
+
current_sentence = ""
|
| 33 |
+
if current_sentence:
|
| 34 |
+
combined_sentences.append(current_sentence.strip())
|
| 35 |
+
return combined_sentences
|
| 36 |
|
| 37 |
def parse_api_response(response):
|
| 38 |
try:
|
|
|
|
| 116 |
|
| 117 |
progress(33, desc="μλ¬Έ μ€ν¬λ¦½νΈ μ²λ¦¬ μ€...")
|
| 118 |
script_sentences = split_sentences(script)
|
| 119 |
+
script_content = f"# {title}\n\n" + "\n".join(script_sentences)
|
| 120 |
|
| 121 |
+
progress(66, desc="μμ½ μμ± μ€...")
|
| 122 |
summary = summarize_text(title, description, script)
|
| 123 |
+
|
| 124 |
+
progress(88, desc="μμ½ λ΄μ© μ 리 μ€...")
|
| 125 |
summary_content = f"# {title}\n\n{summary}"
|
| 126 |
|
| 127 |
+
progress(100, desc="μλ£")
|
| 128 |
return script_content, summary_content
|
| 129 |
except Exception as e:
|
| 130 |
error_msg = f"μ²λ¦¬ μ€ μ€λ₯ λ°μ: {str(e)}"
|