-
Notifications
You must be signed in to change notification settings - Fork 21
/
app.py
161 lines (100 loc) · 4.64 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import streamlit as st
import os
from Senti import extract_video_id,analyze_sentiment,bar_chart,plot_sentiment
from YoutubeCommentScrapper import save_video_comments_to_csv,get_channel_info,youtube,get_channel_id,get_video_stats
def delete_non_matching_csv_files(directory_path, video_id):
for file_name in os.listdir(directory_path):
if not file_name.endswith('.csv'):
continue
if file_name == f'{video_id}.csv':
continue
os.remove(os.path.join(directory_path, file_name))
st.set_page_config(page_title='Jatin_Agrawal_20BCS6606', page_icon = 'LOGO.png', initial_sidebar_state = 'auto')
#st.set_page_config(page_title=None, page_icon=None, layout="centered", initial_sidebar_state="auto", menu_items=None)
st.sidebar.title("Sentimental Analsis")
st.sidebar.header("Enter YouTube Link")
youtube_link = st.sidebar.text_input("Link")
directory_path = os.getcwd()
hide_st_style = """
<style>
#MainMenu {visibility: hidden;}
footer {visibility: hidden;}
</style>
"""
st.markdown(hide_st_style, unsafe_allow_html=True)
if youtube_link:
video_id = extract_video_id(youtube_link)
channel_id = get_channel_id(video_id)
if video_id:
st.sidebar.write("The video ID is:", video_id)
csv_file = save_video_comments_to_csv(video_id)
delete_non_matching_csv_files(directory_path,video_id)
st.sidebar.write("Comments saved to CSV!")
st.sidebar.download_button(label="Download Comments", data=open(csv_file, 'rb').read(), file_name=os.path.basename(csv_file), mime="text/csv")
#using fn
channel_info = get_channel_info(youtube,channel_id)
col1, col2 = st.columns(2)
with col1:
channel_logo_url = channel_info['channel_logo_url']
st.image(channel_logo_url, width=250)
with col2:
channel_title = channel_info['channel_title']
st.title(' ')
st.text(" YouTube Channel Name ")
#st.markdown('** YouTube Channel Name **')
st.title(channel_title)
st.title(" ")
st.title(" ")
st.title(" ")
#Using fn
st.title(" ")
col3, col4 ,col5 = st.columns(3)
with col3:
video_count=channel_info['video_count']
st.header(" Total Videos ")
#st.subheader("Total Videos")
st.subheader(video_count)
with col4:
channel_created_date= channel_info['channel_created_date']
created_date = channel_created_date[:10]
st.header("Channel Created ")
st.subheader(created_date)
with col5:
st.header(" Subscriber_Count ")
st.subheader(channel_info["subscriber_count"])
st.title(" ")
stats = get_video_stats(video_id)
st.title("Video Information :")
col6, col7 ,col8 = st.columns(3)
with col6:
st.header(" Total Views ")
#st.subheader("Total Videos")
st.subheader(stats["viewCount"])
with col7:
st.header(" Like Count ")
st.subheader(stats["likeCount"])
with col8:
st.header(" Comment Count ")
st.subheader(stats["commentCount"])
st.header(" ")
_, container, _ = st.columns([10, 80, 10])
container.video(data=youtube_link)
results = analyze_sentiment(csv_file)
col9, col10 ,col11 = st.columns(3)
with col9:
st.header(" Positive Comments ")
#st.subheader("Total Videos")
st.subheader(results['num_positive'])
with col10:
st.header(" Negative Comments ")
st.subheader( results['num_negative'])
with col11:
st.header(" Neutral Comments ")
st.subheader(results['num_neutral'])
bar_chart(csv_file)
plot_sentiment(csv_file)
st.subheader("Channel Description ")
channel_description = channel_info['channel_description']
st.write(channel_description)
else:
st.error("Invalid YouTube link")