Spaces:
Sleeping
Sleeping
fixed br tag error
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import requests
|
|
2 |
import os
|
3 |
import streamlit as st
|
4 |
import math
|
|
|
5 |
from io import BytesIO
|
6 |
from reportlab.lib.pagesizes import letter
|
7 |
from reportlab.platypus import SimpleDocTemplate, Paragraph
|
@@ -68,6 +69,7 @@ def get_coding_tasks(topic):
|
|
68 |
st.error("Someting went wrong. Please try again later.", icon="🚨")
|
69 |
|
70 |
def load_topics_into_question_list():
|
|
|
71 |
with st.spinner("Loading questions..."):
|
72 |
for topic in st.session_state["loaded_questions"]:
|
73 |
if topic["topic"] not in st.session_state["selected_topics"]:
|
@@ -78,6 +80,7 @@ def load_topics_into_question_list():
|
|
78 |
st.session_state["loaded_questions"].append(question_element)
|
79 |
|
80 |
def load_topics_into_task_list():
|
|
|
81 |
with st.spinner("Loading coding tasks..."):
|
82 |
for topic in st.session_state["loaded_tasks"]:
|
83 |
if topic["topic"] not in st.session_state["selected_task_topics"]:
|
@@ -129,6 +132,13 @@ def update_questions_and_tasks():
|
|
129 |
print(f"Fehler beim Speichern der Fragen und Aufgaben: {e}")
|
130 |
st.error("Someting went wrong. Please try again later.", icon="🚨")
|
131 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
if "topics" not in st.session_state:
|
133 |
topics = list(set([topic["dimension"] for topic in get_question_topics() if topic["dimension"] != None]))
|
134 |
st.session_state["topics"] = topics
|
@@ -261,7 +271,7 @@ st.subheader("Coding tasks for the interview:")
|
|
261 |
if len(st.session_state["tasks_for_interview"]) == 0:
|
262 |
st.write("No coding tasks selected yet.")
|
263 |
for i, task in enumerate(st.session_state["tasks_for_interview"]):
|
264 |
-
interview_col_1, interview_col_2 = st.columns([
|
265 |
with interview_col_1:
|
266 |
st.write(task["task"])
|
267 |
with interview_col_2:
|
@@ -278,12 +288,24 @@ if len(st.session_state["questions_for_interview"]) > 0 and len(st.session_state
|
|
278 |
paragraphs = []
|
279 |
for i, question in enumerate(st.session_state["questions_for_interview"]):
|
280 |
paragraph_text = f"<font size='14'><b>Question {i+1}. :</b></font><br/><br/>{question['question']}<br/><b>Perfect answer:</b> {question['perfect_answer']}<br/><b>Difficulty:</b> {question['difficulty']}\n"
|
281 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
282 |
paragraphs.append(Paragraph("<br/><br/>", styles["Normal"])) # Zusätzlicher Zeilenumbruch mit 12pt Abstand
|
283 |
|
284 |
for i, task in enumerate(st.session_state["tasks_for_interview"]):
|
285 |
paragraph_text = f"<font size='14'><b>Coding task {i+1}. :</b></font><br/><br/>{task['task']}<br/><b>Perfect answer:</b> {task['perfect_solution']}\n"
|
286 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
287 |
paragraphs.append(Paragraph("<br/><br/>", styles["Normal"])) # Zusätzlicher Zeilenumbruch mit 12pt Abstand
|
288 |
|
289 |
# Füge die Paragraphen in das PDF-Dokument ein
|
|
|
2 |
import os
|
3 |
import streamlit as st
|
4 |
import math
|
5 |
+
import re
|
6 |
from io import BytesIO
|
7 |
from reportlab.lib.pagesizes import letter
|
8 |
from reportlab.platypus import SimpleDocTemplate, Paragraph
|
|
|
69 |
st.error("Someting went wrong. Please try again later.", icon="🚨")
|
70 |
|
71 |
def load_topics_into_question_list():
|
72 |
+
st.session_state["current_page"] = 1
|
73 |
with st.spinner("Loading questions..."):
|
74 |
for topic in st.session_state["loaded_questions"]:
|
75 |
if topic["topic"] not in st.session_state["selected_topics"]:
|
|
|
80 |
st.session_state["loaded_questions"].append(question_element)
|
81 |
|
82 |
def load_topics_into_task_list():
|
83 |
+
st.session_state["current_page"] = 1
|
84 |
with st.spinner("Loading coding tasks..."):
|
85 |
for topic in st.session_state["loaded_tasks"]:
|
86 |
if topic["topic"] not in st.session_state["selected_task_topics"]:
|
|
|
132 |
print(f"Fehler beim Speichern der Fragen und Aufgaben: {e}")
|
133 |
st.error("Someting went wrong. Please try again later.", icon="🚨")
|
134 |
|
135 |
+
def fix_br_tags(input_string: str):
|
136 |
+
return input_string.replace("<br>", "<br/>")
|
137 |
+
|
138 |
+
def remove_html_tags(input_string: str):
|
139 |
+
clean = re.compile('<.*?>')
|
140 |
+
return re.sub(clean, '', input_string)
|
141 |
+
|
142 |
if "topics" not in st.session_state:
|
143 |
topics = list(set([topic["dimension"] for topic in get_question_topics() if topic["dimension"] != None]))
|
144 |
st.session_state["topics"] = topics
|
|
|
271 |
if len(st.session_state["tasks_for_interview"]) == 0:
|
272 |
st.write("No coding tasks selected yet.")
|
273 |
for i, task in enumerate(st.session_state["tasks_for_interview"]):
|
274 |
+
interview_col_1, interview_col_2 = st.columns([6, 2])
|
275 |
with interview_col_1:
|
276 |
st.write(task["task"])
|
277 |
with interview_col_2:
|
|
|
288 |
paragraphs = []
|
289 |
for i, question in enumerate(st.session_state["questions_for_interview"]):
|
290 |
paragraph_text = f"<font size='14'><b>Question {i+1}. :</b></font><br/><br/>{question['question']}<br/><b>Perfect answer:</b> {question['perfect_answer']}<br/><b>Difficulty:</b> {question['difficulty']}\n"
|
291 |
+
try:
|
292 |
+
paragraphs.append(Paragraph(paragraph_text, styles["Normal"]))
|
293 |
+
except:
|
294 |
+
try:
|
295 |
+
paragraphs.append(Paragraph(fix_br_tags(paragraph_text), styles["Normal"]))
|
296 |
+
except:
|
297 |
+
paragraphs.append(Paragraph(remove_html_tags(paragraph_text), styles["Normal"]))
|
298 |
paragraphs.append(Paragraph("<br/><br/>", styles["Normal"])) # Zusätzlicher Zeilenumbruch mit 12pt Abstand
|
299 |
|
300 |
for i, task in enumerate(st.session_state["tasks_for_interview"]):
|
301 |
paragraph_text = f"<font size='14'><b>Coding task {i+1}. :</b></font><br/><br/>{task['task']}<br/><b>Perfect answer:</b> {task['perfect_solution']}\n"
|
302 |
+
try:
|
303 |
+
paragraphs.append(Paragraph(paragraph_text, styles["Normal"]))
|
304 |
+
except:
|
305 |
+
try:
|
306 |
+
paragraphs.append(Paragraph(fix_br_tags(paragraph_text), styles["Normal"]))
|
307 |
+
except:
|
308 |
+
paragraphs.append(Paragraph(remove_html_tags(paragraph_text), styles["Normal"]))
|
309 |
paragraphs.append(Paragraph("<br/><br/>", styles["Normal"])) # Zusätzlicher Zeilenumbruch mit 12pt Abstand
|
310 |
|
311 |
# Füge die Paragraphen in das PDF-Dokument ein
|