Update app.py
Browse files
app.py
CHANGED
@@ -30,6 +30,14 @@ def load_sentiment_pipeline():
|
|
30 |
def load_keybert_model():
|
31 |
return KeyBERT(model="all-MiniLM-L6-v2")
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
def main():
|
35 |
st.title("📊 Review Analyzer")
|
@@ -52,8 +60,9 @@ def main():
|
|
52 |
|
53 |
# Run sentiment analysis
|
54 |
progress.text("Analyzing sentiment...")
|
55 |
-
|
56 |
-
|
|
|
57 |
progress.progress(40)
|
58 |
|
59 |
# Extract keywords
|
@@ -79,7 +88,7 @@ def main():
|
|
79 |
# Bar chart
|
80 |
progress.text("Rendering chart...")
|
81 |
df_scores = pd.DataFrame.from_dict(sentiment_results, orient='index', columns=['score'])
|
82 |
-
df_scores.index.name = '
|
83 |
st.bar_chart(df_scores)
|
84 |
progress.progress(80)
|
85 |
|
@@ -95,8 +104,8 @@ Review: \"{review}\"
|
|
95 |
Sentiment Scores: {sentiment_results}
|
96 |
Top Keywords: {[kw for kw, _ in keywords]}
|
97 |
Tasks:
|
98 |
-
1. Write a concise paragraph (
|
99 |
-
2. Provide 3 actionable suggestions with brief explanations (up to
|
100 |
"""
|
101 |
|
102 |
response = openai_client.chat.completions.create(
|
@@ -116,4 +125,4 @@ Tasks:
|
|
116 |
progress.text("Done!")
|
117 |
|
118 |
if __name__ == "__main__":
|
119 |
-
main()
|
|
|
30 |
def load_keybert_model():
|
31 |
return KeyBERT(model="all-MiniLM-L6-v2")
|
32 |
|
33 |
+
LABEL_MAP = {
|
34 |
+
"LABEL_0": "Very Negative",
|
35 |
+
"LABEL_1": "Negative",
|
36 |
+
"LABEL_2": "Neutral",
|
37 |
+
"LABEL_3": "Positive",
|
38 |
+
"LABEL_4": "Very Positive"
|
39 |
+
}
|
40 |
+
|
41 |
|
42 |
def main():
|
43 |
st.title("📊 Review Analyzer")
|
|
|
60 |
|
61 |
# Run sentiment analysis
|
62 |
progress.text("Analyzing sentiment...")
|
63 |
+
raw_scores = sentiment_pipeline(review)[0]
|
64 |
+
# Map labels
|
65 |
+
sentiment_results = {LABEL_MAP[item['label']]: float(item['score']) for item in raw_scores}
|
66 |
progress.progress(40)
|
67 |
|
68 |
# Extract keywords
|
|
|
88 |
# Bar chart
|
89 |
progress.text("Rendering chart...")
|
90 |
df_scores = pd.DataFrame.from_dict(sentiment_results, orient='index', columns=['score'])
|
91 |
+
df_scores.index.name = 'Sentiment'
|
92 |
st.bar_chart(df_scores)
|
93 |
progress.progress(80)
|
94 |
|
|
|
104 |
Sentiment Scores: {sentiment_results}
|
105 |
Top Keywords: {[kw for kw, _ in keywords]}
|
106 |
Tasks:
|
107 |
+
1. Write a concise paragraph (3 sentences) interpreting customer sentiment by combining the scores and keywords.
|
108 |
+
2. Provide 3 actionable suggestions with brief explanations (up to 4 sentences each).
|
109 |
"""
|
110 |
|
111 |
response = openai_client.chat.completions.create(
|
|
|
125 |
progress.text("Done!")
|
126 |
|
127 |
if __name__ == "__main__":
|
128 |
+
main()
|