Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -109,58 +109,48 @@ def summarize_text(title, description, text):
|
|
109 |
"""
|
110 |
return call_api(prompt, max_tokens=2000, temperature=0.3, top_p=0.9)
|
111 |
|
112 |
-
def
|
113 |
-
if section_title == "์๋ฌธ ์คํฌ๋ฆฝํธ":
|
114 |
-
sentences = split_sentences(content)
|
115 |
-
content = "\n".join(sentences)
|
116 |
-
|
117 |
-
return f"""
|
118 |
-
<details>
|
119 |
-
<summary style="cursor: pointer; font-weight: bold;">{section_title}</summary>
|
120 |
-
<div style="margin-top: 10px;">
|
121 |
-
<h3 style="font-size: 18px; margin-bottom: 10px;">{video_title}</h3>
|
122 |
-
<div style="white-space: pre-wrap; background-color: #f0f0f0; padding: 15px; border-radius: 5px;">{content}</div>
|
123 |
-
</div>
|
124 |
-
</details>
|
125 |
-
"""
|
126 |
-
|
127 |
-
def analyze(url, cache):
|
128 |
try:
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
# ์๋ฌธ ์คํฌ๋ฆฝํธ ์น์
์์ฑ
|
138 |
-
script_section = create_collapsible_section("์๋ฌธ ์คํฌ๋ฆฝํธ", title, script)
|
139 |
-
yield script_section, cache
|
140 |
-
|
141 |
-
# ์์ฝ ์์ฑ ๋ฐ ์น์
์์ฑ
|
142 |
summary = summarize_text(title, description, script)
|
143 |
-
|
144 |
-
|
145 |
-
|
|
|
|
|
|
|
|
|
146 |
except Exception as e:
|
147 |
error_msg = f"์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
148 |
logging.exception(error_msg)
|
149 |
-
|
150 |
|
151 |
# Gradio ์ธํฐํ์ด์ค
|
152 |
with gr.Blocks() as demo:
|
153 |
gr.Markdown("## YouTube ์คํฌ๋ฆฝํธ ์ถ์ถ ๋ฐ ์์ฝ ๋๊ตฌ")
|
154 |
youtube_url_input = gr.Textbox(label="YouTube URL ์
๋ ฅ")
|
155 |
analyze_button = gr.Button("๋ถ์ํ๊ธฐ")
|
156 |
-
|
157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
|
159 |
analyze_button.click(
|
160 |
-
analyze,
|
161 |
-
inputs=[youtube_url_input
|
162 |
-
outputs=[
|
163 |
)
|
164 |
|
165 |
if __name__ == "__main__":
|
166 |
-
demo.launch(
|
|
|
109 |
"""
|
110 |
return call_api(prompt, max_tokens=2000, temperature=0.3, top_p=0.9)
|
111 |
|
112 |
+
def analyze(url, progress=gr.Progress()):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
try:
|
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 = "\n".join(script_sentences)
|
120 |
+
|
121 |
+
progress(66, desc="์์ฝ ์์ฑ ์ค...")
|
|
|
|
|
|
|
|
|
|
|
122 |
summary = summarize_text(title, description, script)
|
123 |
+
|
124 |
+
progress(100, desc="์๋ฃ")
|
125 |
+
return {
|
126 |
+
"์ ๋ชฉ": title,
|
127 |
+
"์๋ฌธ ์คํฌ๋ฆฝํธ": script_content,
|
128 |
+
"์์ฝ": summary
|
129 |
+
}
|
130 |
except Exception as e:
|
131 |
error_msg = f"์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
132 |
logging.exception(error_msg)
|
133 |
+
return {"์ค๋ฅ": error_msg}
|
134 |
|
135 |
# Gradio ์ธํฐํ์ด์ค
|
136 |
with gr.Blocks() as demo:
|
137 |
gr.Markdown("## YouTube ์คํฌ๋ฆฝํธ ์ถ์ถ ๋ฐ ์์ฝ ๋๊ตฌ")
|
138 |
youtube_url_input = gr.Textbox(label="YouTube URL ์
๋ ฅ")
|
139 |
analyze_button = gr.Button("๋ถ์ํ๊ธฐ")
|
140 |
+
|
141 |
+
with gr.Tabs():
|
142 |
+
with gr.TabItem("์๋ฌธ ์คํฌ๋ฆฝํธ"):
|
143 |
+
script_output = gr.Markdown()
|
144 |
+
with gr.TabItem("์์ฝ"):
|
145 |
+
summary_output = gr.Markdown()
|
146 |
+
|
147 |
+
title_output = gr.Textbox(label="์์ ์ ๋ชฉ")
|
148 |
|
149 |
analyze_button.click(
|
150 |
+
analyze,
|
151 |
+
inputs=[youtube_url_input],
|
152 |
+
outputs=[title_output, script_output, summary_output]
|
153 |
)
|
154 |
|
155 |
if __name__ == "__main__":
|
156 |
+
demo.launch()
|