Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,60 @@
|
|
| 1 |
-
gradio
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|