dtkne commited on
Commit
beed497
Β·
verified Β·
1 Parent(s): 4041d63

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -17
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 variable to store transcript for Q&A
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 # Save for Q&A
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 interface with three parts
49
- with gr.Blocks() as iface:
50
- with gr.Row():
51
- video_input = gr.Video(label="Upload Video (.mp4)")
52
- transcribed_text = gr.Textbox(label="Transcribed Text", lines=6)
53
- summarized_text = gr.Textbox(label="Summarized Text", lines=6)
54
 
55
- transcribe_btn = gr.Button("Transcribe and Summarize")
56
- transcribe_btn.click(fn=transcribe_and_summarize, inputs=video_input, outputs=[transcribed_text, summarized_text])
 
 
 
 
 
 
57
 
58
- with gr.Row():
59
- question_input = gr.Textbox(label="Ask a question about the transcript")
60
- answer_output = gr.Textbox(label="Answer")
61
 
62
- ask_btn = gr.Button("Get Answer")
63
- ask_btn.click(fn=answer_question, inputs=question_input, outputs=answer_output)
 
 
 
 
 
64
 
65
- # Launch
 
 
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)