Abbasid commited on
Commit
c3b0ed3
1 Parent(s): 846a590

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. README.md +1 -7
  2. TableQAGradio.py +162 -0
README.md CHANGED
@@ -1,12 +1,6 @@
1
  ---
2
  title: TableQA
3
- emoji: 💻
4
- colorFrom: indigo
5
- colorTo: indigo
6
  sdk: gradio
7
  sdk_version: 4.12.0
8
- app_file: app.py
9
- pinned: false
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
  title: TableQA
3
+ app_file: TableQAGradio.py
 
 
4
  sdk: gradio
5
  sdk_version: 4.12.0
 
 
6
  ---
 
 
TableQAGradio.py ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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[12]:
83
+
84
+
85
+ from collections import Counter
86
+ Counter(result)
87
+
88
+
89
+ # In[13]:
90
+
91
+
92
+ #mstqa(table=table4, query=query1)["answer"]
93
+
94
+
95
+ # In[14]:
96
+
97
+
98
+ mswtqa(table=table3, query=query5)["answer"]
99
+
100
+
101
+ # In[15]:
102
+
103
+
104
+ def main(filepath, query):
105
+
106
+ table5 = pd.read_excel(filepath).head(20).astype(str)
107
+ result = tsqa(table=table5, query=query)["answer"]
108
+ return result
109
+
110
+ #greet("World")
111
+
112
+
113
+ # In[16]:
114
+
115
+
116
+ import gradio as gr
117
+
118
+ iface = gr.Interface(
119
+ fn=main,
120
+ inputs=[
121
+ gr.File(type="filepath", label="Upload XLSX file"),
122
+ gr.Textbox(type="text", label="Enter text"),
123
+ ],
124
+ outputs=[gr.Textbox(type="text", label="Text Input Output")],
125
+ title="Multi-input Processor",
126
+ description="Upload an XLSX file and/or enter text, and the processed output will be displayed.",
127
+ )
128
+
129
+ # Launch the Gradio interface
130
+ iface.launch()
131
+
132
+
133
+ # In[21]:
134
+
135
+
136
+ get_ipython().system('pip install notebook')
137
+
138
+
139
+ # In[34]:
140
+
141
+
142
+ import os
143
+ import subprocess
144
+
145
+ # Use subprocess to execute the shell command
146
+ subprocess.run(["jupyter", "nbconvert", "--to", "script", "--format", "script", "--output", "/content/", "/content/drive/MyDrive/Colab Notebooks/NEW TableQA-GRADIO: Hello World.ipynb"])
147
+
148
+
149
+ # In[19]:
150
+
151
+
152
+ get_ipython().system('gradio deploy')
153
+
154
+
155
+ # In[32]:
156
+
157
+
158
+ from google.colab import drive
159
+ drive.mount('/content/drive')
160
+
161
+
162
+ # 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.