AIRider commited on
Commit
85efe2c
ยท
verified ยท
1 Parent(s): 876af8e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -39
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 create_collapsible_section(section_title, video_title, content):
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
- if url == cache["url"]:
130
- logging.info(f"์บ์‹œ๋œ ๋ฐ์ดํ„ฐ ์‚ฌ์šฉ: URL = {url}")
131
- title, description, script = cache["title"], cache["description"], cache["script"]
132
- else:
133
- logging.info(f"์ƒˆ๋กœ์šด ๋ฐ์ดํ„ฐ ์ถ”์ถœ ์‹œ์ž‘: URL = {url}")
134
- title, description, script = get_youtube_script(url)
135
- cache = {"url": url, "title": title, "description": description, "script": script}
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
- summary_section = create_collapsible_section("์š”์•ฝ", title, summary)
144
- yield script_section + summary_section, cache
145
-
 
 
 
 
146
  except Exception as e:
147
  error_msg = f"์ฒ˜๋ฆฌ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}"
148
  logging.exception(error_msg)
149
- yield error_msg, cache
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
- content_output = gr.HTML(label="๋‚ด์šฉ")
157
- cached_data = gr.State({"url": "", "title": "", "description": "", "script": ""})
 
 
 
 
 
 
158
 
159
  analyze_button.click(
160
- analyze,
161
- inputs=[youtube_url_input, cached_data],
162
- outputs=[content_output, cached_data]
163
  )
164
 
165
  if __name__ == "__main__":
166
- demo.launch(share=True)
 
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()