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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -1
app.py CHANGED
@@ -1,3 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  "LABEL_4": "Very Positive"
2
  }
3
 
@@ -73,7 +124,8 @@ Customer 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)
 
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
 
 
124
 
125
  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.
126
 
127
+ Output only the three numbered recommendations (1–3), each with its title, detailed explanation, steps, and impact measure.
128
+ """
129
  response = generation_pipeline(prompt)
130
  detailed = response[0]["generated_text"]
131
  st.markdown(detailed)