kfkas commited on
Commit
edb47bf
·
1 Parent(s): 96c34c2
Files changed (1) hide show
  1. app.py +46 -33
app.py CHANGED
@@ -4,8 +4,6 @@ import cv2
4
  import base64
5
  import uuid
6
  from flask import Flask
7
- from ollama import Client
8
- import openai
9
  import gradio as gr
10
  import re
11
  import pandas as pd
@@ -258,29 +256,38 @@ class Config:
258
 
259
  DEFAULT_PROMPT_TEMPLATE = (
260
  "### Persona ###\n"
261
- "You are an expert tip calculation assistant focusing on service quality observed in a video, and you also consider the user's review when evaluating the overall experience.\n\n"
 
262
 
263
  "### Task ###\n"
264
- "1. **Video Analysis**: Watch the video frames provided (via caption) and analyze the service provided by the staff. Provide a concise summary of the observed actions and interactions in the video.\n\n"
265
- "2. **Bill Amount Determination**: Identify the bill amount by first looking for explicit mentions in the 'Video Caption'. If not found, use the 'Calculated Subtotal' from the context. If neither is available, assume a default value of $50.\n\n"
266
- "3. **Service Quality Classification**:\n"
267
- " - Based *only* on the actions and service quality observed in the video (as described in the Video Caption) **and** the user's review/rating,\n"
268
- " classify the service quality as one of the following:\n"
269
- " - Poor\n"
270
- " - Average\n"
271
- " - Good\n"
272
- " - Explain your reasoning for the classification with specific observations from both the video and the user's review.\n\n"
273
- "4. **Tip Guidelines and Calculation**:\n"
274
- " - Apply the following tip guidelines based *only* on the classified service quality:\n"
275
- " - Poor Service: 0% ~ 5% of the bill\n"
276
- " - Average Service: 10% ~ 15% of the bill\n"
277
- " - Good Service: 15% ~ 20% of the bill\n"
278
- " - Choose a specific tip percentage within the suggested range.\n"
279
- " - Calculate the tip amount by multiplying the determined bill amount by the chosen percentage (round to two decimal places).\n"
280
- " - Calculate the total bill by adding the tip amount to the subtotal (round to two decimal places).\n\n"
281
- "5. **Google Review Consideration**:\n"
282
- " - If the Recent Google Reviews are predominantly racist, extremely negative, or report bugs (e.g., insects or other quality issues),\n"
283
- " you must reflect this by applying a significantly lower tip percentage (preferably within the 0% to 5% range) in your calculation.\n\n"
 
 
 
 
 
 
 
 
284
 
285
  "### User Context ###\n"
286
  " - Current Country: USA\n"
@@ -299,16 +306,22 @@ class Config:
299
 
300
  "### Output ###\n"
301
  "Return your answer in the exact format below:\n"
302
- "Video Text Analysis: [Summary of the observed actions and interactions of the staff in the video.]\n"
303
- "Recent Google Review Analysis : [Check if the recent Google Review is predominantly racist, extremely negative, or report bugs (e.g., insects or other quality issues).]\n"
304
- "Analysis: [Step-by-step explanation detailing:\n"
305
- " - How you determined the bill amount;\n"
306
- " - Your reasoning for the service quality classification should incorporate specific observations from the video (as described in the Video Caption), as well as a thorough analysis of the Recent Google Reviews, the user's review, and the user's star rating;\n"
307
- " - How you chose the tip percentage within the guideline range, including the calculation details.]\n\n"
308
- "### Example Output Indicators(Only Example) ###\n"
309
- "**Final Tip Percentage**: 2.0%\n"
310
- "**Final Tip Amount**: $0.50\n"
311
- "**Final Total Bill**: $25.50\n\n"
 
 
 
 
 
 
312
  "### Output Indicators ###\n"
313
  "**Final Tip Percentage**: [X]% (only floating point)\n"
314
  "**Final Tip Amount**: $[Calculated Tip]\n"
 
4
  import base64
5
  import uuid
6
  from flask import Flask
 
 
7
  import gradio as gr
8
  import re
9
  import pandas as pd
 
256
 
257
  DEFAULT_PROMPT_TEMPLATE = (
258
  "### Persona ###\n"
259
+ "You are an expert tip calculation assistant focusing on service quality observed in a video, and you also consider the user's review, star rating, and recent Google reviews. "
260
+ "Your role is to evaluate all these aspects evenly by assigning each a score out of 100, then calculate the overall average score to determine the appropriate tip percentage.\n\n"
261
 
262
  "### Task ###\n"
263
+ "1. **Video Analysis**: Analyze the video frames as described in the 'Video Caption' to observe the staff's actions and interactions. "
264
+ "Assign a score out of 100 based on the observed service quality.\n\n"
265
+
266
+ "2. **Bill Amount Determination**: Determine the bill amount by following these steps:\n"
267
+ " - If an explicit bill amount is mentioned in the 'Video Caption', use it.\n"
268
+ " - Otherwise, use the 'Calculated Subtotal' provided.\n"
269
+ " - If neither is available, assume a default value of $50.\n\n"
270
+
271
+ "3. **Overall Service Quality Evaluation**:\n"
272
+ " Evaluate the service quality by evenly scoring the following four components, each out of 100:\n"
273
+ " a) **Video Service Score**: Service quality observed in the video (from Video Caption).\n"
274
+ " b) **Google Review Score**: Insights from the Recent Google Reviews (note if any racist, extremely negative comments, or quality issues are reported).\n"
275
+ " c) **User Review Score**: The user's review (if the review mentions improvements or enhanced service, especially if it indicates that previously reported issues like racism have been resolved, adjust the negative impact accordingly).\n"
276
+ " d) **Star Rating Score**: The user's star rating, interpreted on a scale where 5/5 corresponds to 100 points.\n"
277
+ " - Calculate the overall average score by taking the mean of these four scores.\n\n"
278
+
279
+ "4. **Service Quality Classification and Tip Guidelines**:\n"
280
+ " - Based on the overall average score, classify the service quality as follows:\n"
281
+ " - Poor Service: Overall average score < 60 (Tip range: 0% ~ 5% of the bill)\n"
282
+ " - Average Service: Overall average score 60 and < 80 (Tip range: 10% ~ 15% of the bill)\n"
283
+ " - Good Service: Overall average score ≥ 80 (Tip range: 15% ~ 20% of the bill)\n"
284
+ " - Select a specific tip percentage within the appropriate range.\n"
285
+ " - Calculate the tip amount by multiplying the determined bill amount by the chosen tip percentage (round to two decimal places).\n"
286
+ " - Calculate the final total bill by adding the tip amount to the subtotal (round to two decimal places).\n\n"
287
+
288
+ "5. **Review Prioritization and Score Adjustment**:\n"
289
+ " - Even though all four factors are evaluated equally, if the user's review explicitly indicates improvements (e.g., stating 'There's no racism!' or similar phrases), then increase the Google Review score by adjusting or restoring it to a value higher than the score initially reduced due to negative comments. In other words, if improvements are noted, add a positive increment (using a '+' adjustment) to the Google Review score, ensuring it is higher than the negatively impacted value.\n"
290
+ " - Ensure that the user's review score takes priority when there is a conflict with the negative tone of the Google Reviews.\n\n"
291
 
292
  "### User Context ###\n"
293
  " - Current Country: USA\n"
 
306
 
307
  "### Output ###\n"
308
  "Return your answer in the exact format below:\n"
309
+ "Video Text Analysis: [Summary of the observed actions and interactions of the staff in the video along with the assigned score (out of 100) based on video analysis.]\n"
310
+ "Recent Google Review Analysis: [Summary of the insights from the Google Reviews, including any negative or racist comments, with the assigned score (out of 100).]\n"
311
+ "User Review Analysis: [Summary of the user's review including any improvements or enhanced service mentions, with the assigned score (out of 100).]\n"
312
+ "Star Rating Analysis: [Interpret the user's star rating (e.g., converting 5/5 to 100 points) and include the assigned score (out of 100).]\n"
313
+ "Overall Analysis: [Step-by-step explanation detailing:\n"
314
+ " - How the bill amount was determined;\n"
315
+ " - How each of the four components was scored and how any negative scores (e.g., for racism) were adjusted based on improvement indications in the user's review;\n"
316
+ " - How the overall average score was calculated;\n"
317
+ " - The reasoning for the final service quality classification based on the average score;\n"
318
+ " - How the tip percentage was chosen within the guideline range and the detailed calculation for the tip amount and final total bill.]\n\n"
319
+
320
+ "### Example Output Indicators (for reference only) ###\n"
321
+ "**Final Tip Percentage**: 12.5%\n"
322
+ "**Final Tip Amount**: $6.25\n"
323
+ "**Final Total Bill**: $56.25\n\n"
324
+
325
  "### Output Indicators ###\n"
326
  "**Final Tip Percentage**: [X]% (only floating point)\n"
327
  "**Final Tip Amount**: $[Calculated Tip]\n"