eliakuassi commited on
Commit
cf14830
Β·
verified Β·
1 Parent(s): fdff980

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -21
app.py CHANGED
@@ -1,9 +1,6 @@
1
  import gradio as gr
2
  import pandas as pd
3
  import numpy as np
4
- from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
5
-
6
- analyzer = SentimentIntensityAnalyzer()
7
 
8
  restaurants = ['PastaPlace', 'BurgerHub', 'SushiBar', 'TacoLoco', 'CafeBleu']
9
 
@@ -16,32 +13,32 @@ df_sales = pd.DataFrame({
16
  })
17
 
18
  def analyze_restaurant(restaurant, review):
19
- # Sentiment analysis
20
- score = analyzer.polarity_scores(review)['compound']
21
- if score > 0.05:
 
 
 
 
 
 
22
  sentiment = "😊 Positive"
23
- elif score < -0.05:
 
24
  sentiment = "😑 Negative"
 
25
  else:
26
  sentiment = "😐 Neutral"
 
27
 
28
- # Sales stats
29
  stats = df_sales[df_sales['restaurant'] == restaurant]['revenue']
30
  avg_rev = stats.mean().round(2)
31
 
32
- # Pricing recommendation
33
- if score > 0.05 and avg_rev > 8000:
34
- recommendation = "πŸ“ˆ Increase prices by 10% - Strong performance!"
35
- elif score < -0.05:
36
- recommendation = "πŸ“‰ Improve service before adjusting prices"
37
- else:
38
- recommendation = "➑️ Keep current pricing strategy"
39
-
40
  result = f"""
41
- 🍽️ Restaurant: {restaurant}
42
- πŸ“Š Sentiment: {sentiment} (score: {score:.2f})
43
- πŸ’° Average Weekly Revenue: €{avg_rev}
44
- πŸ’‘ Recommendation: {recommendation}
45
  """
46
  return result
47
 
@@ -49,7 +46,7 @@ iface = gr.Interface(
49
  fn=analyze_restaurant,
50
  inputs=[
51
  gr.Dropdown(choices=restaurants, label="Select Restaurant"),
52
- gr.Textbox(label="Enter a customer review",
53
  placeholder="e.g. Amazing food, loved it!")
54
  ],
55
  outputs=gr.Textbox(label="Analysis & Recommendation"),
 
1
  import gradio as gr
2
  import pandas as pd
3
  import numpy as np
 
 
 
4
 
5
  restaurants = ['PastaPlace', 'BurgerHub', 'SushiBar', 'TacoLoco', 'CafeBleu']
6
 
 
13
  })
14
 
15
  def analyze_restaurant(restaurant, review):
16
+ # Simple keyword sentiment
17
+ positive_words = ['amazing', 'great', 'fantastic', 'loved', 'best', 'delicious']
18
+ negative_words = ['terrible', 'bad', 'disappointing', 'never', 'worst', 'expensive']
19
+
20
+ review_lower = review.lower()
21
+ pos = sum(w in review_lower for w in positive_words)
22
+ neg = sum(w in review_lower for w in negative_words)
23
+
24
+ if pos > neg:
25
  sentiment = "😊 Positive"
26
+ recommendation = "πŸ“ˆ Increase prices by 10% - Strong performance!"
27
+ elif neg > pos:
28
  sentiment = "😑 Negative"
29
+ recommendation = "πŸ“‰ Improve service before adjusting prices"
30
  else:
31
  sentiment = "😐 Neutral"
32
+ recommendation = "➑️ Keep current pricing strategy"
33
 
 
34
  stats = df_sales[df_sales['restaurant'] == restaurant]['revenue']
35
  avg_rev = stats.mean().round(2)
36
 
 
 
 
 
 
 
 
 
37
  result = f"""
38
+ 🍽️ Restaurant: {restaurant}
39
+ πŸ“Š Sentiment: {sentiment}
40
+ πŸ’° Average Weekly Revenue: €{avg_rev}
41
+ πŸ’‘ Recommendation: {recommendation}
42
  """
43
  return result
44
 
 
46
  fn=analyze_restaurant,
47
  inputs=[
48
  gr.Dropdown(choices=restaurants, label="Select Restaurant"),
49
+ gr.Textbox(label="Enter a customer review",
50
  placeholder="e.g. Amazing food, loved it!")
51
  ],
52
  outputs=gr.Textbox(label="Analysis & Recommendation"),