AIRider commited on
Commit
6abe9bf
ยท
verified ยท
1 Parent(s): a725404

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -36
app.py CHANGED
@@ -119,52 +119,34 @@ def display_script(title, script):
119
  formatted_script = "\n\n".join(script_sentences)
120
  return f"# {title}\n\n{formatted_script}"
121
 
122
- def analyze(url, progress=gr.Progress()):
123
- try:
124
- # ์Šคํฌ๋ฆฝํŠธ ์ถ”์ถœ (์ง„ํ–‰ ์ƒํ™ฉ ํ‘œ์‹œ ์—†์ด)
125
- title, description, script = get_youtube_script(url)
126
-
127
- # ์›๋ฌธ ์Šคํฌ๋ฆฝํŠธ ์ฒ˜๋ฆฌ ๋ฐ ์ถœ๋ ฅ
128
- script_content = display_script(title, script)
129
- yield script_content, "์š”์•ฝ ์ค€๋น„ ์ค‘..."
130
-
131
- # ์š”์•ฝ ์ž‘์—… ์‹œ์ž‘ (์ง„ํ–‰ ์ƒํ™ฉ ํ‘œ์‹œ)
132
- for i in progress.tqdm(range(3), desc="์š”์•ฝ ์ƒ์„ฑ ์ค‘..."):
133
- if i == 0:
134
- # ์š”์•ฝ ์ƒ์„ฑ
135
- summary = summarize_text(title, description, script)
136
- elif i == 1:
137
- # ์š”์•ฝ ๋‚ด์šฉ ์ •๋ฆฌ
138
- summary_content = f"# {title}\n\n{summary}"
139
- else:
140
- # ์™„๋ฃŒ
141
- pass
142
- yield script_content, f"์š”์•ฝ ์ƒ์„ฑ ์ค‘... ({i+1}/3)"
143
-
144
- # ์ตœ์ข… ๊ฒฐ๊ณผ ์ถœ๋ ฅ
145
- yield script_content, summary_content
146
- except Exception as e:
147
- error_msg = f"์ฒ˜๋ฆฌ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}"
148
- logging.exception(error_msg)
149
- yield error_msg, error_msg
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
- with gr.Tabs():
158
- with gr.TabItem("์›๋ฌธ ์Šคํฌ๋ฆฝํŠธ"):
159
- script_output = gr.Markdown()
160
- with gr.TabItem("์š”์•ฝ"):
161
- summary_output = gr.Markdown()
162
 
163
  analyze_button.click(
164
  analyze,
165
  inputs=[youtube_url_input],
166
- outputs=[script_output, summary_output],
167
- show_progress=True
168
  )
169
 
170
  if __name__ == "__main__":
 
119
  formatted_script = "\n\n".join(script_sentences)
120
  return f"# {title}\n\n{formatted_script}"
121
 
122
+ def display_script(title, script):
123
+ script_sentences = split_sentences(script)
124
+ formatted_script = "\n\n".join(script_sentences)
125
+ return f"""<h2>{title}</h2>
126
+ <details>
127
+ <summary>์›๋ฌธ ์Šคํฌ๋ฆฝํŠธ (ํด๋ฆญํ•˜์—ฌ ํŽผ์น˜๊ธฐ)</summary>
128
+ <pre>{formatted_script}</pre>
129
+ </details>"""
130
+
131
+ def analyze(url):
132
+ title, description, script = get_youtube_script(url)
133
+ script_content = display_script(title, script)
134
+ summary = summarize_text(title, description, script)
135
+ summary_content = f"<h2>{title}</h2>\n\n{summary}"
136
+ return script_content, summary_content
 
 
 
 
 
 
 
 
 
 
 
 
 
137
 
138
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค
139
  with gr.Blocks() as demo:
140
  gr.Markdown("## YouTube ์Šคํฌ๋ฆฝํŠธ ์ถ”์ถœ ๋ฐ ์š”์•ฝ ๋„๊ตฌ")
141
  youtube_url_input = gr.Textbox(label="YouTube URL ์ž…๋ ฅ")
142
  analyze_button = gr.Button("๋ถ„์„ํ•˜๊ธฐ")
143
+ script_output = gr.HTML(label="์›๋ฌธ ์Šคํฌ๋ฆฝํŠธ")
144
+ summary_output = gr.HTML(label="์š”์•ฝ")
 
 
 
 
145
 
146
  analyze_button.click(
147
  analyze,
148
  inputs=[youtube_url_input],
149
+ outputs=[script_output, summary_output]
 
150
  )
151
 
152
  if __name__ == "__main__":