Spaces:
Sleeping
Sleeping
File size: 2,475 Bytes
fdff980 cddfcbb fdff980 cddfcbb fdff980 cddfcbb fdff980 cf14830 fdff980 cf14830 fdff980 cddfcbb fdff980 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | import gradio as gr
import pandas as pd
import numpy as np
import requests
WEBHOOK_URL = "https://eliabigdata.app.n8n.cloud/webhook/restaurant-analyzer"
restaurants = ['PastaPlace', 'BurgerHub', 'SushiBar', 'TacoLoco', 'CafeBleu']
np.random.seed(42)
df_sales = pd.DataFrame({
'restaurant': np.repeat(restaurants, 20),
'week': list(range(1, 21)) * 5,
'revenue': np.random.randint(3000, 15000, 100),
'avg_price': np.random.uniform(12, 45, 100).round(2)
})
def analyze_restaurant(restaurant, review):
try:
# Send to n8n webhook
response = requests.post(WEBHOOK_URL, json={
"restaurant": restaurant,
"review": review
}, timeout=10)
if response.status_code == 200:
data = response.json()
sentiment = data.get('sentiment', 'Neutral')
recommendation = data.get('recommendation', 'Keep current strategy')
else:
raise Exception("Webhook error")
except:
# Fallback local analysis
positive_words = ['amazing', 'great', 'fantastic', 'loved', 'best', 'delicious']
negative_words = ['terrible', 'bad', 'disappointing', 'never', 'worst', 'expensive']
review_lower = review.lower()
pos = sum(w in review_lower for w in positive_words)
neg = sum(w in review_lower for w in negative_words)
if pos > neg:
sentiment = "Positive"
recommendation = "Increase prices by 10%"
elif neg > pos:
sentiment = "Negative"
recommendation = "Improve service first"
else:
sentiment = "Neutral"
recommendation = "Keep current strategy"
stats = df_sales[df_sales['restaurant'] == restaurant]['revenue']
avg_rev = stats.mean().round(2)
result = f"""
🍽️ Restaurant: {restaurant}
📊 Sentiment: {sentiment}
💰 Average Weekly Revenue: €{avg_rev}
💡 Recommendation: {recommendation}
"""
return result
iface = gr.Interface(
fn=analyze_restaurant,
inputs=[
gr.Dropdown(choices=restaurants, label="Select Restaurant"),
gr.Textbox(label="Enter a customer review",
placeholder="e.g. Amazing food, loved it!")
],
outputs=gr.Textbox(label="Analysis & Recommendation"),
title="🍽️ Restaurant Performance Analyzer",
description="Analyze customer sentiment via n8n webhook and get pricing recommendations"
)
iface.launch() |