Spaces:
Runtime error
Runtime error
Download app.py from Sumayyea/Video_Summarizer: direct link, hf CLI and curl.
- Browser
- Download file 2.25 kB
-
https://huggingface.co/spaces/Sumayyea/Video_Summarizer/resolve/main/app.py
- Command line
-
hf download hf://spaces/Sumayyea/Video_Summarizer/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Sumayyea/Video_Summarizer/resolve/main/app.py
2.25 kB
| 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() |