mayf commited on
Commit
5a29e86
·
verified ·
1 Parent(s): b2e17db

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -63
app.py CHANGED
@@ -1,54 +1,3 @@
1
- import os
2
- import numpy as np
3
- import pandas as pd
4
- import streamlit as st
5
- from transformers import (
6
- pipeline,
7
- AutoTokenizer,
8
- AutoModelForSequenceClassification,
9
- AutoModelForSeq2SeqLM
10
- )
11
- from keybert import KeyBERT
12
-
13
- # ─── Sentiment & Keyword Models ─────────────────────────────────────────────
14
- @st.cache_resource
15
- def load_sentiment_pipeline():
16
- model_name = "mayf/amazon_reviews_bert_ft"
17
- tok = AutoTokenizer.from_pretrained(model_name, use_auth_token=True)
18
- mdl = AutoModelForSequenceClassification.from_pretrained(
19
- model_name,
20
- use_auth_token=True
21
- )
22
- return pipeline(
23
- "sentiment-analysis",
24
- model=mdl,
25
- tokenizer=tok,
26
- return_all_scores=True
27
- )
28
-
29
- @st.cache_resource
30
- def load_keybert_model():
31
- return KeyBERT(model="all-MiniLM-L6-v2")
32
-
33
- # ─── FLAN-T5 Generation Pipeline ────────────────────────────────────────────
34
- @st.cache_resource
35
- def load_flant5_pipeline():
36
- seq_tok = AutoTokenizer.from_pretrained("google/flan-t5-base")
37
- seq_model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-base")
38
- return pipeline(
39
- "text2text-generation",
40
- model=seq_model,
41
- tokenizer=seq_tok,
42
- max_new_tokens=300,
43
- do_sample=True,
44
- temperature=0.7
45
- )
46
-
47
- LABEL_MAP = {
48
- "LABEL_0": "Very Negative",
49
- "LABEL_1": "Negative",
50
- "LABEL_2": "Neutral",
51
- "LABEL_3": "Positive",
52
  "LABEL_4": "Very Positive"
53
  }
54
 
@@ -122,18 +71,9 @@ You are a senior product quality and customer experience specialist at an e-comm
122
  Customer Review:
123
  "{review}"
124
 
125
- Please analyze this feedback and provide **three** distinct, actionable improvement recommendations designed to reduce customer pain points.
126
- For each recommendation, include:
127
- 1. **Recommendation Title**: a concise summary of the action.
128
- 2. The specific issue or frustration extracted from the review.
129
- 3. Why this action addresses the pain point and how it will improve the customer experience.
130
- 4. A bullet-point list of 3–5 clear steps for operations or product teams to execute.
131
- 5. How to measure the impact.
132
-
133
- Write each recommendation in at least 5–7 sentences, grounding every detail in the customer's own words. Avoid generic advice—focus on specifics from the review.
134
 
135
- Recommendations:
136
- """
137
  response = generation_pipeline(prompt)
138
  detailed = response[0]["generated_text"]
139
  st.markdown(detailed)
@@ -148,4 +88,3 @@ Recommendations:
148
  if __name__ == "__main__":
149
  main()
150
 
151
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  "LABEL_4": "Very Positive"
2
  }
3
 
 
71
  Customer Review:
72
  "{review}"
73
 
74
+ Instructions: Analyze the feedback and provide three distinct, actionable improvement recommendations. For each, include a concise title and a detailed explanation in 5–7 sentences, plus a bullet list of 3–5 execution steps and a measure of impact.
 
 
 
 
 
 
 
 
75
 
76
+ **Output only the recommendations as numbered items (1–3).*"""
 
77
  response = generation_pipeline(prompt)
78
  detailed = response[0]["generated_text"]
79
  st.markdown(detailed)
 
88
  if __name__ == "__main__":
89
  main()
90