mayf commited on
Commit
601d686
·
verified ·
1 Parent(s): 3ed4c8f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -10
app.py CHANGED
@@ -31,8 +31,15 @@ def load_keybert_model():
31
  return KeyBERT(model="all-MiniLM-L6-v2")
32
 
33
  # ─── BlenderBot Response Pipeline ───────────────────────────────────────────
 
 
34
  @st.cache_resource
35
  def load_response_pipeline():
 
 
 
 
 
36
  # High-level helper using BlenderBot 400M Distill
37
  return pipeline(
38
  "text2text-generation",
@@ -100,19 +107,17 @@ def main():
100
  # Generate appropriate reply
101
  response_pipeline = load_response_pipeline()
102
  if max_label in ["Positive", "Very Positive"]:
103
- prompt = (
104
- f"You are a friendly customer success representative. The customer said: \"{review}\". "
105
- "Write a warm, appreciative reply celebrating their positive experience."
106
- )
107
  else:
108
- prompt = (
109
- f"You are a helpful customer support specialist. The customer said: \"{review}\". "
110
- f"Identified issues: {', '.join([kw for kw, _ in keywords])}. "
111
  "First, ask 1-2 clarifying questions to better understand their situation. "
112
- "Then, provide two concrete suggestions or next steps to address these issues, grounded in their feedback."
113
  )
114
- result = response_pipeline(prompt)
115
- reply = result[0]['generated_text'].strip()
 
 
116
 
117
  st.subheader("Generated Reply")
118
  st.write(reply)
@@ -120,3 +125,4 @@ def main():
120
 
121
  if __name__ == '__main__':
122
  main()
 
 
31
  return KeyBERT(model="all-MiniLM-L6-v2")
32
 
33
  # ─── BlenderBot Response Pipeline ───────────────────────────────────────────
34
+ from transformers import Conversation
35
+
36
  @st.cache_resource
37
  def load_response_pipeline():
38
+ # Use conversational pipeline for interactive-style replies
39
+ return pipeline(
40
+ "conversational",
41
+ model="facebook/blenderbot-400M-distill"
42
+ ):
43
  # High-level helper using BlenderBot 400M Distill
44
  return pipeline(
45
  "text2text-generation",
 
107
  # Generate appropriate reply
108
  response_pipeline = load_response_pipeline()
109
  if max_label in ["Positive", "Very Positive"]:
110
+ user_input = f"The customer said: \"{review}\". Write a warm, appreciative two-sentence reply celebrating their positive experience."
 
 
 
111
  else:
112
+ user_input = (
113
+ f"The customer said: \"{review}\". Identified issues: {', '.join([kw for kw, _ in keywords])}. "
 
114
  "First, ask 1-2 clarifying questions to better understand their situation. "
115
+ "Then provide two concrete suggestions or next steps to address these issues."
116
  )
117
+ conv = Conversation(user_input)
118
+ response = response_pipeline(conv)
119
+ # Grab the latest generated response
120
+ reply = response.generated_responses[-1]
121
 
122
  st.subheader("Generated Reply")
123
  st.write(reply)
 
125
 
126
  if __name__ == '__main__':
127
  main()
128
+