-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.py
112 lines (81 loc) · 2.73 KB
/
ui.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env python
#
# Brief description here
#
##############################################################################
# Authors:
# - Alessio Xompero, [email protected]
#
# Created Date: 2024/08/23
# Modified Date: 2023/08/26
#
# Copyright (c) 2024 AtomicDeFake
#
##############################################################################
import argparse
import streamlit as st
from atomic_defake.atomic_defake import AtomicDeFake
UI_STAGES = ["atomic_defake", "post", "adf_aggregation", "contributor", "output"]
def initialise_session():
""" """
st.session_state.stage = None
if "social_media" not in st.session_state:
st.session_state.social_media = None
st.session_state.atomic_defake = AtomicDeFake(
aggregation_method="single_false_or_unsure"
)
parser = GetParser()
args = parser.parse_args()
st.session_state.n_checkers = args.n_checkers - 1
st.session_state.n_checkers_iter = args.n_checkers - 1
def reset_session():
""" """
if "social_media" not in st.session_state:
st.session_state.social_media = None
parser = GetParser()
args = parser.parse_args()
st.session_state.n_checkers = args.n_checkers - 1
if "logged_in" not in st.session_state:
st.session_state.logged_in = False
def login():
st.text("Please log in to continue.")
if st.button("Log in"):
st.session_state.logged_in = True
st.rerun()
def logout():
if st.button("Log out"):
st.session_state.logged_in = False
st.rerun()
#############################################################################
def GetParser(desc=""):
""" """
parser = argparse.ArgumentParser(
description=desc,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument("--n_checkers", type=int, default=2)
return parser
if __name__ == "__main__":
if "stage" not in st.session_state:
initialise_session()
elif st.session_state.stage is None:
reset_session()
login_page = st.Page(login, title="Log in", icon=":material/login:")
logout_page = st.Page(logout, title="Log out", icon=":material/logout:")
user_post_page = st.Page(
"user_post.py", title="User post", icon=":material/add_circle:"
)
contributor_page = st.Page(
"contributor.py", title="Contributor", icon=":material/delete:"
)
if st.session_state.logged_in:
pg = st.navigation(
{
"Account": [logout_page],
"AtomicDeFake": [user_post_page, contributor_page],
}
)
st.set_page_config(page_title="AtomicDeFake", page_icon=":identification_card:")
else:
pg = st.navigation([login_page])
pg.run()