Spaces:
Sleeping
Sleeping
myselfshravan
commited on
Commit
Β·
bf90bae
1
Parent(s):
0be59d9
chore: Refactor login functionality and improve UI
Browse filesRefactor the login functionality to remove unnecessary code and improve the user interface.
app.py
CHANGED
@@ -1,32 +1,15 @@
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
|
3 |
st.set_page_config(page_title="Enigma Escape", page_icon="π")
|
4 |
|
5 |
-
from new_api import auth, add_points, get_points, levels_done
|
6 |
-
from levels import levels
|
7 |
-
from nemo import EnigmaEscape
|
8 |
-
|
9 |
st.title("Enigma Escape")
|
10 |
st.subheader("Embark on a linguistic adventure.")
|
11 |
|
12 |
-
st.session_state["user"] = st.session_state.get("user", None)
|
13 |
-
|
14 |
-
if st.session_state["user"] is None:
|
15 |
-
with st.form("login"):
|
16 |
-
teamname = st.text_input("Team Name")
|
17 |
-
password = st.text_input("Password", type="password")
|
18 |
-
if st.form_submit_button("Login"):
|
19 |
-
user = auth(teamname, password)
|
20 |
-
if user is not None:
|
21 |
-
st.session_state["user"] = user
|
22 |
-
st.rerun()
|
23 |
-
else:
|
24 |
-
st.error("Invalid credentials")
|
25 |
-
st.stop()
|
26 |
-
|
27 |
st.write(
|
28 |
"The game where you guide Bot to say specific phrases with your own cleverly tweaked instructions."
|
29 |
-
"Keep it short and smart
|
30 |
"Ready, set, twist!"
|
31 |
)
|
32 |
|
@@ -37,18 +20,14 @@ def get_ee():
|
|
37 |
|
38 |
|
39 |
with get_ee() as bot:
|
40 |
-
done_levels = levels_done(st.session_state["user"], [lev.name for lev in bot.levels])
|
41 |
with st.expander("Choose Level >"):
|
42 |
bot.set_level(st.radio("Level", options=range(len(levels)),
|
43 |
-
format_func=lambda
|
44 |
-
|
45 |
-
st.markdown(f"""
|
46 |
-
|
47 |
-
|
48 |
with st.form("chat"):
|
49 |
-
points_holder = st.empty()
|
50 |
-
st.session_state["curr_points"] = get_points(st.session_state["user"])
|
51 |
-
points_holder.info(f"Points: {st.session_state['curr_points']}")
|
52 |
que = st.text_area("Enter your instructions to Bot: ", height=100)
|
53 |
if st.form_submit_button("Send"):
|
54 |
with st.container():
|
@@ -65,8 +44,5 @@ with get_ee() as bot:
|
|
65 |
elif _type == "success":
|
66 |
st.success(content)
|
67 |
st.success(f"hurray! you escaped and gained some points")
|
68 |
-
add_points(st.session_state["user"], bot.level.points, bot.level.name, resp["tokens"], que)
|
69 |
-
st.session_state["curr_points"] = get_points(st.session_state["user"])
|
70 |
-
points_holder.info(f"Points: {st.session_state['curr_points']}")
|
71 |
else:
|
72 |
st.write(content)
|
|
|
1 |
+
from nemo import EnigmaEscape
|
2 |
+
from levels import levels
|
3 |
import streamlit as st
|
4 |
|
5 |
st.set_page_config(page_title="Enigma Escape", page_icon="π")
|
6 |
|
|
|
|
|
|
|
|
|
7 |
st.title("Enigma Escape")
|
8 |
st.subheader("Embark on a linguistic adventure.")
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
st.write(
|
11 |
"The game where you guide Bot to say specific phrases with your own cleverly tweaked instructions."
|
12 |
+
"Keep it short and smart - change up the words just enough to pass the test and hit the target phrase."
|
13 |
"Ready, set, twist!"
|
14 |
)
|
15 |
|
|
|
20 |
|
21 |
|
22 |
with get_ee() as bot:
|
|
|
23 |
with st.expander("Choose Level >"):
|
24 |
bot.set_level(st.radio("Level", options=range(len(levels)),
|
25 |
+
format_func=lambda x: f"{levels[x].name}: {levels[x].points} points"))
|
26 |
+
|
27 |
+
st.markdown(f"""<h4>Make the bot say the Enigma Phrase <br><span style="color: #ff0000">{
|
28 |
+
bot.level.phrase}</span><br> to escape this level</h4>""", unsafe_allow_html=True)
|
29 |
+
|
30 |
with st.form("chat"):
|
|
|
|
|
|
|
31 |
que = st.text_area("Enter your instructions to Bot: ", height=100)
|
32 |
if st.form_submit_button("Send"):
|
33 |
with st.container():
|
|
|
44 |
elif _type == "success":
|
45 |
st.success(content)
|
46 |
st.success(f"hurray! you escaped and gained some points")
|
|
|
|
|
|
|
47 |
else:
|
48 |
st.write(content)
|