Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -95,42 +95,27 @@ def make_chart(row, filtered_df):
|
|
| 95 |
|
| 96 |
|
| 97 |
# ββ AI explanation (rule-based, no API key needed) βββββββββ
|
|
|
|
|
|
|
| 98 |
def explain(row):
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
sentiment_word = "positive" if sent > 0.2 else ("neutral" if sent > -0.2 else "negative")
|
| 109 |
-
volatility_note = (
|
| 110 |
-
" Reviews are polarised β strong opinions on both sides."
|
| 111 |
-
if vols > 0.5 else
|
| 112 |
-
" Reviews are consistent."
|
| 113 |
-
)
|
| 114 |
-
value_note = (
|
| 115 |
-
f" At {price}, it delivers excellent value for money."
|
| 116 |
-
if pf > 0.6 else
|
| 117 |
-
f" At {price}, the price-to-experience ratio is fair."
|
| 118 |
-
if pf > 0.3 else
|
| 119 |
-
f" At {price}, some diners feel it falls short of expectations."
|
| 120 |
-
)
|
| 121 |
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
f"
|
| 131 |
-
f"{verdict} "
|
| 132 |
-
f"Customer reviews are broadly {sentiment_word} (raw sentiment: {sent:+.2f}), "
|
| 133 |
-
f"and the star rating is {stars:.1f}/5.{volatility_note}{value_note}"
|
| 134 |
)
|
| 135 |
|
| 136 |
|
|
|
|
| 95 |
|
| 96 |
|
| 97 |
# ββ AI explanation (rule-based, no API key needed) βββββββββ
|
| 98 |
+
import requests
|
| 99 |
+
|
| 100 |
def explain(row):
|
| 101 |
+
payload = {
|
| 102 |
+
"restaurant_name": row["restaurant_name"],
|
| 103 |
+
"true_score": float(row["true_score"]),
|
| 104 |
+
"worth_it_label": row["worth_it_label"],
|
| 105 |
+
"sentiment_score": float(row["sentiment_score"]),
|
| 106 |
+
"star_rating": float(row["star_rating"]),
|
| 107 |
+
"price_category": row["price_category"],
|
| 108 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
+
try:
|
| 111 |
+
r = requests.post(
|
| 112 |
+
"https://scohen3012.app.n8n.cloud/webhook/explain",
|
| 113 |
+
json=payload,
|
| 114 |
+
timeout=8
|
| 115 |
+
)
|
| 116 |
+
return r.json().get("explanation", "No explanation returned.")
|
| 117 |
+
except Exception as e:
|
| 118 |
+
return f"Explanation service unavailable: {e}"
|
|
|
|
|
|
|
|
|
|
| 119 |
)
|
| 120 |
|
| 121 |
|