import gradio as gr
from utils import *
from youtube_api_test import *
from prompt import *
from final_channal_analyzer import *
from final_video_analyzer import *
css = """
.gradio-container {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
.main {
background: rgba(255, 255, 255, 0.98);
border-radius: 25px;
margin: 20px;
padding: 40px;
box-shadow: 0 25px 80px rgba(0,0,0,0.15);
backdrop-filter: blur(10px);
}
.analysis-button {
background: linear-gradient(45deg, #4facfe, #00f2fe) !important;
border: none !important;
color: white !important;
font-weight: bold !important;
border-radius: 15px !important;
padding: 15px 30px !important;
margin: 10px !important;
transition: all 0.3s ease !important;
box-shadow: 0 6px 20px rgba(79, 172, 254, 0.3) !important;
}
.analysis-button:hover {
transform: translateY(-3px) !important;
box-shadow: 0 10px 30px rgba(79, 172, 254, 0.4) !important;
}
.shorts-button {
background: linear-gradient(45deg, #ff6b6b, #feca57) !important;
box-shadow: 0 6px 20px rgba(255, 107, 107, 0.3) !important;
}
.shorts-button:hover {
box-shadow: 0 10px 30px rgba(255, 107, 107, 0.4) !important;
}
"""
with gr.Blocks(css=css, title="YouTube Analyzer Pro - Specialized Analysis") as demo:
gr.HTML("""
š YouTube Analyzer Pro
AI-Powered Specialized Content Analysis
š¹ Deep Video Analysis ⢠š¬ Shorts Intelligence ⢠š¬ Comment Insights
""")
with gr.Tabs():
with gr.Tab("š Youtube Channel Specialized Analysis"):
gr.HTML("š Choose Your Analysis Type ~60s
")
with gr.Row():
with gr.Column(scale=2):
channel_input = gr.Textbox(
label="šÆ YouTube Channel Name",
value="MrBeast",
placeholder="Enter YouTube channel Name for specialized analysis...",
info="š Extract channel name from URL - if URL is https://www.youtube.com/@MrBeast, enter 'MrBeast'",
lines=1
)
with gr.Column(scale=1):
max_videos_slider = gr.Slider(
minimum=2,
maximum=10,
value=5,
step=1,
label="š Max Videos/Shorts to Analyze",
info="šÆ Select 2-10 content pieces for analysis"
)
# Two specialized analysis buttons
with gr.Row():
with gr.Column():
videos_btn = gr.Button(
"š¹ Analyze Videos",
variant="primary",
size="large",
elem_classes=["analysis-button"]
)
with gr.Column():
shorts_btn = gr.Button(
"š¬ Analyze Shorts",
variant="secondary",
size="large",
elem_classes=["analysis-button", "shorts-button"]
)
with gr.Row():
analysis_result = gr.Markdown(
label="šÆ AI Intelligence Report",
elem_classes=["analysis-report"]
)
dashboard_plot = gr.Plot(
label="š Interactive Analytics Dashboard",
elem_classes=["dashboard-plot"]
)
videos_btn.click(
fn=lambda channel_input, max_videos: analyze_content_batch(channel_input, "videos", max_videos),
inputs=[channel_input, max_videos_slider],
outputs=[analysis_result, dashboard_plot],
show_progress=True
)
shorts_btn.click(
fn=lambda channel_input, max_videos: analyze_content_batch(channel_input, "shorts", max_videos),
inputs=[channel_input, max_videos_slider],
outputs=[analysis_result, dashboard_plot],
show_progress=True
)
with gr.Tab("šÆ Youtube Single Video Analysis"):
with gr.Tabs():
with gr.TabItem("YouTube Channel: Single Video"):
with gr.Row():
with gr.Column(scale=2):
video_id = gr.Textbox(
label="YouTube Video ID",
value="hTSaweR8qMI",
placeholder="Enter video ID...",
info="š” The video ID is the part after 'v=' in a YouTube URL\nšŗ Example: youtube.com/watch?v=dQw4w9WgXcQ ā Enter: dQw4w9WgXcQ"
)
with gr.Column(scale=1):
comment_limit_slider = gr.Slider(
minimum=10,
maximum=50,
value=25,
step=5,
label="š Major Comments to Analyze",
info="šÆ Select 10-50 comments for analysis"
)
video_btn = gr.Button("š Analyze Video In Depth :) ~40s", variant="primary")
with gr.Row():
with gr.Column(scale=2):
video_result = gr.Markdown(label="š Comprehensive Analysis Report")
with gr.Column(scale=1):
gr.HTML("š Analytics Dashboard
")
video_info_display = gr.Markdown(label="š¹ Video Information")
sentiment_chart = gr.Image(label="š¬ Sentiment Analysis Dashboard", type="pil")
opinion_chart = gr.Image(label="š„ Public Opinion Analysis", type="pil")
video_btn.click(
fn=lambda video_id, comment_limit: comment_analyzer(video_id, comment_limit),
inputs=[video_id, comment_limit_slider],
outputs=[video_result, video_info_display, sentiment_chart, opinion_chart],
show_progress=True
)
gr.HTML("""
šÆ Specialized Analysis ⢠š¬ Real Comment Insights ⢠š Trend Reasoning
""")
if __name__ == "__main__":
demo.launch(mcp_server=True)