Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,7 @@ from oauth2client.service_account import ServiceAccountCredentials
|
|
7 |
import PyPDF2
|
8 |
import io
|
9 |
from datetime import datetime
|
|
|
10 |
|
11 |
# Constants
|
12 |
WORD_LIMIT = 8000
|
@@ -225,38 +226,68 @@ if 'username' not in st.session_state:
|
|
225 |
|
226 |
# Login system
|
227 |
if st.session_state.username is None:
|
228 |
-
|
229 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
230 |
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
|
|
|
|
243 |
else:
|
244 |
-
st.warning("
|
245 |
-
else:
|
246 |
-
st.warning("Please enter a valid username.")
|
247 |
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
252 |
|
253 |
-
# Show instructions
|
254 |
-
if st.session_state.login_step == 'username':
|
255 |
-
st.markdown("""
|
256 |
-
### How to Login:
|
257 |
-
1. Enter your username and click 'Login' to verify your account
|
258 |
-
2. After verification, click 'Enter GeneXam Application' to start using the system
|
259 |
-
""")
|
260 |
else:
|
261 |
# Main application code (ส่วนที่เหลือเหมือนเดิม)
|
262 |
st.title(f"Welcome to GeneXam, {st.session_state.username}! 🎓")
|
|
|
7 |
import PyPDF2
|
8 |
import io
|
9 |
from datetime import datetime
|
10 |
+
from PIL import Image
|
11 |
|
12 |
# Constants
|
13 |
WORD_LIMIT = 8000
|
|
|
226 |
|
227 |
# Login system
|
228 |
if st.session_state.username is None:
|
229 |
+
# Center align the content
|
230 |
+
col1, col2, col3 = st.columns([1,2,1])
|
231 |
+
|
232 |
+
with col2:
|
233 |
+
# Display logo
|
234 |
+
st.image("logo.png", width=200) # Assuming the image is saved as logo.png
|
235 |
+
|
236 |
+
st.title("Login")
|
237 |
+
username_input = st.text_input("Enter your username:")
|
238 |
|
239 |
+
if st.session_state.login_step == 'username' and st.button("Login", use_container_width=True):
|
240 |
+
if username_input:
|
241 |
+
if check_user_in_sheet(username_input):
|
242 |
+
stats = get_user_stats(username_input)
|
243 |
+
if stats:
|
244 |
+
st.success(f"Welcome, {username_input}! 👋")
|
245 |
+
st.info(f"""
|
246 |
+
📊 Your API Usage Statistics:
|
247 |
+
- Today's Usage: {stats['daily_count']}/{DAILY_API_LIMIT} generations
|
248 |
+
- Total All-Time Usage: {stats['total_count']} generations
|
249 |
+
""")
|
250 |
+
st.session_state.login_step = 'enter_app'
|
251 |
+
else:
|
252 |
+
st.warning("Username not found. Please try again.")
|
253 |
else:
|
254 |
+
st.warning("Please enter a valid username.")
|
|
|
|
|
255 |
|
256 |
+
if st.session_state.login_step == 'enter_app':
|
257 |
+
if st.button("🎯 Enter GeneXam Application", use_container_width=True):
|
258 |
+
st.session_state.username = username_input
|
259 |
+
st.rerun()
|
260 |
+
|
261 |
+
# Show instructions
|
262 |
+
if st.session_state.login_step == 'username':
|
263 |
+
st.markdown("""
|
264 |
+
### How to Login:
|
265 |
+
1. Enter your username and click 'Login' to verify your account
|
266 |
+
2. After verification, click 'Enter GeneXam Application' to start using the system
|
267 |
+
""")
|
268 |
+
|
269 |
+
# Add some custom CSS to improve the layout
|
270 |
+
st.markdown("""
|
271 |
+
<style>
|
272 |
+
.stImage {
|
273 |
+
text-align: center;
|
274 |
+
display: block;
|
275 |
+
margin-left: auto;
|
276 |
+
margin-right: auto;
|
277 |
+
}
|
278 |
+
|
279 |
+
.stTitle {
|
280 |
+
text-align: center;
|
281 |
+
padding-bottom: 20px;
|
282 |
+
}
|
283 |
+
|
284 |
+
div[data-testid="stVerticalBlock"] > div:has(div.stButton) {
|
285 |
+
text-align: center;
|
286 |
+
padding: 10px 0;
|
287 |
+
}
|
288 |
+
</style>
|
289 |
+
""", unsafe_allow_html=True)
|
290 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
291 |
else:
|
292 |
# Main application code (ส่วนที่เหลือเหมือนเดิม)
|
293 |
st.title(f"Welcome to GeneXam, {st.session_state.username}! 🎓")
|