Matteo08 commited on
Commit
85b56ac
·
verified ·
1 Parent(s): 37cffe4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -27,7 +27,7 @@ def analyze_book(title, reviews_text, avg_units_sold):
27
  if not title or not reviews_text:
28
  return "⚠️ Please enter a title and at least one review.", "", None
29
 
30
- url = "https://matteoadam.app.n8n.cloud/webhook-test/price-decider"
31
 
32
  payload = {
33
  "title": title,
@@ -37,14 +37,20 @@ def analyze_book(title, reviews_text, avg_units_sold):
37
 
38
  try:
39
  response = requests.post(url, json=payload)
 
 
 
 
 
 
40
 
41
  summary = (
42
  f"📚 {title}\n\n"
43
- f"Status code: {response.status_code}\n\n"
44
- f"Raw response:\n{response.text}"
45
  )
46
 
47
- return summary, "Debug mode", None
48
 
49
  except Exception as e:
50
  return f"Error: {str(e)}", "Request failed", None
 
27
  if not title or not reviews_text:
28
  return "⚠️ Please enter a title and at least one review.", "", None
29
 
30
+ url = "https://matteoadam.app.n8n.cloud/webhook/price-decider"
31
 
32
  payload = {
33
  "title": title,
 
37
 
38
  try:
39
  response = requests.post(url, json=payload)
40
+ data = response.json()
41
+
42
+ if isinstance(data, list) and len(data) > 0:
43
+ result = data[0]
44
+ else:
45
+ result = data
46
 
47
  summary = (
48
  f"📚 {title}\n\n"
49
+ f"Pricing Decision: {result.get('pricing_decision', 'Error')}\n"
50
+ f"Sentiment: {result.get('sentiment', 'N/A')}"
51
  )
52
 
53
+ return summary, "Processed via n8n", None
54
 
55
  except Exception as e:
56
  return f"Error: {str(e)}", "Request failed", None