-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
65 lines (54 loc) · 1.93 KB
/
server.py
File metadata and controls
65 lines (54 loc) · 1.93 KB
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
58
59
60
61
62
63
64
65
import os
import streamlit as st
import sqlite3
import sys
sys.path.append('.')
from benchmarkUtils.database import DB
from benchmarkUtils.frontend import check_password
if not check_password():
st.stop()
dbRoot = 'symDataset/scaledDB'
taskPath = 'symDataset/tasks/TableQA/dataset.sqlite'
scale = '8k 16k 32k 64k 128k'.split()
class datasetShow:
def __init__(self, dbRoot, taskPath):
self.dbRoot = dbRoot
self.taskPath = taskPath
self.conn = sqlite3.connect(self.taskPath)
self.cur = self.conn.cursor()
def listAllTables(self):
self.cur.execute('SELECT name FROM sqlite_master WHERE type=\'table\';')
tableNames = []
lst = self.cur.fetchall()
if lst:
for item in lst:
tableNames.append(item[0])
return tableNames
def fetchItem(self, dbn, sc, dbIdx, sampleIdx, questionIdx):
self.cur.execute('SELECT * FROM {dbn} WHERE scale=? AND dbIdx=? AND sampleIdx=? AND questionIdx=?;'.format(dbn=dbn),
(sc, dbIdx, sampleIdx, questionIdx))
item = self.cur.fetchone()
if item:
return item
return None
dtst = datasetShow(dbRoot, taskPath)
dbNames = dtst.listAllTables()
dbn = st.selectbox('Select a dataset', dbNames)
sc = st.selectbox('Select a scale', scale)
dbIdx = st.selectbox('Select dbIdx', list(range(10)))
sampleIdx = st.selectbox('Select sampleIdx', list(range(10)))
questionIdx = st.selectbox('Select questionIdx', list(range(14)))
item = dtst.fetchItem(dbn, sc, dbIdx, sampleIdx, questionIdx)
if item is not None:
st.markdown(item[-6])
for i in range(4):
if i == item[-5]:
st.markdown(f':red[{item[-4:][i]}]')
else:
st.markdown(item[-4:][i])
dbp = os.path.join(dbRoot, sc, dbn, f'{dbIdx}.sqlite')
db = DB(dbp)
for k, v in db.tables.items():
st.header(k)
st.write(v)
st.write(f'```sql\n{db.schema()}\n```')