File size: 2,251 Bytes
84d64f7
 
 
 
798890e
233caf2
798890e
 
84d64f7
 
 
233caf2
 
 
 
1dcb9fb
233caf2
 
84d64f7
233caf2
 
 
 
 
 
84d64f7
798890e
233caf2
 
 
 
 
 
84d64f7
798890e
233caf2
798890e
 
84d64f7
798890e
84d64f7
233caf2
84d64f7
233caf2
 
84d64f7
233caf2
84d64f7
 
 
 
 
 
798890e
233caf2
 
 
 
84d64f7
 
798890e
84d64f7
 
 
 
798890e
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import gradio as gr
import whisper
from transformers import pipeline

# Load Whisper model for transcription
whisper_model = whisper.load_model("base")

# Load summarization and question-answering pipelines
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
qa_pipeline = pipeline("question-answering", model="distilbert-base-cased-distilled-squad")

# Function to transcribe video
def transcribe_video(video_path):
    result = whisper_model.transcribe(video_path)
    return result["text"]

# Function to summarize text
def summarize_text(text):
    summary = summarizer(text, max_length=130, min_length=30, do_sample=False)
    return summary[0]["summary_text"]

# Function to answer questions
def answer_question(summary, question):
    answer = qa_pipeline(question=question, context=summary)
    return answer["answer"]

# Main function for Gradio interface
def process_video(video_path):
    # Step 1: Transcribe the video
    transcript = transcribe_video(video_path)
    # Step 2: Summarize the transcript
    summary = summarize_text(transcript)
    return transcript, summary

def ask_question(summary, question):
    # Step 3: Answer the question
    answer = answer_question(summary, question)
    return answer

# Gradio interface
with gr.Blocks() as demo:
    gr.Markdown("# Video Transcription, Summarization, and Q&A")
    with gr.Tab("Transcribe and Summarize"):
        video_input = gr.Video(label="Upload Video")
        transcript_output = gr.Textbox(label="Transcript", lines=10)
        summary_output = gr.Textbox(label="Summary", lines=5)
        transcribe_button = gr.Button("Transcribe and Summarize")
    with gr.Tab("Ask a Question"):
        summary_input = gr.Textbox(label="Paste Summary Here", lines=5)
        question_input = gr.Textbox(label="Your Question")
        answer_output = gr.Textbox(label="Answer", lines=2)
        ask_button = gr.Button("Ask Question")

    # Set up button actions
    transcribe_button.click(
        process_video,
        inputs=video_input,
        outputs=[transcript_output, summary_output]
    )
    ask_button.click(
        ask_question,
        inputs=[summary_input, question_input],
        outputs=answer_output
    )

# Launch the app
demo.launch()