import gradio as gr from VideoAccentAnalyzer import VideoAccentAnalyzer import ffmpeg import os analyzer = VideoAccentAnalyzer() def analyze_video(url=None, video_file=None): if url: result = analyzer.analyze_video_url(url) elif video_file: result = analyzer.analyze_local_video(video_file) else: return "Please provide a video URL or upload a file" if 'error' in result: return f"❌ Error: {result['error']}" # Format results as markdown markdown = f"## 🎯 Results\n" markdown += f"**Predicted Accent:** {result['predicted_accent']}\n" markdown += f"**Confidence:** {result['accent_confidence']:.1f}%\n" markdown += f"**English Confidence:** {result['english_confidence']:.1f}%\n\n" markdown += "### 📊 Probability Breakdown:\n" for accent, prob in sorted(result['all_probabilities'].items(), key=lambda x: x[1], reverse=True): markdown += f"- {accent}: {prob:.1f}%\n" return markdown # Create Gradio interface interface = gr.Interface( fn=analyze_video, inputs=[ gr.Textbox(label="Video URL (YouTube/Loom/Direct MP4)"), gr.File(label="Or Upload Video File", type="filepath") ], outputs=gr.Markdown(label="Analysis Results"), examples=[ ["https://www.youtube.com/watch?v=NO5SbsvIjHE ", None], [None, "/kaggle/input/test-video.mp4"] ], title="🎧 Video Accent Analyzer", description="Analyze accents in videos from YouTube, Loom, or uploaded files. Supports English accents only." ) if __name__ == "__main__": interface.launch()