Spaces:
Sleeping
Sleeping
added PDF download
Browse files- app.py +31 -4
- requirements.txt +2 -1
app.py
CHANGED
@@ -4,6 +4,12 @@ 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
|
@@ -37,6 +43,8 @@ def get_coding_task_topics():
|
|
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"]
|
@@ -229,9 +237,28 @@ for i, task in enumerate(st.session_state["tasks_for_interview"]):
|
|
229 |
st.divider()
|
230 |
if len(st.session_state["questions_for_interview"]) > 0 and len(st.session_state["tasks_for_interview"]) > 0:
|
231 |
st.write("You can now save the questions and coding tasks for your interview.")
|
232 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
233 |
for i, question in enumerate(st.session_state["questions_for_interview"]):
|
234 |
-
|
|
|
|
|
|
|
235 |
for i, task in enumerate(st.session_state["tasks_for_interview"]):
|
236 |
-
|
237 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
import uuid
|
5 |
import streamlit as st
|
6 |
import math
|
7 |
+
from io import BytesIO
|
8 |
+
from reportlab.lib.pagesizes import letter
|
9 |
+
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, PageTemplate, Frame, Image
|
10 |
+
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
|
11 |
+
from reportlab.lib.units import inch
|
12 |
+
from reportlab.lib.utils import ImageReader
|
13 |
from datetime import datetime, timedelta
|
14 |
from dotenv import load_dotenv
|
15 |
from typing import List
|
|
|
43 |
st.error("Someting went wrong. Please try again later.", icon="🚨")
|
44 |
|
45 |
def get_questions(topic):
|
46 |
+
topic = topic.replace(" ", "%20")
|
47 |
+
topic = topic.replace("&", "%26")
|
48 |
url = os.environ["BASE_URL"]+"/questions"+f"?dimension={topic}"
|
49 |
headers = {
|
50 |
"x-api-key": os.environ["API_KEY"]
|
|
|
237 |
st.divider()
|
238 |
if len(st.session_state["questions_for_interview"]) > 0 and len(st.session_state["tasks_for_interview"]) > 0:
|
239 |
st.write("You can now save the questions and coding tasks for your interview.")
|
240 |
+
|
241 |
+
# Erstelle eine BytesIO, um die PDF im Speicher zu halten
|
242 |
+
pdf_buffer = BytesIO()
|
243 |
+
doc = SimpleDocTemplate(pdf_buffer, pagesize=letter, title="Interview Questions")
|
244 |
+
|
245 |
+
styles = getSampleStyleSheet()
|
246 |
+
paragraphs = []
|
247 |
for i, question in enumerate(st.session_state["questions_for_interview"]):
|
248 |
+
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"
|
249 |
+
paragraphs.append(Paragraph(paragraph_text, styles["Normal"]))
|
250 |
+
paragraphs.append(Paragraph("<br/><br/>", styles["Normal"])) # Zusätzlicher Zeilenumbruch mit 12pt Abstand
|
251 |
+
|
252 |
for i, task in enumerate(st.session_state["tasks_for_interview"]):
|
253 |
+
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"
|
254 |
+
paragraphs.append(Paragraph(paragraph_text, styles["Normal"]))
|
255 |
+
paragraphs.append(Paragraph("<br/><br/>", styles["Normal"])) # Zusätzlicher Zeilenumbruch mit 12pt Abstand
|
256 |
+
|
257 |
+
# Füge die Paragraphen in das PDF-Dokument ein
|
258 |
+
doc.build(paragraphs)
|
259 |
+
|
260 |
+
# Speichere die PDF und schließe den Stream
|
261 |
+
pdf_buffer.seek(0)
|
262 |
+
|
263 |
+
# Zeige den Download-Button für die PDF an
|
264 |
+
st.download_button(label="Download", data=pdf_buffer, file_name="interview_questions.pdf", mime="application/pdf")
|
requirements.txt
CHANGED
@@ -1,2 +1,3 @@
|
|
1 |
streamlit
|
2 |
-
python-dotenv
|
|
|
|
1 |
streamlit
|
2 |
+
python-dotenv
|
3 |
+
reportlab
|