Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
# Load synthetic data
|
| 7 |
+
df = pd.read_csv("synthetic_profit.csv")
|
| 8 |
+
|
| 9 |
+
# Initialize TAPAS QA pipeline
|
| 10 |
+
qa = pipeline(
|
| 11 |
+
"table-question-answering",
|
| 12 |
+
model="google/tapas-base-finetuned-sqa",
|
| 13 |
+
tokenizer="google/tapas-base-finetuned-sqa"
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
def answer(query: str) -> str:
|
| 17 |
+
res = qa(table=df, query=query)
|
| 18 |
+
return f"**Answer:** {res['answer']} _(agg: {res['aggregate']})_"
|
| 19 |
+
|
| 20 |
+
demo = gr.Interface(
|
| 21 |
+
fn=answer,
|
| 22 |
+
inputs=gr.Textbox(lines=2, placeholder="e.g. What was profit margin for Product B in EMEA Q2 2024?"),
|
| 23 |
+
outputs="markdown",
|
| 24 |
+
title="S/4HANA Profitability Chat",
|
| 25 |
+
description="Ask questions of synthetic S/4HANA data using TAPAS"
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
if __name__ == "__main__":
|
| 29 |
+
demo.launch()
|