-
Notifications
You must be signed in to change notification settings - Fork 0
/
app_tableQA.py
57 lines (34 loc) · 1.32 KB
/
app_tableQA.py
1
2
3
4
5
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import streamlit as st
import pandas as pd
# install tableqa with pip/pip3 install tableqa
from tableqa.agent import Agent
# running this for the first will start downloading of transformer models and weights
# after that they will be saved in cache and loaded from there
st.title("Streamlit app")
path = st.text_input('File name/path:')
loaded = False
if path:
try:
df = pd.read_csv(path)
st.write(df)
loaded = True
columns = df.columns
for col in columns: # converting binary columns into string columns
if df[col].nunique() < 3:
if df[col].dtypes != 'object':
column = df[col]
new_column = []
for val in column:
if val == 1:
new_column.append('yes')
else:
new_column.append('no')
df[col] = new_column
agent = Agent(df) # creating tableqa agent object with the given dataframe
except:
st.write("No such file found")
if loaded:
query = st.text_input('Instruction')
if query:
st.write("** agent response : **",agent.get_query(query))
# currently returning the SQL query, for result use agent.query_db(query)