Update app.py
Browse files
app.py
CHANGED
@@ -33,11 +33,17 @@ def load_keybert_model():
|
|
33 |
# ─── FLAN-T5 Generation Pipeline ────────────────────────────────────────────
|
34 |
@st.cache_resource
|
35 |
def load_flant5_pipeline():
|
36 |
-
#
|
|
|
|
|
37 |
return pipeline(
|
38 |
"text2text-generation",
|
39 |
-
model=
|
40 |
-
tokenizer=
|
|
|
|
|
|
|
|
|
41 |
)
|
42 |
|
43 |
LABEL_MAP = {
|
@@ -119,20 +125,17 @@ def main():
|
|
119 |
# FLAN-T5 Analysis & Suggestions
|
120 |
progress.text("Generating insights...")
|
121 |
prompt = f"""
|
122 |
-
You are an analytical
|
123 |
Review: \"{review}\"
|
124 |
Sentiment Scores: {sentiment_results}
|
125 |
Top Keywords: {[kw for kw, _ in keywords]}
|
126 |
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
"""
|
131 |
-
|
132 |
-
|
133 |
-
max_length=200,
|
134 |
-
do_sample=False
|
135 |
-
)[0]['generated_text']
|
136 |
st.markdown(output)
|
137 |
|
138 |
# Done
|
|
|
33 |
# ─── FLAN-T5 Generation Pipeline ────────────────────────────────────────────
|
34 |
@st.cache_resource
|
35 |
def load_flant5_pipeline():
|
36 |
+
# Explicitly load the Seq2Seq model & tokenizer to avoid truncation/classification fallback
|
37 |
+
seq_tok = AutoTokenizer.from_pretrained("google/flan-t5-base")
|
38 |
+
seq_model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-base")
|
39 |
return pipeline(
|
40 |
"text2text-generation",
|
41 |
+
model=seq_model,
|
42 |
+
tokenizer=seq_tok,
|
43 |
+
# ensure we generate up to 200 new tokens
|
44 |
+
max_new_tokens=200,
|
45 |
+
do_sample=True,
|
46 |
+
temperature=0.7
|
47 |
)
|
48 |
|
49 |
LABEL_MAP = {
|
|
|
125 |
# FLAN-T5 Analysis & Suggestions
|
126 |
progress.text("Generating insights...")
|
127 |
prompt = f"""
|
128 |
+
You are an analytical Amazon feedback expert.
|
129 |
Review: \"{review}\"
|
130 |
Sentiment Scores: {sentiment_results}
|
131 |
Top Keywords: {[kw for kw, _ in keywords]}
|
132 |
|
133 |
+
Please complete the following:
|
134 |
+
- ANALYSIS: A concise paragraph (3 sentences) interpreting customer sentiment.
|
135 |
+
- RECOMMENDATIONS: Three separate paragraphs with actionable suggestions (max 30 words each).
|
136 |
"""
|
137 |
+
response = generation_pipeline(prompt)
|
138 |
+
output = response[0]["generated_text"]
|
|
|
|
|
|
|
139 |
st.markdown(output)
|
140 |
|
141 |
# Done
|