Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,7 @@ asr = pipeline(task="automatic-speech-recognition", model="distil-whisper/distil
|
|
8 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
9 |
qa_pipeline = pipeline("question-answering", model="distilbert-base-cased-distilled-squad")
|
10 |
|
11 |
-
# Global
|
12 |
stored_transcript = ""
|
13 |
|
14 |
def transcribe_and_summarize(video_file):
|
@@ -24,9 +24,8 @@ def transcribe_and_summarize(video_file):
|
|
24 |
|
25 |
transcription_result = asr(audio_path, return_timestamps=True)
|
26 |
transcribed_text = " ".join([segment['text'] for segment in transcription_result['chunks']])
|
27 |
-
stored_transcript = transcribed_text
|
28 |
|
29 |
-
# Summarize
|
30 |
if len(transcribed_text.split()) < 50:
|
31 |
summarized_text = "Text too short to summarize."
|
32 |
else:
|
@@ -45,23 +44,32 @@ def answer_question(question):
|
|
45 |
result = qa_pipeline(question=question, context=stored_transcript)
|
46 |
return result['answer']
|
47 |
|
48 |
-
# Gradio
|
49 |
-
with gr.Blocks() as iface:
|
50 |
-
|
51 |
-
|
52 |
-
transcribed_text = gr.Textbox(label="Transcribed Text", lines=6)
|
53 |
-
summarized_text = gr.Textbox(label="Summarized Text", lines=6)
|
54 |
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
-
|
59 |
-
question_input = gr.Textbox(label="Ask a question about the transcript")
|
60 |
-
answer_output = gr.Textbox(label="Answer")
|
61 |
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
-
|
|
|
|
|
66 |
port = int(os.environ.get('PORT1', 7860))
|
67 |
iface.launch(share=True, server_port=port)
|
|
|
8 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
9 |
qa_pipeline = pipeline("question-answering", model="distilbert-base-cased-distilled-squad")
|
10 |
|
11 |
+
# Global transcript
|
12 |
stored_transcript = ""
|
13 |
|
14 |
def transcribe_and_summarize(video_file):
|
|
|
24 |
|
25 |
transcription_result = asr(audio_path, return_timestamps=True)
|
26 |
transcribed_text = " ".join([segment['text'] for segment in transcription_result['chunks']])
|
27 |
+
stored_transcript = transcribed_text
|
28 |
|
|
|
29 |
if len(transcribed_text.split()) < 50:
|
30 |
summarized_text = "Text too short to summarize."
|
31 |
else:
|
|
|
44 |
result = qa_pipeline(question=question, context=stored_transcript)
|
45 |
return result['answer']
|
46 |
|
47 |
+
# Gradio UI
|
48 |
+
with gr.Blocks(theme=gr.themes.Base()) as iface:
|
49 |
+
gr.Markdown("## π₯ Video Transcriber, Summarizer & Q&A Tool")
|
50 |
+
gr.Markdown("Upload a video to get a transcript, summary, and ask questions about its content.")
|
|
|
|
|
51 |
|
52 |
+
with gr.Tab("1οΈβ£ Transcription & Summary"):
|
53 |
+
with gr.Row():
|
54 |
+
video_input = gr.Video(label="π Upload Video (.mp4)", interactive=True)
|
55 |
+
with gr.Row():
|
56 |
+
transcribe_btn = gr.Button("π Transcribe and Summarize")
|
57 |
+
with gr.Row():
|
58 |
+
transcribed_text = gr.Textbox(label="π Transcribed Text", lines=8, interactive=False)
|
59 |
+
summarized_text = gr.Textbox(label="π Summarized Text", lines=8, interactive=False)
|
60 |
|
61 |
+
transcribe_btn.click(fn=transcribe_and_summarize, inputs=video_input, outputs=[transcribed_text, summarized_text])
|
|
|
|
|
62 |
|
63 |
+
with gr.Tab("2οΈβ£ Ask Questions"):
|
64 |
+
with gr.Row():
|
65 |
+
question_input = gr.Textbox(label="β Ask a question based on the transcript", placeholder="E.g., What is the main topic?")
|
66 |
+
with gr.Row():
|
67 |
+
ask_btn = gr.Button("π Get Answer")
|
68 |
+
with gr.Row():
|
69 |
+
answer_output = gr.Textbox(label="π¬ Answer", interactive=False)
|
70 |
|
71 |
+
ask_btn.click(fn=answer_question, inputs=question_input, outputs=answer_output)
|
72 |
+
|
73 |
+
# Launch app
|
74 |
port = int(os.environ.get('PORT1', 7860))
|
75 |
iface.launch(share=True, server_port=port)
|