File size: 1,133 Bytes
a5ece8b
 
0f5aca7
 
 
887b999
0f5aca7
a5ece8b
 
0f5aca7
 
 
 
 
887b999
 
0f5aca7
 
 
6a97111
0f5aca7
67fc297
0f5aca7
 
67fc297
0f5aca7
887b999
0f5aca7
887b999
 
0f5aca7
6a97111
0f5aca7
 
887b999
a5ece8b
67fc297
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
import pandas as pd
import gradio as gr
from transformers import pipeline
from langchain.llms import HuggingFacePipeline
from langchain.agents import create_pandas_dataframe_agent

# Load your data
df = pd.read_csv("synthetic_profit.csv")

# Set up lightweight Hugging Face pipeline with Flan-T5 base
hf_pipeline = pipeline(
    task="text2text-generation",
    model="google/flan-t5-base",
    device=-1  # ensures CPU
)

# LangChain agent setup
llm = HuggingFacePipeline(pipeline=hf_pipeline)
agent = create_pandas_dataframe_agent(llm, df, verbose=True)

def answer(query: str) -> str:
    try:
        response = agent.run(query)
        return f"πŸ“Š {response}"
    except Exception as e:
        return f"❗ Error: {str(e)}"

# Gradio interface
demo = gr.Interface(
    fn=answer,
    inputs=gr.Textbox(lines=2, placeholder="E.g., 'Total revenue for Product B in EMEA', 'List products with negative profit.'"),
    outputs="text",
    title="🟒 SAP Profitability Data Chat (Flan-T5 + Pandas)",
    description="Ask questions about synthetic SAP profitability data. Powered by Flan-T5-base via Hugging Face."
)

demo.launch()