Spaces:
Sleeping
Sleeping
Upload youtube.py
Browse files- youtube.py +13 -4
youtube.py
CHANGED
|
@@ -1,7 +1,12 @@
|
|
| 1 |
-
from helper import extract_youtube_id, get_all_comments
|
| 2 |
import streamlit as st
|
| 3 |
import random
|
| 4 |
import pandas as pd
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
st.header("💬 Youtube Comments Sentiment Analysis")
|
| 7 |
|
|
@@ -30,8 +35,12 @@ if st.button('Submit', type="secondary"):
|
|
| 30 |
the_youtube_id = extract_youtube_id(user_input)
|
| 31 |
if the_youtube_id:
|
| 32 |
with st.spinner("Please wait while we're loading the data..."):
|
| 33 |
-
the_data = get_all_comments(the_youtube_id)
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
st.balloons()
|
| 36 |
st.markdown(f"""<p style="color: green; padding: 0; margin: 0;">Total comments: {len(the_data)}</p>""", unsafe_allow_html=True)
|
| 37 |
for data in the_data:
|
|
@@ -42,7 +51,7 @@ if st.button('Submit', type="secondary"):
|
|
| 42 |
<p style="font-size: 18px; line-height: 1.6; color: #333; font-family: 'Arial', sans-serif;">
|
| 43 |
{data["comment"]}
|
| 44 |
</p>
|
| 45 |
-
<p style="font-size: 16px; margin-top: 15px; font-family: 'Arial', sans-serif; font-weight: bold;">
|
| 46 |
Sentiment Analysis: <span style="color: {sentiment_color}; font-size: 18px; font-weight: bold; padding: 5px 10px; background-color: {sentiment_color + "33"}; border-radius: 5px;">
|
| 47 |
{sentiment}
|
| 48 |
</span>
|
|
|
|
| 1 |
+
from helper import extract_youtube_id, get_all_comments, text_preprocessing, slang_dict
|
| 2 |
import streamlit as st
|
| 3 |
import random
|
| 4 |
import pandas as pd
|
| 5 |
+
import tensorflow as tf
|
| 6 |
+
import tensorflow_hub as tf_hub
|
| 7 |
+
|
| 8 |
+
def load_model():
|
| 9 |
+
return tf.keras.models.load_model('model_lstm.h5', custom_objects={'KerasLayer': tf_hub.KerasLayer})
|
| 10 |
|
| 11 |
st.header("💬 Youtube Comments Sentiment Analysis")
|
| 12 |
|
|
|
|
| 35 |
the_youtube_id = extract_youtube_id(user_input)
|
| 36 |
if the_youtube_id:
|
| 37 |
with st.spinner("Please wait while we're loading the data..."):
|
| 38 |
+
the_data, comment_only = get_all_comments(the_youtube_id)
|
| 39 |
+
the_comments = pd.DataFrame({"comment": comment_only})
|
| 40 |
+
the_comments['text_processed'] = the_comments['comment'].apply(lambda x: text_preprocessing(x))
|
| 41 |
+
the_comments['text_processed'] = the_comments['text_processed'].apply(lambda x: x if len(x.split()) > 0 else None)
|
| 42 |
+
the_comments = the_comments.dropna(subset=['text_processed'])
|
| 43 |
+
print(the_comments['text_processed'])
|
| 44 |
st.balloons()
|
| 45 |
st.markdown(f"""<p style="color: green; padding: 0; margin: 0;">Total comments: {len(the_data)}</p>""", unsafe_allow_html=True)
|
| 46 |
for data in the_data:
|
|
|
|
| 51 |
<p style="font-size: 18px; line-height: 1.6; color: #333; font-family: 'Arial', sans-serif;">
|
| 52 |
{data["comment"]}
|
| 53 |
</p>
|
| 54 |
+
<p style="font-size: 16px; color: gray; margin-top: 15px; font-family: 'Arial', sans-serif; font-weight: bold;">
|
| 55 |
Sentiment Analysis: <span style="color: {sentiment_color}; font-size: 18px; font-weight: bold; padding: 5px 10px; background-color: {sentiment_color + "33"}; border-radius: 5px;">
|
| 56 |
{sentiment}
|
| 57 |
</span>
|