Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -87,20 +87,45 @@ def summarize_text(title, description, text):
|
|
87 |
"""
|
88 |
return call_api(prompt, max_tokens=8000, temperature=0.35, top_p=0.95)
|
89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
def analyze(url, progress=gr.Progress()):
|
91 |
try:
|
92 |
progress(0, desc="์คํฌ๋ฆฝํธ ์ถ์ถ ์ค...")
|
93 |
title, description, script = get_youtube_script(url)
|
94 |
|
95 |
progress(0.25, desc="์๋ฌธ ์คํฌ๋ฆฝํธ ์ฒ๋ฆฌ ์ค...")
|
96 |
-
|
97 |
-
script_content = f"# {title}\n\n" + "\n".join(script_sentences)
|
98 |
|
99 |
# ์๋ฌธ ์คํฌ๋ฆฝํธ ๋จผ์ ์ถ๋ ฅํ๊ณ ์งํ
|
100 |
yield script_content, "์์ฝ ์ค๋น ์ค..."
|
101 |
|
102 |
progress(0.5, desc="์์ฝ ์์ฑ ์ค...")
|
103 |
-
summary = summarize_text(title, description,
|
104 |
|
105 |
progress(0.75, desc="์์ฝ ๋ด์ฉ ์ ๋ฆฌ ์ค...")
|
106 |
summary_content = f"# {title}\n\n{summary}"
|
@@ -112,34 +137,6 @@ def analyze(url, progress=gr.Progress()):
|
|
112 |
logging.exception(error_msg)
|
113 |
yield error_msg, error_msg
|
114 |
|
115 |
-
def split_sentences(text):
|
116 |
-
sentence_end = r'(๋๋ค|์์|๊ตฌ๋|ํด์|๊ตฐ์|๊ฒ ์ด์|์์ค|ํด๋ผ|์์|์์|๋ฐ์|๋์|์ธ์|์ด์|๊ฒ์|๊ตฌ์|๊ณ ์|๋์|ํ์ฃ )(?![\w])'
|
117 |
-
segments = re.split(f'({sentence_end})', text)
|
118 |
-
|
119 |
-
combined_sentences = []
|
120 |
-
current_sentence = ""
|
121 |
-
|
122 |
-
for i in range(0, len(segments), 2):
|
123 |
-
segment = segments[i]
|
124 |
-
if i + 1 < len(segments):
|
125 |
-
segment += segments[i + 1]
|
126 |
-
|
127 |
-
if len(current_sentence) + len(segment) > 100:
|
128 |
-
if current_sentence:
|
129 |
-
combined_sentences.append(current_sentence.strip())
|
130 |
-
current_sentence = segment.strip()
|
131 |
-
else:
|
132 |
-
current_sentence += (' ' if current_sentence else '') + segment.strip()
|
133 |
-
|
134 |
-
if re.search(sentence_end, segment):
|
135 |
-
combined_sentences.append(current_sentence.strip())
|
136 |
-
current_sentence = ""
|
137 |
-
|
138 |
-
if current_sentence:
|
139 |
-
combined_sentences.append(current_sentence.strip())
|
140 |
-
|
141 |
-
return combined_sentences
|
142 |
-
|
143 |
# Gradio ์ธํฐํ์ด์ค
|
144 |
with gr.Blocks() as demo:
|
145 |
gr.Markdown("## YouTube ์คํฌ๋ฆฝํธ ์ถ์ถ ๋ฐ ์์ฝ ๋๊ตฌ")
|
|
|
87 |
"""
|
88 |
return call_api(prompt, max_tokens=8000, temperature=0.35, top_p=0.95)
|
89 |
|
90 |
+
def split_sentences(text):
|
91 |
+
sentences = re.split(r"(๋๋ค|์์|๊ตฌ๋|ํด์|๊ตฐ์|๊ฒ ์ด์|์์ค|ํด๋ผ|์์|์์|๋ฐ์|๋์|์ธ์|์ด์|๊ฒ์|๊ตฌ์|๊ณ ์|๋์|ํ์ฃ )(?![\w])", text)
|
92 |
+
combined_sentences = []
|
93 |
+
current_sentence = ""
|
94 |
+
for i in range(0, len(sentences), 2):
|
95 |
+
if i + 1 < len(sentences):
|
96 |
+
sentence = sentences[i] + sentences[i + 1]
|
97 |
+
else:
|
98 |
+
sentence = sentences[i]
|
99 |
+
if len(current_sentence) + len(sentence) > 100: # 100์๋ฅผ ์ด๊ณผํ ๊ฒฝ์ฐ
|
100 |
+
combined_sentences.append(current_sentence.strip())
|
101 |
+
current_sentence = sentence.strip()
|
102 |
+
else:
|
103 |
+
current_sentence += sentence
|
104 |
+
if sentence.endswith(('.', '?', '!')):
|
105 |
+
combined_sentences.append(current_sentence.strip())
|
106 |
+
current_sentence = ""
|
107 |
+
if current_sentence:
|
108 |
+
combined_sentences.append(current_sentence.strip())
|
109 |
+
return combined_sentences
|
110 |
+
|
111 |
+
def display_script(title, script):
|
112 |
+
script_sentences = split_sentences(script)
|
113 |
+
formatted_script = "\n\n".join(script_sentences)
|
114 |
+
return f"# {title}\n\n{formatted_script}"
|
115 |
+
|
116 |
def analyze(url, progress=gr.Progress()):
|
117 |
try:
|
118 |
progress(0, desc="์คํฌ๋ฆฝํธ ์ถ์ถ ์ค...")
|
119 |
title, description, script = get_youtube_script(url)
|
120 |
|
121 |
progress(0.25, desc="์๋ฌธ ์คํฌ๋ฆฝํธ ์ฒ๋ฆฌ ์ค...")
|
122 |
+
script_content = display_script(title, script)
|
|
|
123 |
|
124 |
# ์๋ฌธ ์คํฌ๋ฆฝํธ ๋จผ์ ์ถ๋ ฅํ๊ณ ์งํ
|
125 |
yield script_content, "์์ฝ ์ค๋น ์ค..."
|
126 |
|
127 |
progress(0.5, desc="์์ฝ ์์ฑ ์ค...")
|
128 |
+
summary = summarize_text(title, description, script)
|
129 |
|
130 |
progress(0.75, desc="์์ฝ ๋ด์ฉ ์ ๋ฆฌ ์ค...")
|
131 |
summary_content = f"# {title}\n\n{summary}"
|
|
|
137 |
logging.exception(error_msg)
|
138 |
yield error_msg, error_msg
|
139 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
140 |
# Gradio ์ธํฐํ์ด์ค
|
141 |
with gr.Blocks() as demo:
|
142 |
gr.Markdown("## YouTube ์คํฌ๋ฆฝํธ ์ถ์ถ ๋ฐ ์์ฝ ๋๊ตฌ")
|