Mustafiz996 commited on
Commit
555878e
·
verified ·
1 Parent(s): 9d909a9

Update app.py

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