-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
180 lines (153 loc) · 6.18 KB
/
app.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
from email.policy import default
from sklearn.feature_selection import SelectFromModel
import streamlit as st
import streamlit_authenticator as stauth
from streamlit_option_menu import option_menu
import yaml
from PIL import Image
import all_func
import plotly.express as px
from Apps import news_portal, socmed_portal, statistics_portal
from deta import Deta # Import Deta
import io
# Fullscreen
im = Image.open("Image/page_icon.png")
st.set_page_config(
page_title="MOCKUP - ANALISIS TEKS PEMILU",
page_icon=im,
layout="wide",
)
# Remove Whitespace, hamburger, and "Made with streamlit"
# hide_streamlit_style = """
# <style>
# #MainMenu {visibility: hidden;}
# footer {visibility: hidden;}
# .css-18e3th9 {
# padding-top: 0rem;
# padding-bottom: 10rem;
# padding-left: 5rem;
# padding-right: 5rem;
# }
# .css-1d391kg {
# padding-top: 3.5rem;
# padding-right: 1rem;
# padding-bottom: 3.5rem;
# padding-left: 1rem;
# }
# </style>
# """
hide_streamlit_style = """
<style>
.css-18e3th9 {
padding-top: 0rem;
padding-bottom: 10rem;
padding-left: 3rem;
padding-right: 5rem;
}
.css-1d391kg {
padding-top: 3.5rem;
padding-right: 1rem;
padding-bottom: 3.5rem;
padding-left: 1rem;
}
</style>
"""
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
# Configuration login/logout function
with open('Users Data/config.yaml') as file:
config = yaml.safe_load(file)
authenticator = stauth.Authenticate(
config['credentials'],
config['cookie']['name'],
config['cookie']['key'],
config['cookie']['expiry_days'],
config['preauthorized']
)
# Login Page
judul = st.markdown("<h1 style='text-align: center; color: #f94144;'>Mockup Analisis Teks Pemilu</h1>", unsafe_allow_html=True)
col1, col2, col3 = st.columns(3)
with col2:
# Login form
name, authentication_status, username = authenticator.login('Login', 'main')
if st.session_state["authentication_status"]:
judul.empty()
## Read File
df_berita = all_func.get_data_berita()
df_tokoh = all_func.get_data_tokoh()
df_twitter = all_func.get_data_twitter()
st.session_state["df_berita"] = df_berita
st.session_state["df_tokoh"] = df_tokoh
st.session_state["df_twitter"] = df_twitter
if st.session_state["username"] == 'admin':
# Sidebar menu
with st.sidebar:
selected = option_menu(
menu_title = 'MOCKUP',
menu_icon = 'ui-radios',
options = ['Beranda','Social Media Portal', 'News Portal', 'Statistics Portal', 'Location Portal', 'Demography Portal', 'Emotion Portal', 'SNA', 'Atur Profil'],
icons = ['house-door','gpu-card', 'newspaper', 'file-bar-graph-fill', 'geo-alt-fill', 'people-fill', 'emoji-smile-fill', 'gear-wide-connected', 'gear']
)
else:
# Sidebar menu
with st.sidebar:
selected = option_menu(
menu_title = 'SIDINIBAKERJA',
menu_icon = 'ui-radios',
options = ['Beranda', 'Pagu Anggaran', 'Target dan Realisasi', 'Capaian Kinerja/Output', 'Laporan Performa', 'Atur Profil'],
icons = ['house-door', 'journal-album', 'journal-check', 'bullseye', 'clipboard-data', 'gear']
)
with st.sidebar:
authenticator.logout('Logout', 'main')
# Halaman Beranda
if selected == 'Beranda':
st.title('MOCKUP - ANALISIS TEKS PEMILU')
st.markdown("""---""")
st.warning(
f"""
Selamat datang **{st.session_state["name"]}**,
**MOCKUP - ANALISIS TEKS PEMILU** merupakan mockup aplikasi analisis teks.
Untuk pertanyaan atau masukan silakan hubungi **Admin** melalui
[E-Mail](https://mail.google.com/) | [Twitter](https://twitter.com/) | [YouTube](https://www.youtube.com/c/).
"""
)
if selected == 'News Portal':
news_portal.app()
if selected == 'Social Media Portal':
socmed_portal.app()
if selected == 'Statistics Portal':
statistics_portal.app()
if selected == 'Atur Profil':
st.title(selected)
st.markdown("""---""")
# Fungsi ADMIN
colpro1, colpro2 = st.columns(2)
with colpro1:
# Ganti Password
with st.expander("Ganti Password"):
pass
if authentication_status:
try:
if authenticator.reset_password(username, 'Ganti Password'):
st.success('Password berhasil diganti')
with open('Users Data/config.yaml', 'w') as file:
yaml.dump(config, file, default_flow_style=False)
except Exception as e:
st.error(e)
with colpro2:
if st.session_state["username"] == 'admin':
# Tambah User baru
with st.expander("Tambah User Baru"):
if authentication_status:
try:
if authenticator.register_user('Register user', preauthorization=False):
st.success('User registered successfully')
with open('Users Data/config.yaml', 'w') as file:
yaml.dump(config, file, default_flow_style=False)
except Exception as e:
st.error(e)
elif st.session_state["authentication_status"] == False:
with col2:
st.error('Username/password salah atau tidak terdaftar')
elif st.session_state["authentication_status"] == None:
with col2:
st.warning('Silakan masukan username dan password')