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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -4
app.py CHANGED
@@ -1,4 +1,60 @@
1
- gradio
2
- vaderSentiment
3
- pandas
4
- numpy
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
10
+ np.random.seed(42)
11
+ df_sales = pd.DataFrame({
12
+ 'restaurant': np.repeat(restaurants, 20),
13
+ 'week': list(range(1, 21)) * 5,
14
+ 'revenue': np.random.randint(3000, 15000, 100),
15
+ 'avg_price': np.random.uniform(12, 45, 100).round(2)
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
+
48
+ 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"),
56
+ title="🍽️ Restaurant Performance Analyzer",
57
+ description="Analyze customer sentiment and get pricing recommendations"
58
+ )
59
+
60
+ iface.launch()