excel-chatbot / app.py
samirpeobz's picture
Update app.py
fa6e093 verified
Raw History Blame Contribute Delete
870 Bytes
import gradio as gr
import pandas as pd
from transformers import pipeline
# Load lightweight hosted model
llm = pipeline("text2text-generation", model="google/flan-t5-base")
def chat(file, question):
if file is None or not question:
return "Please upload an Excel file and ask a question."
df = pd.read_excel(file.name)
context = df.head(10).to_string(index=False)
prompt = f"Given this table:\n{context}\n\nQuestion: {question}"
result = llm(prompt, max_new_tokens=200)[0]["generated_text"]
return result.strip()
demo = gr.Interface(
fn=chat,
inputs=[gr.File(label="Upload Excel File"), gr.Textbox(label="Ask a Question")],
outputs=gr.Textbox(label="Answer"),
title="Excel Q&A Chatbot",
description="Ask questions from your Excel sheet using an open-source model."
)
if __name__ == "__main__":
demo.launch()