Spaces:
Sleeping
Sleeping
initial app
Browse files
app.py
CHANGED
@@ -3,7 +3,226 @@ import json
|
|
3 |
import os
|
4 |
import uuid
|
5 |
import streamlit as st
|
|
|
6 |
from datetime import datetime, timedelta
|
7 |
from dotenv import load_dotenv
|
|
|
8 |
|
9 |
-
load_dotenv()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
import os
|
4 |
import uuid
|
5 |
import streamlit as st
|
6 |
+
import math
|
7 |
from datetime import datetime, timedelta
|
8 |
from dotenv import load_dotenv
|
9 |
+
from typing import List
|
10 |
|
11 |
+
load_dotenv()
|
12 |
+
|
13 |
+
def get_question_topics():
|
14 |
+
url = os.environ["BASE_URL"]+"/question-topics"
|
15 |
+
headers = {
|
16 |
+
"x-api-key": os.environ["API_KEY"]
|
17 |
+
}
|
18 |
+
try:
|
19 |
+
response = requests.get(url,headers=headers)
|
20 |
+
response.raise_for_status()
|
21 |
+
return response.json()["output"]
|
22 |
+
except Exception as e:
|
23 |
+
print(f"Fehler beim Fetchen der Topics: {e}")
|
24 |
+
st.error("Someting went wrong. Please try again later.", icon="🚨")
|
25 |
+
|
26 |
+
def get_coding_task_topics():
|
27 |
+
url = os.environ["BASE_URL"]+"/coding-task-topics"
|
28 |
+
headers = {
|
29 |
+
"x-api-key": os.environ["API_KEY"]
|
30 |
+
}
|
31 |
+
try:
|
32 |
+
response = requests.get(url,headers=headers)
|
33 |
+
response.raise_for_status()
|
34 |
+
return response.json()["output"]
|
35 |
+
except Exception as e:
|
36 |
+
print(f"Fehler beim Fetchen der Topics: {e}")
|
37 |
+
st.error("Someting went wrong. Please try again later.", icon="🚨")
|
38 |
+
|
39 |
+
def get_questions(topic):
|
40 |
+
url = os.environ["BASE_URL"]+"/questions"+f"?dimension={topic}"
|
41 |
+
headers = {
|
42 |
+
"x-api-key": os.environ["API_KEY"]
|
43 |
+
}
|
44 |
+
try:
|
45 |
+
response = requests.get(url, data=topic, headers=headers)
|
46 |
+
response.raise_for_status()
|
47 |
+
# print(response.json())
|
48 |
+
return response.json()["output"]
|
49 |
+
except Exception as e:
|
50 |
+
print(f"Fehler beim Fetchen der Topics: {e}")
|
51 |
+
st.error("Someting went wrong. Please try again later.", icon="🚨")
|
52 |
+
|
53 |
+
def get_coding_tasks(topic):
|
54 |
+
url = os.environ["BASE_URL"]+"/coding-tasks"+f"?topic={topic}"
|
55 |
+
headers = {
|
56 |
+
"x-api-key": os.environ["API_KEY"]
|
57 |
+
}
|
58 |
+
try:
|
59 |
+
response = requests.get(url, data=topic, headers=headers)
|
60 |
+
response.raise_for_status()
|
61 |
+
print(response.json())
|
62 |
+
return response.json()["output"]
|
63 |
+
except Exception as e:
|
64 |
+
print(f"Fehler beim Fetchen der Topics: {e}")
|
65 |
+
st.error("Someting went wrong. Please try again later.", icon="🚨")
|
66 |
+
|
67 |
+
def load_topics_into_question_list():
|
68 |
+
with st.spinner("Loading questions..."):
|
69 |
+
for topic in st.session_state["loaded_questions"]:
|
70 |
+
if topic["topic"] not in st.session_state["selected_topics"]:
|
71 |
+
st.session_state["loaded_questions"].remove(topic)
|
72 |
+
for topic in st.session_state["selected_topics"]:
|
73 |
+
if topic not in [topic["topic"] for topic in st.session_state["loaded_questions"]]:
|
74 |
+
question_element = {"topic": topic, "questions": get_questions(topic)}
|
75 |
+
st.session_state["loaded_questions"].append(question_element)
|
76 |
+
|
77 |
+
def load_topics_into_task_list():
|
78 |
+
with st.spinner("Loading coding tasks..."):
|
79 |
+
for topic in st.session_state["loaded_tasks"]:
|
80 |
+
if topic["topic"] not in st.session_state["selected_task_topics"]:
|
81 |
+
st.session_state["loaded_tasks"].remove(topic)
|
82 |
+
for topic in st.session_state["selected_task_topics"]:
|
83 |
+
if topic not in [topic["topic"] for topic in st.session_state["loaded_tasks"]]:
|
84 |
+
question_element = {"topic": topic, "tasks": get_coding_tasks(topic)}
|
85 |
+
st.session_state["loaded_tasks"].append(question_element)
|
86 |
+
|
87 |
+
def add_question_to_interview(question):
|
88 |
+
if question not in st.session_state["questions_for_interview"]:
|
89 |
+
st.session_state["questions_for_interview"].append(question)
|
90 |
+
else:
|
91 |
+
print("Question already in list")
|
92 |
+
|
93 |
+
def increment_page():
|
94 |
+
if st.session_state["current_page"] < math.ceil(len(st.session_state["questions_to_display"])/10):
|
95 |
+
st.session_state["current_page"] += 1
|
96 |
+
|
97 |
+
def decrement_page():
|
98 |
+
if st.session_state["current_page"] > 1:
|
99 |
+
st.session_state["current_page"] -= 1
|
100 |
+
|
101 |
+
def change_question_type():
|
102 |
+
if st.session_state["question_type"] == "question":
|
103 |
+
st.session_state["question_type"] = "coding_tasks"
|
104 |
+
else:
|
105 |
+
st.session_state["question_type"] = "question"
|
106 |
+
|
107 |
+
if "topics" not in st.session_state:
|
108 |
+
topics = list(set([topic["dimension"] for topic in get_question_topics() if topic["dimension"] != None]))
|
109 |
+
st.session_state["topics"] = topics
|
110 |
+
if "task_topics" not in st.session_state:
|
111 |
+
topics = list(set([topic for topic in get_coding_task_topics() if topic != None]))
|
112 |
+
st.session_state["task_topics"] = topics
|
113 |
+
if "loaded_questions" not in st.session_state:
|
114 |
+
st.session_state["loaded_questions"] = []
|
115 |
+
if "loaded_tasks" not in st.session_state:
|
116 |
+
st.session_state["loaded_tasks"] = []
|
117 |
+
if "selected_topics" not in st.session_state:
|
118 |
+
st.session_state["selected_topics"] = []
|
119 |
+
if "questions_to_display" not in st.session_state:
|
120 |
+
st.session_state["questions_to_display"] = []
|
121 |
+
if "tasks_to_display" not in st.session_state:
|
122 |
+
st.session_state["tasks_to_display"] = []
|
123 |
+
if "questions_for_interview" not in st.session_state:
|
124 |
+
st.session_state["questions_for_interview"] = []
|
125 |
+
if "current_page" not in st.session_state:
|
126 |
+
st.session_state["current_page"] = 1
|
127 |
+
if "question_type" not in st.session_state:
|
128 |
+
st.session_state["question_type"] = "question"
|
129 |
+
if "tasks_for_interview" not in st.session_state:
|
130 |
+
st.session_state["tasks_for_interview"] = []
|
131 |
+
|
132 |
+
col1, col2 = st.columns([2, 1])
|
133 |
+
|
134 |
+
col1.title("Interview Preparation")
|
135 |
+
col2.image("https://www.workgenius.com/wp-content/uploads/2023/03/WorkGenius_navy-1.svg")
|
136 |
+
|
137 |
+
type_col1, type_col2 = st.columns([1, 1])
|
138 |
+
|
139 |
+
with type_col1:
|
140 |
+
st.button("Questions", key="question_button", on_click=change_question_type, disabled=True if st.session_state["question_type"] == "question" else False, use_container_width=True)
|
141 |
+
with type_col2:
|
142 |
+
st.button("Coding tasks", key="coding_tasks", on_click=change_question_type, disabled=True if st.session_state["question_type"] == "coding_tasks" else False, use_container_width=True)
|
143 |
+
|
144 |
+
|
145 |
+
if st.session_state["question_type"] == "question":
|
146 |
+
st.multiselect("Select the topics for the questions", st.session_state["topics"], key="selected_topics", default=None, on_change=load_topics_into_question_list)
|
147 |
+
st.divider()
|
148 |
+
if len(st.session_state["selected_topics"]) > 0:
|
149 |
+
st.subheader("Questions to choose from:")
|
150 |
+
st.write("Filter according to the difficulty of the questions:")
|
151 |
+
st.checkbox("Easy", key="checkbox_filter_easy", value=True)
|
152 |
+
st.checkbox("Medium", key="checkbox_filter_medium", value=True)
|
153 |
+
st.checkbox("Hard", key="checkbox_filter_hard", value=True)
|
154 |
+
st.write("Filter by the topic of the questions:")
|
155 |
+
for topic in st.session_state["loaded_questions"]:
|
156 |
+
st.checkbox(topic["topic"], key="checkbox_filter_"+topic["topic"], value=True)
|
157 |
+
result_questions = []
|
158 |
+
for i, topic in enumerate(st.session_state["loaded_questions"]):
|
159 |
+
if st.session_state["checkbox_filter_"+topic["topic"]]:
|
160 |
+
for j, question in enumerate(topic["questions"]):
|
161 |
+
if st.session_state["checkbox_filter_easy"] and question["difficulty"] == "Easy":
|
162 |
+
result_questions.append(question)
|
163 |
+
if st.session_state["checkbox_filter_medium"] and question["difficulty"] == "Medium":
|
164 |
+
result_questions.append(question)
|
165 |
+
if st.session_state["checkbox_filter_hard"] and question["difficulty"] == "Hard":
|
166 |
+
result_questions.append(question)
|
167 |
+
st.session_state["questions_to_display"] = result_questions
|
168 |
+
if len(st.session_state["questions_to_display"]) > 0:
|
169 |
+
nav_col1, nav_col2, nav_col3 = st.columns([1, 4, 1])
|
170 |
+
|
171 |
+
nav_col1.button("◀️", key="nav1", use_container_width=True, on_click=decrement_page, disabled=True if st.session_state["current_page"] == 1 else False)
|
172 |
+
nav_col2.markdown(f"<div style='text-align: center;'>Page {str(st.session_state['current_page'])} / {str(math.ceil(len(st.session_state['questions_to_display'])/10))}</div>", unsafe_allow_html=True)
|
173 |
+
nav_col3.button("▶️", key="nav2", use_container_width=True, on_click=increment_page, disabled=True if st.session_state["current_page"] == math.ceil(len(st.session_state["questions_to_display"])/10) else False)
|
174 |
+
|
175 |
+
for i in range((st.session_state["current_page"]-1)*10, st.session_state["current_page"]*10 if st.session_state["current_page"]*10 < len(st.session_state["questions_to_display"]) else len(st.session_state["questions_to_display"])):
|
176 |
+
col_1, col_2 = st.columns([7, 1])
|
177 |
+
with col_1:
|
178 |
+
st.write(st.session_state["questions_to_display"][i]["question"])
|
179 |
+
with col_2:
|
180 |
+
st.button("Select", disabled=True if st.session_state["questions_to_display"][i] in st.session_state["questions_for_interview"] else False ,key="select_button_"+str(i), on_click=add_question_to_interview, args=(st.session_state["questions_to_display"][i],))
|
181 |
+
else:
|
182 |
+
st.multiselect("Select the topics for the coding tasks", options=st.session_state["task_topics"], key="selected_task_topics", default=None, on_change=load_topics_into_task_list)
|
183 |
+
st.divider()
|
184 |
+
if len(st.session_state["selected_task_topics"]) > 0:
|
185 |
+
st.subheader("Coding tasks to choose from:")
|
186 |
+
st.write("Filter by the topic of the coding task:")
|
187 |
+
for topic in st.session_state["loaded_tasks"]:
|
188 |
+
st.checkbox(topic["topic"], key="checkbox_filter_tasks_"+topic["topic"], value=True)
|
189 |
+
result_tasks = []
|
190 |
+
for i, topic in enumerate(st.session_state["loaded_tasks"]):
|
191 |
+
if st.session_state["checkbox_filter_tasks_"+topic["topic"]]:
|
192 |
+
for j, task in enumerate(topic["tasks"]):
|
193 |
+
result_tasks.append(task)
|
194 |
+
st.session_state["tasks_to_display"] = result_tasks
|
195 |
+
if len(st.session_state["tasks_to_display"]) > 0:
|
196 |
+
nav_col1, nav_col2, nav_col3 = st.columns([1, 4, 1])
|
197 |
+
|
198 |
+
nav_col1.button("◀️", key="nav1", use_container_width=True, on_click=decrement_page, disabled=True if st.session_state["current_page"] == 1 else False)
|
199 |
+
nav_col2.markdown(f"<div style='text-align: center;'>Page {str(st.session_state['current_page'])} / {str(math.ceil(len(st.session_state['tasks_to_display'])/10))}</div>", unsafe_allow_html=True)
|
200 |
+
nav_col3.button("▶️", key="nav2", use_container_width=True, on_click=increment_page, disabled=True if st.session_state["current_page"] == math.ceil(len(st.session_state["tasks_to_display"])/10) else False)
|
201 |
+
|
202 |
+
for i in range((st.session_state["current_page"]-1)*10, st.session_state["current_page"]*10 if st.session_state["current_page"]*10 < len(st.session_state["tasks_to_display"]) else len(st.session_state["tasks_to_display"])):
|
203 |
+
col_1, col_2 = st.columns([7, 1])
|
204 |
+
with col_1:
|
205 |
+
st.write(st.session_state["tasks_to_display"][i]["task"])
|
206 |
+
with col_2:
|
207 |
+
st.button("Select", disabled=True if st.session_state["tasks_to_display"][i] in st.session_state["tasks_for_interview"] else False ,key="select_button_tasks_"+str(i), on_click=st.session_state["tasks_for_interview"].append, args=(st.session_state["tasks_to_display"][i],))
|
208 |
+
st.divider()
|
209 |
+
|
210 |
+
st.subheader("Questions for the interview:")
|
211 |
+
if len(st.session_state["questions_for_interview"]) == 0:
|
212 |
+
st.write("No questions selected yet.")
|
213 |
+
for i, question in enumerate(st.session_state["questions_for_interview"]):
|
214 |
+
interview_col_1, interview_col_2 = st.columns([7, 1])
|
215 |
+
with interview_col_1:
|
216 |
+
st.write(question["question"])
|
217 |
+
with interview_col_2:
|
218 |
+
st.button("Remove", key="remove_button_"+str(i), on_click=st.session_state["questions_for_interview"].remove, args=(question,))
|
219 |
+
st.subheader("Coding tasks for the interview:")
|
220 |
+
if len(st.session_state["tasks_for_interview"]) == 0:
|
221 |
+
st.write("No coding tasks selected yet.")
|
222 |
+
for i, task in enumerate(st.session_state["tasks_for_interview"]):
|
223 |
+
interview_col_1, interview_col_2 = st.columns([7, 1])
|
224 |
+
with interview_col_1:
|
225 |
+
st.write(task["task"])
|
226 |
+
with interview_col_2:
|
227 |
+
st.button("Remove", key="remove_button_tasks_"+str(i), on_click=st.session_state["tasks_for_interview"].remove, args=(task,))
|
228 |
+
st.divider()
|