Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,25 +14,8 @@ openai.api_key = os.getenv("OPENAI_API_KEY")
|
|
| 14 |
|
| 15 |
# ๋ฌธ์ฅ ๊ตฌ๋ถ ํจ์
|
| 16 |
def split_sentences(text):
|
| 17 |
-
sentences = re.split(r
|
| 18 |
-
|
| 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,17 +99,18 @@ def analyze(url, progress=gr.Progress()):
|
|
| 116 |
|
| 117 |
progress(33, desc="์๋ฌธ ์คํฌ๋ฆฝํธ ์ฒ๋ฆฌ ์ค...")
|
| 118 |
script_sentences = split_sentences(script)
|
| 119 |
-
script_content = "\n".join(script_sentences)
|
| 120 |
|
| 121 |
progress(66, desc="์์ฝ ์์ฑ ์ค...")
|
| 122 |
summary = summarize_text(title, description, script)
|
|
|
|
| 123 |
|
| 124 |
progress(100, desc="์๋ฃ")
|
| 125 |
-
return
|
| 126 |
except Exception as e:
|
| 127 |
error_msg = f"์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
| 128 |
logging.exception(error_msg)
|
| 129 |
-
return
|
| 130 |
|
| 131 |
# Gradio ์ธํฐํ์ด์ค
|
| 132 |
with gr.Blocks() as demo:
|
|
@@ -134,8 +118,6 @@ with gr.Blocks() as demo:
|
|
| 134 |
youtube_url_input = gr.Textbox(label="YouTube URL ์
๋ ฅ")
|
| 135 |
analyze_button = gr.Button("๋ถ์ํ๊ธฐ")
|
| 136 |
|
| 137 |
-
title_output = gr.Textbox(label="์์ ์ ๋ชฉ")
|
| 138 |
-
|
| 139 |
with gr.Tabs():
|
| 140 |
with gr.TabItem("์๋ฌธ ์คํฌ๋ฆฝํธ"):
|
| 141 |
script_output = gr.Markdown()
|
|
@@ -145,7 +127,7 @@ with gr.Blocks() as demo:
|
|
| 145 |
analyze_button.click(
|
| 146 |
analyze,
|
| 147 |
inputs=[youtube_url_input],
|
| 148 |
-
outputs=[
|
| 149 |
)
|
| 150 |
|
| 151 |
if __name__ == "__main__":
|
|
|
|
| 14 |
|
| 15 |
# ๋ฌธ์ฅ ๊ตฌ๋ถ ํจ์
|
| 16 |
def split_sentences(text):
|
| 17 |
+
sentences = re.split(r'([.!?]+)\s*', text)
|
| 18 |
+
return ''.join(sentences).split()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
def parse_api_response(response):
|
| 21 |
try:
|
|
|
|
| 99 |
|
| 100 |
progress(33, desc="์๋ฌธ ์คํฌ๋ฆฝํธ ์ฒ๋ฆฌ ์ค...")
|
| 101 |
script_sentences = split_sentences(script)
|
| 102 |
+
script_content = f"# {title}\n\n" + "\n".join(script_sentences)
|
| 103 |
|
| 104 |
progress(66, desc="์์ฝ ์์ฑ ์ค...")
|
| 105 |
summary = summarize_text(title, description, script)
|
| 106 |
+
summary_content = f"# {title}\n\n{summary}"
|
| 107 |
|
| 108 |
progress(100, desc="์๋ฃ")
|
| 109 |
+
return script_content, summary_content
|
| 110 |
except Exception as e:
|
| 111 |
error_msg = f"์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
| 112 |
logging.exception(error_msg)
|
| 113 |
+
return error_msg, error_msg
|
| 114 |
|
| 115 |
# Gradio ์ธํฐํ์ด์ค
|
| 116 |
with gr.Blocks() as demo:
|
|
|
|
| 118 |
youtube_url_input = gr.Textbox(label="YouTube URL ์
๋ ฅ")
|
| 119 |
analyze_button = gr.Button("๋ถ์ํ๊ธฐ")
|
| 120 |
|
|
|
|
|
|
|
| 121 |
with gr.Tabs():
|
| 122 |
with gr.TabItem("์๋ฌธ ์คํฌ๋ฆฝํธ"):
|
| 123 |
script_output = gr.Markdown()
|
|
|
|
| 127 |
analyze_button.click(
|
| 128 |
analyze,
|
| 129 |
inputs=[youtube_url_input],
|
| 130 |
+
outputs=[script_output, summary_output]
|
| 131 |
)
|
| 132 |
|
| 133 |
if __name__ == "__main__":
|