youngtsai commited on
Commit
c5386f6
ยท
1 Parent(s): 9b4503a
Files changed (1) hide show
  1. app.py +53 -3
app.py CHANGED
@@ -102,6 +102,45 @@ def generate_transcript(youtube_link):
102
  print(f"\n็”Ÿๆˆ้€ๅญ—็จฟๆ™‚็™ผ็”Ÿ้Œฏ่ชค: {str(e)}")
103
  raise
104
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  def process_all_files(file_list):
106
  print("\n=== ้–‹ๅง‹่™•็†ๆช”ๆกˆ ===")
107
  print(f"ๅพ…่™•็†ๆช”ๆกˆๆ•ธ้‡: {len(file_list)}")
@@ -176,12 +215,12 @@ with gr.Blocks() as demo:
176
  gr.Markdown("### ๅŠŸ่ƒฝๅก็‰‡")
177
  with gr.Tab("ๆ‘˜่ฆ็”Ÿๆˆ"):
178
  summary_button = gr.Button("็”Ÿๆˆๆ‘˜่ฆ")
179
- summary = gr.Textbox(label="ๆ‘˜่ฆ", interactive=False)
180
  with gr.Tab("้€ๅญ—็จฟ"):
181
  transcript_display = gr.Textbox(
182
  label="YouTube ้€ๅญ—็จฟ",
183
  interactive=False,
184
- lines=15,
185
  placeholder="่™•็† YouTube ๅฝฑ็‰‡ๅพŒ๏ผŒ้€ๅญ—็จฟๅฐ‡้กฏ็คบๅœจ้€™่ฃก..."
186
  )
187
  with gr.Tab("ๅ…ถไป–ๅŠŸ่ƒฝ"):
@@ -200,6 +239,17 @@ with gr.Blocks() as demo:
200
 
201
  history = gr.State([])
202
  ask_button.click(mock_question_answer, inputs=[question, history], outputs=[chatbot, question])
203
- summary_button.click(mock_summary, outputs=summary)
 
 
 
 
 
 
 
 
 
 
 
204
 
205
  demo.launch(share=True)
 
102
  print(f"\n็”Ÿๆˆ้€ๅญ—็จฟๆ™‚็™ผ็”Ÿ้Œฏ่ชค: {str(e)}")
103
  raise
104
 
105
+ def generate_summary(transcript):
106
+ """Generate a summary from the transcript using Gemini."""
107
+ try:
108
+ print("\n้–‹ๅง‹็”Ÿๆˆๆ‘˜่ฆ...")
109
+ model = "gemini-2.0-flash-exp"
110
+ contents = [
111
+ types.Content(
112
+ role="user",
113
+ parts=[
114
+ types.Part.from_text(
115
+ f"""่ซ‹ๆ นๆ“šไปฅไธ‹้€ๅญ—็จฟ็”Ÿๆˆ้‡้ปžๆ‘˜่ฆ๏ผŒไปฅๆขๅˆ—ๆ–นๅผๅ‘ˆ็พไธป่ฆ่ง€้ปž๏ผš
116
+
117
+ {transcript}
118
+
119
+ ่ซ‹ไปฅไธ‹ๅˆ—ๆ ผๅผ่ผธๅ‡บ๏ผš
120
+ # ไธป่ฆ่ง€้ปž๏ผš
121
+ 1. [้‡้ปž1]
122
+ 2. [้‡้ปž2]
123
+ ...
124
+
125
+ # ็ต่ซ–๏ผš
126
+ [ๆ•ด้ซ”็ต่ซ–]
127
+ """
128
+ )
129
+ ]
130
+ )
131
+ ]
132
+
133
+ response = GENAI_CLIENT.models.generate_content(
134
+ model=model,
135
+ contents=contents,
136
+ )
137
+
138
+ print("ๆ‘˜่ฆ็”ŸๆˆๅฎŒๆˆ๏ผ")
139
+ return response.text
140
+ except Exception as e:
141
+ print(f"\n็”Ÿๆˆๆ‘˜่ฆๆ™‚็™ผ็”Ÿ้Œฏ่ชค: {str(e)}")
142
+ raise
143
+
144
  def process_all_files(file_list):
145
  print("\n=== ้–‹ๅง‹่™•็†ๆช”ๆกˆ ===")
146
  print(f"ๅพ…่™•็†ๆช”ๆกˆๆ•ธ้‡: {len(file_list)}")
 
215
  gr.Markdown("### ๅŠŸ่ƒฝๅก็‰‡")
216
  with gr.Tab("ๆ‘˜่ฆ็”Ÿๆˆ"):
217
  summary_button = gr.Button("็”Ÿๆˆๆ‘˜่ฆ")
218
+ summary_output = gr.Markdown(label="ๆ‘˜่ฆ")
219
  with gr.Tab("้€ๅญ—็จฟ"):
220
  transcript_display = gr.Textbox(
221
  label="YouTube ้€ๅญ—็จฟ",
222
  interactive=False,
223
+ lines=10,
224
  placeholder="่™•็† YouTube ๅฝฑ็‰‡ๅพŒ๏ผŒ้€ๅญ—็จฟๅฐ‡้กฏ็คบๅœจ้€™่ฃก..."
225
  )
226
  with gr.Tab("ๅ…ถไป–ๅŠŸ่ƒฝ"):
 
239
 
240
  history = gr.State([])
241
  ask_button.click(mock_question_answer, inputs=[question, history], outputs=[chatbot, question])
242
+ summary_button.click(
243
+ fn=lambda transcript: on_summary_click(transcript),
244
+ inputs=[transcript_display],
245
+ outputs=[summary_output]
246
+ )
247
+
248
+ def on_summary_click(transcript):
249
+ if not transcript:
250
+ return "่ซ‹ๅ…ˆไธŠๅ‚ณๆ–‡ไปถๆˆ–่ผธๅ…ฅ YouTube ้€ฃ็ตไธฆ่™•็†ๅฎŒๆˆๅพŒๅ†็”Ÿๆˆๆ‘˜่ฆใ€‚"
251
+
252
+ summary = generate_summary(transcript)
253
+ return summary
254
 
255
  demo.launch(share=True)