Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,31 +2,26 @@ import gradio as gr
|
|
| 2 |
import pandas as pd
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
-
# Load
|
| 6 |
llm = pipeline("text2text-generation", model="google/flan-t5-base")
|
| 7 |
|
| 8 |
-
def
|
| 9 |
if file is None or not question:
|
| 10 |
-
return "Please upload an Excel file and
|
| 11 |
|
| 12 |
df = pd.read_excel(file.name)
|
| 13 |
context = df.head(10).to_string(index=False)
|
| 14 |
-
prompt = f"Given
|
| 15 |
-
|
| 16 |
-
return
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
output_text = gr.Textbox(label="Answer")
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
return demo
|
| 31 |
-
|
| 32 |
-
demo = build_ui()
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
+
# Load lightweight hosted model
|
| 6 |
llm = pipeline("text2text-generation", model="google/flan-t5-base")
|
| 7 |
|
| 8 |
+
def chat(file, question):
|
| 9 |
if file is None or not question:
|
| 10 |
+
return "Please upload an Excel file and ask a question."
|
| 11 |
|
| 12 |
df = pd.read_excel(file.name)
|
| 13 |
context = df.head(10).to_string(index=False)
|
| 14 |
+
prompt = f"Given this table:\n{context}\n\nQuestion: {question}"
|
| 15 |
+
result = llm(prompt, max_new_tokens=200)[0]["generated_text"]
|
| 16 |
+
return result.strip()
|
| 17 |
|
| 18 |
+
demo = gr.Interface(
|
| 19 |
+
fn=chat,
|
| 20 |
+
inputs=[gr.File(label="Upload Excel File"), gr.Textbox(label="Ask a Question")],
|
| 21 |
+
outputs=gr.Textbox(label="Answer"),
|
| 22 |
+
title="Excel Q&A Chatbot",
|
| 23 |
+
description="Ask questions from your Excel sheet using an open-source model."
|
| 24 |
+
)
|
|
|
|
| 25 |
|
| 26 |
+
if __name__ == "__main__":
|
| 27 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|