Spaces:
Sleeping
Sleeping
Download app.py from samirpeobz/excel-chatbot: direct link, hf CLI and curl.
- Browser
- Download file 870 Bytes
-
https://huggingface.co/spaces/samirpeobz/excel-chatbot/resolve/main/app.py
- Command line
-
hf download hf://spaces/samirpeobz/excel-chatbot/app.py
-
curl -L -o app.py https://huggingface.co/spaces/samirpeobz/excel-chatbot/resolve/main/app.py
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() | |