Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
#
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
sentiment = "π Positive"
|
| 23 |
-
|
|
|
|
| 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 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 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"),
|