summary
Browse files
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 |
-
|
180 |
with gr.Tab("้ๅญ็จฟ"):
|
181 |
transcript_display = gr.Textbox(
|
182 |
label="YouTube ้ๅญ็จฟ",
|
183 |
interactive=False,
|
184 |
-
lines=
|
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(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|