lorenzobalestra's picture
Update app.py
7ad197c verified
raw
history blame contribute delete
950 Bytes
import gradio as gr
import requests
WEBHOOK_URL = "https://lorenzobalestra.app.n8n.cloud/webhook/ai-analyst"
def ask_analyst(question):
if not question.strip():
return "Please enter a question.", None
try:
response = requests.post(WEBHOOK_URL, json={"question": question})
data = response.json()
answer = data.get("answer", "No answer received.")
chart = data.get("chart", "none")
chart_info = f"\n\nπŸ“Š Suggested chart: **{chart}**" if chart != "none" else ""
return answer + chart_info
except Exception as e:
return f"Error: {str(e)}"
demo = gr.Interface(
fn=ask_analyst,
inputs=gr.Textbox(label="Ask a question about book sales", placeholder="e.g. What are the top selling books?"),
outputs=gr.Markdown(label="Answer"),
title="πŸ“š Book Sales Analyst",
description="Ask questions about the book sales dataset powered by AI.",
)
demo.launch()