Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
import streamlit as st
|
2 |
import openai
|
3 |
import json
|
|
|
4 |
import os
|
5 |
-
from dotenv import load_dotenv
|
6 |
|
7 |
# Load the OpenAI API Key
|
8 |
api_key = st.text_input('Enter your OpenAI API Key', type="password")
|
@@ -94,6 +94,41 @@ def save_personality_to_output_json(username, mbti_type_classic, mbti_type_llm):
|
|
94 |
with open("Output.json", "w") as json_file:
|
95 |
json.dump(output_data, json_file, indent=4)
|
96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
# Streamlit component to display the quiz and handle responses
|
98 |
def show_mbti_quiz():
|
99 |
st.title('FlexTemp Personality Test')
|
@@ -164,6 +199,17 @@ def show_mbti_quiz():
|
|
164 |
mime="application/json"
|
165 |
)
|
166 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
else:
|
168 |
st.warning("Please answer all the questions!")
|
169 |
|
@@ -171,7 +217,7 @@ def show_mbti_quiz():
|
|
171 |
def main():
|
172 |
# Add instructions to the sidebar
|
173 |
with st.sidebar.expander("How This App Works", expanded=False):
|
174 |
-
st.write("""
|
175 |
### FlexTemp Personality Test
|
176 |
This app is designed to help you determine your MBTI personality type based on your answers to a series of questions. The process works as follows:
|
177 |
1. **Weighted MBTI Scoring**:
|
@@ -189,4 +235,4 @@ def main():
|
|
189 |
st.info("Please enter your OpenAI API Key to begin the quiz.")
|
190 |
|
191 |
if __name__ == "__main__":
|
192 |
-
main()
|
|
|
1 |
import streamlit as st
|
2 |
import openai
|
3 |
import json
|
4 |
+
from fpdf import FPDF
|
5 |
import os
|
|
|
6 |
|
7 |
# Load the OpenAI API Key
|
8 |
api_key = st.text_input('Enter your OpenAI API Key', type="password")
|
|
|
94 |
with open("Output.json", "w") as json_file:
|
95 |
json.dump(output_data, json_file, indent=4)
|
96 |
|
97 |
+
# Function to generate a PDF report from Output.json data
|
98 |
+
def generate_pdf_report():
|
99 |
+
# Load the Output.json data
|
100 |
+
try:
|
101 |
+
with open("Output.json", "r") as json_file:
|
102 |
+
output_data = json.load(json_file)
|
103 |
+
|
104 |
+
# Create PDF object
|
105 |
+
pdf = FPDF()
|
106 |
+
pdf.set_auto_page_break(auto=True, margin=15)
|
107 |
+
pdf.add_page()
|
108 |
+
|
109 |
+
# Set font
|
110 |
+
pdf.set_font("Arial", size=12)
|
111 |
+
|
112 |
+
# Title of the report
|
113 |
+
pdf.cell(200, 10, txt="FlexTemp Personality Test Report", ln=True, align='C')
|
114 |
+
|
115 |
+
# Add username
|
116 |
+
pdf.ln(10)
|
117 |
+
pdf.cell(200, 10, txt=f"Name: {output_data['username']}", ln=True)
|
118 |
+
|
119 |
+
# Add MBTI types
|
120 |
+
pdf.cell(200, 10, txt=f"MBTI Type (Classic): {output_data['mbti_type_classic']}", ln=True)
|
121 |
+
pdf.cell(200, 10, txt=f"MBTI Type (AI Prediction): {output_data['mbti_type_llm']}", ln=True)
|
122 |
+
|
123 |
+
# Save the PDF to a file
|
124 |
+
pdf_file_path = '/mnt/data/flex_temp_personality_report.pdf'
|
125 |
+
pdf.output(pdf_file_path)
|
126 |
+
|
127 |
+
return pdf_file_path
|
128 |
+
except Exception as e:
|
129 |
+
st.error(f"Error occurred while generating the PDF report: {e}")
|
130 |
+
return None
|
131 |
+
|
132 |
# Streamlit component to display the quiz and handle responses
|
133 |
def show_mbti_quiz():
|
134 |
st.title('FlexTemp Personality Test')
|
|
|
199 |
mime="application/json"
|
200 |
)
|
201 |
|
202 |
+
# Add the Download PDF button
|
203 |
+
pdf_file_path = generate_pdf_report()
|
204 |
+
|
205 |
+
if pdf_file_path:
|
206 |
+
st.download_button(
|
207 |
+
label="Download PDF Report",
|
208 |
+
data=open(pdf_file_path, "rb").read(),
|
209 |
+
file_name="FlexTemp_Personality_Report.pdf",
|
210 |
+
mime="application/pdf"
|
211 |
+
)
|
212 |
+
|
213 |
else:
|
214 |
st.warning("Please answer all the questions!")
|
215 |
|
|
|
217 |
def main():
|
218 |
# Add instructions to the sidebar
|
219 |
with st.sidebar.expander("How This App Works", expanded=False):
|
220 |
+
st.write("""
|
221 |
### FlexTemp Personality Test
|
222 |
This app is designed to help you determine your MBTI personality type based on your answers to a series of questions. The process works as follows:
|
223 |
1. **Weighted MBTI Scoring**:
|
|
|
235 |
st.info("Please enter your OpenAI API Key to begin the quiz.")
|
236 |
|
237 |
if __name__ == "__main__":
|
238 |
+
main()
|