Spaces:
Sleeping
Sleeping
| # app.py | |
| import gradio as gr | |
| from backend import fetch_video_metadata, fetch_transcript, split_long_sentences, match_keywords_in_sentences, read_keywords | |
| import pandas as pd | |
| # Gradio interface function to call the backend functions | |
| def analyze_sentiment(video_url, excel_file_path): | |
| # Fetch video metadata | |
| metadata, metadata_error = fetch_video_metadata(video_url) | |
| if metadata_error: | |
| return f"Error: {metadata_error}" | |
| # Fetch transcript | |
| transcript, transcript_error = fetch_transcript(video_url) | |
| if transcript_error: | |
| return f"Error: {transcript_error}" | |
| # Process sentences from transcript | |
| sentences = split_long_sentences(transcript) | |
| # Read keywords from uploaded Excel file | |
| keywords, attributes = read_keywords(excel_file_path) | |
| # Match keywords in sentences | |
| matched_keywords = match_keywords_in_sentences(sentences, keywords) | |
| # Prepare the report for Gradio display | |
| report = { | |
| "Metadata": metadata, | |
| "Matched Keywords": matched_keywords, | |
| "Sentences": sentences | |
| } | |
| return report | |
| # Gradio interface setup | |
| interface = gr.Interface( | |
| fn=analyze_sentiment, | |
| inputs=[ | |
| gr.inputs.Textbox(label="YouTube Video URL"), | |
| gr.inputs.File(label="Upload Keywords Excel File") # User uploads keywords file | |
| ], | |
| outputs=[ | |
| gr.outputs.JSON(label="Metadata and Sentiment Analysis Results"), | |
| gr.outputs.Textbox(label="Sentences from Transcript") # Display sentences detected in transcript | |
| ] | |
| ) | |
| # Launch Gradio interface | |
| interface.launch() | |
| import gradio as gr | |
| def process_keywords_and_video(url, excel_file): | |
| metadata, error = fetch_video_metadata(url) | |
| if error: | |
| return error, None | |
| transcript, error = fetch_transcript(url) | |
| if error: | |
| return error, None | |
| sentences = split_long_sentences(transcript) | |
| keywords, attributes = read_keywords(excel_file) | |
| matched_keywords = match_keywords_in_sentences(sentences, keywords) | |
| sentiment_results = analyze_sentiment_for_keywords(matched_keywords, sentences) | |
| wordclouds = generate_word_clouds(matched_keywords) | |
| pdf_file = generate_pdf_with_sections(metadata, sentiment_results, wordclouds) | |
| return "Processing completed successfully!", pdf_file | |
| # Gradio App | |
| with gr.Blocks() as iface: | |
| gr.Markdown("<h1>Auto-Insight: YouTube Video Analyzer for Automobiles</h1>") | |
| video_url = gr.Textbox(label="YouTube Video URL", placeholder="Enter the YouTube video URL") | |
| excel_file = gr.File(label="Upload Excel File with Keywords") | |
| process_button = gr.Button("Analyze Video") | |
| processing_status = gr.Textbox(label="Processing Status", interactive=False) | |
| pdf_output = gr.File(label="Download Sentiment Report (PDF)") | |
| process_button.click( | |
| process_keywords_and_video, | |
| inputs=[video_url, excel_file], | |
| outputs=[processing_status, pdf_output] | |
| ) | |
| iface.launch(share=True) |