Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -14,24 +14,32 @@ openai.api_key = os.getenv("OPENAI_API_KEY")
|
|
14 |
|
15 |
# λ¬Έμ₯ κ΅¬λΆ ν¨μ
|
16 |
def split_sentences(text):
|
17 |
-
|
|
|
|
|
|
|
18 |
combined_sentences = []
|
19 |
current_sentence = ""
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
current_sentence
|
|
|
|
|
28 |
else:
|
29 |
-
current_sentence +=
|
30 |
-
|
|
|
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):
|
@@ -114,17 +122,17 @@ def analyze(url, progress=gr.Progress()):
|
|
114 |
progress(0, desc="μ€ν¬λ¦½νΈ μΆμΆ μ€...")
|
115 |
title, description, script = get_youtube_script(url)
|
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(
|
128 |
return script_content, summary_content
|
129 |
except Exception as e:
|
130 |
error_msg = f"μ²λ¦¬ μ€ μ€λ₯ λ°μ: {str(e)}"
|
|
|
14 |
|
15 |
# λ¬Έμ₯ κ΅¬λΆ ν¨μ
|
16 |
def split_sentences(text):
|
17 |
+
# μ£Όμ΄μ§ κ΅¬λΆ κΈ°μ€μ μ¬μ©ν μ κ· ννμ
|
18 |
+
sentence_end = r'(λλ€|μμ|ꡬλ|ν΄μ|κ΅°μ|κ² μ΄μ|μμ€|ν΄λΌ|μμ|μμ|λ°μ|λμ|μΈμ|μ΄μ|κ²μ|ꡬμ|κ³ μ|λμ|νμ£ )(?![\w])'
|
19 |
+
segments = re.split(f'({sentence_end})', text)
|
20 |
+
|
21 |
combined_sentences = []
|
22 |
current_sentence = ""
|
23 |
+
|
24 |
+
for i in range(0, len(segments), 2):
|
25 |
+
segment = segments[i]
|
26 |
+
if i + 1 < len(segments):
|
27 |
+
segment += segments[i + 1]
|
28 |
+
|
29 |
+
if len(current_sentence) + len(segment) > 100:
|
30 |
+
if current_sentence:
|
31 |
+
combined_sentences.append(current_sentence.strip())
|
32 |
+
current_sentence = segment.strip()
|
33 |
else:
|
34 |
+
current_sentence += (' ' if current_sentence else '') + segment.strip()
|
35 |
+
|
36 |
+
if re.search(sentence_end, segment):
|
37 |
combined_sentences.append(current_sentence.strip())
|
38 |
current_sentence = ""
|
39 |
+
|
40 |
if current_sentence:
|
41 |
combined_sentences.append(current_sentence.strip())
|
42 |
+
|
43 |
return combined_sentences
|
44 |
|
45 |
def parse_api_response(response):
|
|
|
122 |
progress(0, desc="μ€ν¬λ¦½νΈ μΆμΆ μ€...")
|
123 |
title, description, script = get_youtube_script(url)
|
124 |
|
125 |
+
progress(0.33, desc="μλ¬Έ μ€ν¬λ¦½νΈ μ²λ¦¬ μ€...")
|
126 |
script_sentences = split_sentences(script)
|
127 |
script_content = f"# {title}\n\n" + "\n".join(script_sentences)
|
128 |
|
129 |
+
progress(0.66, desc="μμ½ μμ± μ€...")
|
130 |
summary = summarize_text(title, description, script)
|
131 |
|
132 |
+
progress(0.88, desc="μμ½ λ΄μ© μ 리 μ€...")
|
133 |
summary_content = f"# {title}\n\n{summary}"
|
134 |
|
135 |
+
progress(1.0, desc="μλ£")
|
136 |
return script_content, summary_content
|
137 |
except Exception as e:
|
138 |
error_msg = f"μ²λ¦¬ μ€ μ€λ₯ λ°μ: {str(e)}"
|