Update app.py
Browse files
app.py
CHANGED
@@ -47,16 +47,21 @@ def generate_gemini_content(transcript_text, prompt, max_length):
|
|
47 |
return summary
|
48 |
|
49 |
|
50 |
-
# Function to analyze sentiment of text
|
51 |
-
def
|
52 |
blob = TextBlob(text)
|
53 |
sentiment_score = blob.sentiment.polarity
|
54 |
if sentiment_score > 0:
|
55 |
-
|
|
|
56 |
elif sentiment_score == 0:
|
57 |
-
|
|
|
58 |
else:
|
59 |
-
|
|
|
|
|
|
|
60 |
|
61 |
|
62 |
# Streamlit app
|
@@ -82,12 +87,24 @@ if st.sidebar.button("π Perform Action"):
|
|
82 |
elif action == "Analyze Sentiment":
|
83 |
transcript_text = extract_transcript_details(youtube_link)
|
84 |
if transcript_text:
|
85 |
-
sentiment =
|
86 |
st.markdown("## Sentiment Analysis:")
|
87 |
-
st.
|
88 |
-
|
89 |
-
#
|
90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
video_id = youtube_link.split("=")[1]
|
92 |
st.image(f"http://img.youtube.com/vi/{video_id}/0.jpg", use_column_width=True)
|
93 |
else:
|
|
|
47 |
return summary
|
48 |
|
49 |
|
50 |
+
# Function to analyze sentiment of text and provide explanation
|
51 |
+
def analyze_sentiment_with_explanation(text):
|
52 |
blob = TextBlob(text)
|
53 |
sentiment_score = blob.sentiment.polarity
|
54 |
if sentiment_score > 0:
|
55 |
+
sentiment = "Positive"
|
56 |
+
explanation = "The sentiment is positive because the text contains predominantly positive language."
|
57 |
elif sentiment_score == 0:
|
58 |
+
sentiment = "Neutral"
|
59 |
+
explanation = "The sentiment is neutral as there is an equal balance of positive and negative language."
|
60 |
else:
|
61 |
+
sentiment = "Negative"
|
62 |
+
explanation = "The sentiment is negative because the text contains predominantly negative language."
|
63 |
+
|
64 |
+
return sentiment, explanation
|
65 |
|
66 |
|
67 |
# Streamlit app
|
|
|
87 |
elif action == "Analyze Sentiment":
|
88 |
transcript_text = extract_transcript_details(youtube_link)
|
89 |
if transcript_text:
|
90 |
+
sentiment, explanation = analyze_sentiment_with_explanation(transcript_text)
|
91 |
st.markdown("## Sentiment Analysis:")
|
92 |
+
st.markdown(f"The sentiment of the video is: **{sentiment}**")
|
93 |
+
|
94 |
+
# Display explanation
|
95 |
+
st.markdown("### Explanation:")
|
96 |
+
st.write(explanation)
|
97 |
+
|
98 |
+
# Adjust appearance based on sentiment
|
99 |
+
if sentiment == "Positive":
|
100 |
+
st.write(f"The sentiment of the video is: {sentiment}", unsafe_allow_html=True)
|
101 |
+
st.write('<p style="font-size: large; color: green;">The sentiment of the video is positive!</p>', unsafe_allow_html=True)
|
102 |
+
elif sentiment == "Negative":
|
103 |
+
st.write(f"The sentiment of the video is: {sentiment}", unsafe_allow_html=True)
|
104 |
+
st.write('<p style="font-size: large; color: red;">The sentiment of the video is negative!</p>', unsafe_allow_html=True)
|
105 |
+
|
106 |
+
# Show YouTube video thumbnail if link provided and action is not sentiment analysis
|
107 |
+
if youtube_link and action != "Analyze Sentiment":
|
108 |
video_id = youtube_link.split("=")[1]
|
109 |
st.image(f"http://img.youtube.com/vi/{video_id}/0.jpg", use_column_width=True)
|
110 |
else:
|