-
Notifications
You must be signed in to change notification settings - Fork 1
/
st_form.py
49 lines (40 loc) · 1.31 KB
/
st_form.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
from datetime import datetime
import streamlit as st
import pandas as pd
# import json
from util import schema_data, schema_face
from sqlalchemy import desc, column
st.set_page_config(page_title = "捏脸", layout = "wide")
last = schema_data.select().order_by(desc('id')).limit(1).execute()
start = last.one()['id']
N = 30
checked = [False] * N
def routine():
st.write(start)
data = pd.read_sql_query(
schema_face.select().where(column('id') > start).limit(N),
con = schema_face.bind)
cols = st.columns(5)
checks = [False] * N
with st.form("my_form"):
for i in range(int(N/5)):
for j in range(5):
with cols[j]:
st.image(
data.iloc[i*5+j]['svg'], use_column_width=True)
st.write(data.iloc[i*5+j]['score'])
checks[i*5+j] = st.checkbox(str(data.iloc[i*5+j]['id']))
submitted = st.form_submit_button("Submit")
if submitted:
pd.DataFrame(dict(
id = data['id'],
check = checks,
_utime = datetime.now()
)).to_sql(
'data',
con=schema_data.bind,
if_exists="append",
index=False,
)
st.success('success!')
routine()