Update app.py
Browse files
app.py
CHANGED
|
@@ -1,34 +1,36 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from gradio_spreadsheetcomponent import SpreadsheetComponent
|
| 3 |
-
from dotenv import load_dotenv
|
| 4 |
-
import os
|
| 5 |
-
import pandas as pd
|
| 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 |
-
submit_button
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from gradio_spreadsheetcomponent import SpreadsheetComponent
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
import os
|
| 5 |
+
import pandas as pd
|
| 6 |
+
from huggingface_hub import login
|
| 7 |
+
|
| 8 |
+
def answer_question(file, question):
|
| 9 |
+
if not file or not question:
|
| 10 |
+
return "Please upload a file and enter a question."
|
| 11 |
+
|
| 12 |
+
# Load the spreadsheet data
|
| 13 |
+
df = pd.read_excel(file.name)
|
| 14 |
+
|
| 15 |
+
# Create a SpreadsheetComponent instance
|
| 16 |
+
spreadsheet = SpreadsheetComponent(value=df)
|
| 17 |
+
|
| 18 |
+
# Use the component to answer the question
|
| 19 |
+
return spreadsheet.answer_question(question)
|
| 20 |
+
|
| 21 |
+
with gr.Blocks() as demo:
|
| 22 |
+
gr.Markdown("# Spreadsheet Question Answering")
|
| 23 |
+
|
| 24 |
+
with gr.Row():
|
| 25 |
+
file_input = gr.File(label="Upload Spreadsheet", file_types=[".xlsx"])
|
| 26 |
+
question_input = gr.Textbox(label="Ask a Question")
|
| 27 |
+
|
| 28 |
+
answer_output = gr.Textbox(label="Answer", interactive=False, lines=4)
|
| 29 |
+
|
| 30 |
+
submit_button = gr.Button("Submit")
|
| 31 |
+
submit_button.click(answer_question, inputs=[file_input, question_input], outputs=answer_output)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
if __name__ == "__main__":
|
| 35 |
+
login()
|
| 36 |
+
demo.launch()
|