Abbasid commited on
Commit
97a2094
·
verified ·
1 Parent(s): ee095f7

Update TableQAGradio.py

Browse files
Files changed (1) hide show
  1. TableQAGradio.py +33 -126
TableQAGradio.py CHANGED
@@ -1,143 +1,50 @@
1
- #!/usr/bin/env python
2
- # coding: utf-8
3
-
4
- # ## Using Gradio to create a simple interface.
5
- #
6
- # Check out the library on [github](https://github.com/gradio-app/gradio-UI) and see the [getting started](https://gradio.app/getting_started.html) page for more demos.
7
-
8
- # We'll start with a basic function that greets an input name.
9
-
10
- # In[1]:
11
-
12
-
13
- # get_ipython().system('pip install -q gradio')
14
-
15
-
16
- # Now we'll wrap this function with a Gradio interface.
17
-
18
- # In[2]:
19
-
20
 
21
  from transformers import pipeline
22
  import pandas as pd
 
23
 
24
- tqa = pipeline(task="table-question-answering", model="google/tapas-large-finetuned-wtq")
25
-
26
-
27
- # In[ ]:
28
-
29
-
30
- tsqa = pipeline(task="table-question-answering", model="google/tapas-large-finetuned-sqa")
31
-
32
-
33
- # In[ ]:
34
-
35
-
36
- mstqa = pipeline(task="table-question-answering", model="microsoft/tapex-large-finetuned-wikisql")
37
-
38
-
39
- # In[ ]:
40
-
41
-
42
- mswtqa = pipeline(task="table-question-answering", model="microsoft/tapex-large-finetuned-wtq")
43
-
44
-
45
- # In[6]:
46
-
47
-
48
- # table2 = pd.read_excel("/content/Sample.xlsx").astype(str)
49
- # table3 = table2.head(20)
50
-
51
-
52
- # In[7]:
53
-
54
-
55
- # table3
56
-
57
-
58
- # In[ ]:
59
-
60
-
61
- #t4 = table3.reset_index()
62
- # table4
63
-
64
-
65
- # In[9]:
66
-
67
-
68
- query = "what is the highest delta onu rx power?"
69
- query2 = "what is the lowest delta onu rx power?"
70
- query3 = "what is the most frequent login id?"
71
- query4 = "how many rows with nan values are there?"
72
- query5 = "how many S2 values are there"
73
-
74
-
75
- # In[11]:
76
-
77
-
78
- # result = tsqa(table=table3, query=query5)["answer"]
79
- # result
80
-
81
-
82
- # In[13]:
83
-
84
-
85
- #mstqa(table=table4, query=query1)["answer"]
86
-
87
-
88
- # In[14]:
89
-
90
-
91
- # mswtqa(table=table3, query=query5)["answer"]
92
-
93
-
94
- # In[15]:
95
-
96
-
97
- def main(filepath, query):
98
-
99
- table5 = pd.read_excel(filepath).head(20).astype(str)
100
- result = tsqa(table=table5, query=query)["answer"]
101
- return result
102
-
103
- #greet("World")
104
-
105
-
106
- # In[16]:
107
-
108
 
109
- import gradio as gr
110
 
111
  iface = gr.Interface(
112
  fn=main,
113
  inputs=[
 
114
  gr.File(type="filepath", label="Upload XLSX file"),
115
  gr.Textbox(type="text", label="Enter text"),
116
  ],
117
  outputs=[gr.Textbox(type="text", label="Text Input Output")],
118
- title="TM TableQA Test",
119
  description="Upload an XLSX file and/or enter text, and the processed output will be displayed.",
 
 
 
 
 
120
  )
121
 
122
  # Launch the Gradio interface
123
- iface.launch()
124
-
125
-
126
- # In[34]:
127
-
128
-
129
- import os
130
- import subprocess
131
-
132
- # Use subprocess to execute the shell command
133
- # subprocess.run(["jupyter", "nbconvert", "--to", "script", "--format", "script", "--output", "/content/", "/content/drive/MyDrive/Colab Notebooks/NEW TableQA-GRADIO: Hello World.ipynb"])
134
-
135
-
136
- # In[19]:
137
-
138
-
139
- # get_ipython().system('gradio deploy')
140
-
141
-
142
-
143
- # That's all! Go ahead and open that share link in a new tab. Check out our [getting started](https://gradio.app/getting_started.html) page for more complicated demos.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
 
2
  from transformers import pipeline
3
  import pandas as pd
4
+ import gradio as gr
5
 
6
+ # Define the models
7
+ models = {
8
+ "GTQA (google/tapas-large-finetuned-wtq)": pipeline(task="table-question-answering", model="google/tapas-large-finetuned-wtq"),
9
+ "GTSQA (google/tapas-large-finetuned-sqa)": pipeline(task="table-question-answering", model="google/tapas-large-finetuned-sqa"),
10
+ "MSWTQA (microsoft/tapex-large-finetuned-wtq)": pipeline(task="table-question-answering", model="microsoft/tapex-large-finetuned-wtq"),
11
+ "MSTQA (microsoft/tapex-large-finetuned-wikisql)": pipeline(task="table-question-answering", model="microsoft/tapex-large-finetuned-wikisql")
12
+ }
13
+
14
+ def main(model_choice, file_path, text):
15
+ # Read the Excel file
16
+ table_df = pd.read_excel(file_path).astype(str)
17
+
18
+ # Prepare the input for the model
19
+ tqa_pipeline_input = {
20
+ "table": table_df,
21
+ "query": text
22
+ }
23
+
24
+ # Get the selected model
25
+ model = models[model_choice]
26
+
27
+ # Run the model
28
+ result = model(tqa_pipeline_input)["answer"]
29
+ return result
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
 
31
 
32
  iface = gr.Interface(
33
  fn=main,
34
  inputs=[
35
+ gr.Dropdown(choices=list(models.keys()), label="Select Model"),
36
  gr.File(type="filepath", label="Upload XLSX file"),
37
  gr.Textbox(type="text", label="Enter text"),
38
  ],
39
  outputs=[gr.Textbox(type="text", label="Text Input Output")],
40
+ title="Multi-input Processor",
41
  description="Upload an XLSX file and/or enter text, and the processed output will be displayed.",
42
+ examples=[
43
+ ["https://huggingface.co/spaces/Abbasid/TableQA/blob/main/Literature%20review_Test.xlsx", "How many papers are before the year 2020?"],
44
+ ["https://huggingface.co/spaces/Abbasid/TableQA/blob/main/Literature%20review_Test.xlsx", "How many papers are after the year 2020?"],
45
+ ["https://huggingface.co/spaces/Abbasid/TableQA/blob/main/Literature%20review_Test.xlsx", "what is the paper with NISIT in the title?"],
46
+ ],
47
  )
48
 
49
  # Launch the Gradio interface
50
+ iface.launch(debug=True)