import gradio as gr from video_accent_analyzer import VideoAccentAnalyzer 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']}" markdown = f"## 🎯 Results\n" markdown += f"**Predicted Accent:** {result['predicted_accent']}\n" markdown += f"**Confidence:** {result['confidence']:.1f}%\n" markdown += f"**English Confidence:** {result['english_confidence']:.1f}%\n\n" markdown += "### 📊 Probability Breakdown:\n" for accent, prob in sorted(result['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=abc123 ", None], [None, "example_video.mp4"] ], title="🎧 Video Accent Analyzer", description="Detect English accents in videos from YouTube, Loom, or uploaded files" ) if __name__ == "__main__": interface.launch()