Update app.py
Browse files
app.py
CHANGED
@@ -38,33 +38,37 @@ def youtube_sentiment_analysis(url, num_of_comments):
|
|
38 |
logging.exception(f"Unexpected Error: {str(e)}")
|
39 |
return f"Unexpected Error: {str(e)}", None, None
|
40 |
|
41 |
-
# Gradio Interface (All Outputs Below Input)
|
42 |
-
iface = gr.Blocks()
|
43 |
-
|
44 |
# Example YouTube URLs
|
45 |
example_urls = [
|
46 |
-
"https://www.youtube.com/watch?v=0e9WuB0Ua98",
|
47 |
-
"https://www.youtube.com/watch?v=3JZ_D3ELwOQ",
|
48 |
-
"https://youtu.be/dQw4w9WgXcQ",
|
49 |
-
"https://www.youtube.com/watch?v=9bZkp7q19f0",
|
50 |
-
"https://www.youtube.com/watch?v=2Vv-BfVoq4g"
|
51 |
]
|
52 |
|
53 |
-
|
54 |
-
|
|
|
|
|
|
|
55 |
|
56 |
-
gr.
|
|
|
57 |
|
58 |
with gr.Row():
|
59 |
-
|
60 |
-
|
|
|
|
|
61 |
|
62 |
-
|
|
|
63 |
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
|
69 |
submit_btn.click(
|
70 |
youtube_sentiment_analysis,
|
@@ -72,10 +76,6 @@ with iface:
|
|
72 |
outputs=[output_summary, output_chart, output_table],
|
73 |
)
|
74 |
|
75 |
-
gr.Markdown("### Example YouTube Video URLs for Testing (Click to Use)")
|
76 |
-
with gr.Row():
|
77 |
-
for example in example_urls:
|
78 |
-
gr.Button(example).click(fn=lambda x=example: x, outputs=[youtube_url])
|
79 |
-
|
80 |
# Launch App
|
81 |
-
|
|
|
|
38 |
logging.exception(f"Unexpected Error: {str(e)}")
|
39 |
return f"Unexpected Error: {str(e)}", None, None
|
40 |
|
|
|
|
|
|
|
41 |
# Example YouTube URLs
|
42 |
example_urls = [
|
43 |
+
["https://www.youtube.com/watch?v=0e9WuB0Ua98"],
|
44 |
+
["https://www.youtube.com/watch?v=3JZ_D3ELwOQ"],
|
45 |
+
["https://youtu.be/dQw4w9WgXcQ"],
|
46 |
+
["https://www.youtube.com/watch?v=9bZkp7q19f0"],
|
47 |
+
["https://www.youtube.com/watch?v=2Vv-BfVoq4g"]
|
48 |
]
|
49 |
|
50 |
+
# Gradio Interface
|
51 |
+
with gr.Blocks() as demo:
|
52 |
+
# Centered Title
|
53 |
+
with gr.Row():
|
54 |
+
gr.HTML("<h1 style='text-align: center; width: 100%;'>🎬 YouTube Comment Sentiment Analysis</h1>")
|
55 |
|
56 |
+
with gr.Row():
|
57 |
+
gr.HTML("<p style='text-align: center; width: 100%;'>Enter a YouTube video URL and specify the number of comments to analyze.</p>")
|
58 |
|
59 |
with gr.Row():
|
60 |
+
with gr.Column():
|
61 |
+
youtube_url = gr.Textbox(label="YouTube Video URL")
|
62 |
+
num_comments = gr.Slider(minimum=10, maximum=1000, step=1, value=100, label="Number of Comments to Fetch")
|
63 |
+
submit_btn = gr.Button("Submit")
|
64 |
|
65 |
+
gr.Markdown("### Example YouTube Video URLs for Testing")
|
66 |
+
gr.Examples(examples=example_urls, inputs=youtube_url, label="Click an example to autofill")
|
67 |
|
68 |
+
with gr.Column():
|
69 |
+
output_summary = gr.Textbox(label="Overall Sentiment Summary")
|
70 |
+
output_chart = gr.Plot(label="Sentiment Chart")
|
71 |
+
output_table = gr.Dataframe(label="Comment Sentiment Analysis")
|
72 |
|
73 |
submit_btn.click(
|
74 |
youtube_sentiment_analysis,
|
|
|
76 |
outputs=[output_summary, output_chart, output_table],
|
77 |
)
|
78 |
|
|
|
|
|
|
|
|
|
|
|
79 |
# Launch App
|
80 |
+
if __name__ == "__main__":
|
81 |
+
demo.launch()
|