nlpblogs commited on
Commit
eae5fab
·
verified ·
1 Parent(s): 6fb5eb1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -17
app.py CHANGED
@@ -34,32 +34,88 @@ import torch
34
 
35
 
36
 
 
 
 
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
 
40
-
41
 
42
  tokenizer = transformers.DistilBertTokenizer.from_pretrained("tabularisai/robust-sentiment-analysis")
43
  model = transformers.DistilBertForSequenceClassification.from_pretrained("tabularisai/robust-sentiment-analysis")
44
 
 
 
 
 
 
 
 
 
 
45
  def clear_question():
46
- st.session_state["youtube_video_url"] = ""
47
 
48
- youtube_video_url = st.text_input("Enter Google Maps URL:", key="youtube_video_url")
49
  st.button("Clear question", on_click=clear_question)
50
 
51
- if st.button("Scrape Reviews"):
52
- options = Options()
53
- options.add_argument("--headless")
54
- options.add_argument("--disable-gpu")
55
- options.add_argument("--no-sandbox")
56
- options.add_argument("--disable-dev-shm-usage")
57
- options.add_argument("--start-maximized")
58
- service = Service(ChromeDriverManager(chrome_type=ChromeType.CHROMIUM).install())
59
- driver = webdriver.Chrome(service=service, options=options)
60
- data = []
61
- wait = WebDriverWait(driver, 30)
62
- driver.get(youtube_video_url)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
 
64
 
65
  placeholder = st.empty() # Create an empty placeholder for dynamic text
@@ -114,7 +170,7 @@ if st.button("Scrape Reviews"):
114
  value_counts1 = sentiment_df['Sentiment'].value_counts().rename_axis('Sentiment').reset_index(name='count')
115
  final_df = value_counts1
116
 
117
- tab1, tab2 = st.tabs(["Cat", "Dog"])
118
  with tab1:
119
  fig1 = px.pie(final_df, values='count', names='Sentiment', hover_data=['count'], labels={'count': 'count'})
120
  fig1.update_traces(textposition='inside', textinfo='percent+label')
@@ -133,7 +189,7 @@ if st.button("Scrape Reviews"):
133
  st.download_button(
134
  label="Download data as CSV",
135
  data=csv,
136
- file_name='review_analysis_result.csv',
137
  mime='text/csv',
138
  )
139
 
 
34
 
35
 
36
 
37
+ with st.sidebar:
38
+ st.button("DEMO APP", type="primary")
39
+
40
 
41
+ expander = st.expander("**Important notes on the YouTube Comments Sentiment Analysis App**")
42
+ expander.write('''
43
+
44
+
45
+ **How to Use**
46
+ This app works with the YouTube URL. Paste the URL and press the 'Sentiment Analysis' button to perform sentiment analysis on your YouTube Comments.
47
+
48
+
49
+ **Usage Limits**
50
+ You can perform sentiment analysis on YouTube Comments up to 5 times.
51
+
52
+
53
+ **Subscription Management**
54
+ This demo app offers a one-day subscription, expiring after 24 hours. If you are interested in building your own YouTube Comments Sentiment Analysis Web App, we invite you to explore our NLP Web App Store on our website. You can select your desired features, place your order, and we will deliver your custom app in five business days. If you wish to delete your Account with us, please contact us at [email protected]
55
+
56
+
57
+ **Customization**
58
+ To change the app's background color to white or black, click the three-dot menu on the right-hand side of your app, go to Settings and then Choose app theme, colors and fonts.
59
+
60
+
61
+ **Charts**
62
+ Hover to interact with and download the charts.
63
+
64
+
65
+ **File Handling and Errors**
66
+ The pie and bar charts are based only on reviews containing text. For any errors or inquiries, please contact us at [email protected]
67
+
68
+
69
+
70
+ ''')
71
 
72
 
73
+ st.subheader("YouTube Comments Sentiment Analysis", divider = "red")
74
 
75
  tokenizer = transformers.DistilBertTokenizer.from_pretrained("tabularisai/robust-sentiment-analysis")
76
  model = transformers.DistilBertForSequenceClassification.from_pretrained("tabularisai/robust-sentiment-analysis")
77
 
78
+
79
+ if 'url_count' not in st.session_state:
80
+ st.session_state['url_count'] = 0
81
+
82
+ max_attempts = 2
83
+
84
+ def update_url_count():
85
+ st.session_state['url_count'] += 1
86
+
87
  def clear_question():
88
+ st.session_state["url"] = ""
89
 
90
+ url = st.text_input("Enter YouTube URL:", key="url")
91
  st.button("Clear question", on_click=clear_question)
92
 
93
+ if st.button("Sentiment Analysis", type="secondary"):
94
+ if st.session_state['url_count'] < max_attempts:
95
+ if url:
96
+ with st.spinner("Wait for it...", show_time=True):
97
+ options = Options()
98
+ options.add_argument("--headless")
99
+ options.add_argument("--disable-gpu")
100
+ options.add_argument("--no-sandbox")
101
+ options.add_argument("--disable-dev-shm-usage")
102
+ options.add_argument("--start-maximized")
103
+ service = Service(ChromeDriverManager(chrome_type=ChromeType.CHROMIUM).install())
104
+ driver = webdriver.Chrome(service=service, options=options)
105
+ data = []
106
+ wait = WebDriverWait(driver, 30)
107
+ driver.get(url)
108
+
109
+ st.warning("Failed to scrape reviews.")
110
+ update_url_count() # Correctly indented
111
+ else:
112
+ st.warning("Please enter a URL.")
113
+ else:
114
+ st.warning(f"You have reached the maximum URL attempts ({max_attempts}).")
115
+
116
+ st.write(f"URL pasted {st.session_state['url_count']} times.")
117
+
118
+
119
 
120
 
121
  placeholder = st.empty() # Create an empty placeholder for dynamic text
 
170
  value_counts1 = sentiment_df['Sentiment'].value_counts().rename_axis('Sentiment').reset_index(name='count')
171
  final_df = value_counts1
172
 
173
+ tab1, tab2 = st.tabs(["Pie Chart", "Bar Chart"])
174
  with tab1:
175
  fig1 = px.pie(final_df, values='count', names='Sentiment', hover_data=['count'], labels={'count': 'count'})
176
  fig1.update_traces(textposition='inside', textinfo='percent+label')
 
189
  st.download_button(
190
  label="Download data as CSV",
191
  data=csv,
192
+ file_name='Summary of the results.csv',
193
  mime='text/csv',
194
  )
195