smtsead commited on
Commit
61e280e
·
verified ·
1 Parent(s): 5527a48

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -17
app.py CHANGED
@@ -1,7 +1,7 @@
1
  """
2
- Hotel Review Analysis System for The Mira Hong Kong
3
  ISOM5240 Group Project
4
- Automatically analyzes guest reviews in multiple languages, performs sentiment
5
  analysis and aspect detection, then generates professional responses.
6
  """
7
 
@@ -70,7 +70,7 @@ aspect_responses = {
70
  "view": "It's wonderful to hear you appreciated the stunning views of Victoria Harbour from your room.",
71
  "room comfort": "Our team is thrilled you found your room comfortable and well-appointed for your needs.",
72
  "room cleanliness": "Your commendation of our cleanliness standards means a great deal to our housekeeping team who work diligently to maintain our high standards.",
73
- "staff service": "Your kind words about our team, especially {staff_name}, have been shared with them and are greatly appreciated.",
74
  "reception": "We're pleased our front desk team made your arrival and departure experience seamless and welcoming.",
75
  "spa": "Our spa practitioners will be delighted you enjoyed their treatments and the relaxing ambiance of our wellness center.",
76
  "pool": "We're glad you had a refreshing time at our rooftop pool with its panoramic city views.",
@@ -188,28 +188,22 @@ def detect_aspects(text, aspect_classifier):
188
  return []
189
 
190
  def generate_response(sentiment, aspects, original_text):
191
- # Personalization
192
  guest_name = ""
193
- staff_name = ""
194
  name_match = re.search(r"(Mr\.|Ms\.|Mrs\.)\s(\w+)", original_text, re.IGNORECASE)
195
- staff_match = re.search(r"(receptionist|manager|concierge|chef)\s(\w+)", original_text, re.IGNORECASE)
196
 
197
  if name_match:
198
  guest_name = f" {name_match.group(2)}"
199
- if staff_match:
200
- staff_name = staff_match.group(2)
201
 
202
  if sentiment['label'] == 1:
203
  response = f"""Dear{guest_name if guest_name else ' Valued Guest'},
204
- Thank you for choosing The Mira Hong Kong and for sharing your kind feedback with us."""
205
 
206
  # Add relevant aspect responses
207
  added_aspects = set()
208
  for aspect, _ in sorted(aspects, key=lambda x: float(x[1][:-1]), reverse=True):
209
  if aspect in aspect_responses:
210
  response_text = aspect_responses[aspect]
211
- if "{staff_name}" in response_text and staff_name:
212
- response_text = response_text.format(staff_name=staff_name)
213
  response += "\n\n" + response_text
214
  added_aspects.add(aspect)
215
  if len(added_aspects) >= 3:
@@ -240,8 +234,7 @@ Thank you for taking the time to share your feedback with us. We sincerely regre
240
 
241
  Should you require any further assistance, please don't hesitate to contact our Guest Relations team.
242
  Sincerely yours,
243
- Sam Tse
244
- Guest Relations Manager
245
  The Mira Hong Kong
246
  +852 1234 5678 | [email protected]"""
247
 
@@ -250,7 +243,7 @@ The Mira Hong Kong
250
  # ===== STREAMLIT UI =====
251
  def main():
252
  st.set_page_config(
253
- page_title="Mira Review Assistant",
254
  page_icon="🏨",
255
  layout="centered"
256
  )
@@ -267,8 +260,8 @@ def main():
267
  </style>
268
  """, unsafe_allow_html=True)
269
 
270
- st.markdown('<div class="header">The Mira Hong Kong</div>', unsafe_allow_html=True)
271
- st.markdown('<div class="subheader">Guest Review Analysis System</div>', unsafe_allow_html=True)
272
 
273
  review = st.text_area("**Paste Guest Review:**",
274
  height=200,
@@ -317,7 +310,7 @@ def main():
317
 
318
  sentiment = analyze_sentiment(analysis_text, sentiment_model, tokenizer)
319
  aspects = detect_aspects(analysis_text, aspect_classifier)
320
- response = generate_response(sentiment, aspects, review) # Use original text for name extraction
321
 
322
  # Translate response back if needed
323
  if review_lang != 'en':
 
1
  """
2
+ Hotel Review Analysis and Response System
3
  ISOM5240 Group Project
4
+ Automatically analyzes hotel guest reviews in multiple languages, performs sentiment
5
  analysis and aspect detection, then generates professional responses.
6
  """
7
 
 
70
  "view": "It's wonderful to hear you appreciated the stunning views of Victoria Harbour from your room.",
71
  "room comfort": "Our team is thrilled you found your room comfortable and well-appointed for your needs.",
72
  "room cleanliness": "Your commendation of our cleanliness standards means a great deal to our housekeeping team who work diligently to maintain our high standards.",
73
+ "staff service": "Your kind words about our team have been shared with them and are greatly appreciated.",
74
  "reception": "We're pleased our front desk team made your arrival and departure experience seamless and welcoming.",
75
  "spa": "Our spa practitioners will be delighted you enjoyed their treatments and the relaxing ambiance of our wellness center.",
76
  "pool": "We're glad you had a refreshing time at our rooftop pool with its panoramic city views.",
 
188
  return []
189
 
190
  def generate_response(sentiment, aspects, original_text):
191
+ # Personalization - only extract guest name
192
  guest_name = ""
 
193
  name_match = re.search(r"(Mr\.|Ms\.|Mrs\.)\s(\w+)", original_text, re.IGNORECASE)
 
194
 
195
  if name_match:
196
  guest_name = f" {name_match.group(2)}"
 
 
197
 
198
  if sentiment['label'] == 1:
199
  response = f"""Dear{guest_name if guest_name else ' Valued Guest'},
200
+ Thank you for choosing our hotel and for sharing your kind feedback with us."""
201
 
202
  # Add relevant aspect responses
203
  added_aspects = set()
204
  for aspect, _ in sorted(aspects, key=lambda x: float(x[1][:-1]), reverse=True):
205
  if aspect in aspect_responses:
206
  response_text = aspect_responses[aspect]
 
 
207
  response += "\n\n" + response_text
208
  added_aspects.add(aspect)
209
  if len(added_aspects) >= 3:
 
234
 
235
  Should you require any further assistance, please don't hesitate to contact our Guest Relations team.
236
  Sincerely yours,
237
+ Guest Relations Team
 
238
  The Mira Hong Kong
239
  +852 1234 5678 | [email protected]"""
240
 
 
243
  # ===== STREAMLIT UI =====
244
  def main():
245
  st.set_page_config(
246
+ page_title="Hotel Review Analysis and Response System",
247
  page_icon="🏨",
248
  layout="centered"
249
  )
 
260
  </style>
261
  """, unsafe_allow_html=True)
262
 
263
+ st.markdown('<div class="header">Hotel Review Analysis and Response System</div>', unsafe_allow_html=True)
264
+ st.markdown('<div class="subheader">The Mira Hong Kong</div>', unsafe_allow_html=True)
265
 
266
  review = st.text_area("**Paste Guest Review:**",
267
  height=200,
 
310
 
311
  sentiment = analyze_sentiment(analysis_text, sentiment_model, tokenizer)
312
  aspects = detect_aspects(analysis_text, aspect_classifier)
313
+ response = generate_response(sentiment, aspects, review)
314
 
315
  # Translate response back if needed
316
  if review_lang != 'en':