Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ 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 +95,33 @@ 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')
|
@@ -121,8 +149,10 @@ def show_mbti_quiz():
|
|
121 |
st.write(f"Your MBTI type based on weighted answers: {mbti_type_classic}")
|
122 |
|
123 |
# You can add LLM-based prediction if needed here (example OpenAI-based model)
|
|
|
|
|
|
|
124 |
if api_key:
|
125 |
-
# Run the LLM (GPT-4, for example) model to generate a personality type.
|
126 |
prompt = f"""
|
127 |
Determine a person's personality type based on their answers to the following Myers-Briggs Type Indicator (MBTI) questions:
|
128 |
The person has answered the following questions:
|
@@ -164,6 +194,16 @@ def show_mbti_quiz():
|
|
164 |
mime="application/json"
|
165 |
)
|
166 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
else:
|
168 |
st.warning("Please answer all the questions!")
|
169 |
|
@@ -171,8 +211,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**:
|
178 |
- Each question corresponds to a trait in the MBTI system.
|
@@ -181,7 +220,7 @@ def main():
|
|
181 |
2. **LLM-Based Prediction**:
|
182 |
- Optionally, you can also get your MBTI type based on the answers using a language model (LLM) like GPT-4. This provides an additional prediction that may offer insights into your personality.
|
183 |
- The LLM is trained on vast amounts of data and can generate responses based on patterns from psychological research and real-world interactions.
|
184 |
-
|
185 |
|
186 |
if api_key:
|
187 |
show_mbti_quiz()
|
|
|
3 |
import json
|
4 |
import os
|
5 |
from dotenv import load_dotenv
|
6 |
+
from fpdf import FPDF
|
7 |
|
8 |
# Load the OpenAI API Key
|
9 |
api_key = st.text_input('Enter your OpenAI API Key', type="password")
|
|
|
95 |
with open("Output.json", "w") as json_file:
|
96 |
json.dump(output_data, json_file, indent=4)
|
97 |
|
98 |
+
# Function to generate a PDF report
|
99 |
+
def generate_pdf_report(participant_name, mbti_type_classic, mbti_type_llm):
|
100 |
+
pdf = FPDF()
|
101 |
+
pdf.set_auto_page_break(auto=True, margin=15)
|
102 |
+
pdf.add_page()
|
103 |
+
|
104 |
+
# Set fonts and title
|
105 |
+
pdf.set_font("Arial", 'B', 16)
|
106 |
+
pdf.cell(200, 10, txt="MBTI Personality Report", ln=True, align="C")
|
107 |
+
|
108 |
+
# Add participant name
|
109 |
+
pdf.ln(10)
|
110 |
+
pdf.set_font("Arial", '', 12)
|
111 |
+
pdf.cell(200, 10, txt=f"Participant Name: {participant_name}", ln=True)
|
112 |
+
|
113 |
+
# Add MBTI information
|
114 |
+
pdf.ln(10)
|
115 |
+
pdf.set_font("Arial", 'I', 12)
|
116 |
+
pdf.cell(200, 10, txt=f"Your MBTI type based on weighted answers: {mbti_type_classic}", ln=True)
|
117 |
+
pdf.cell(200, 10, txt=f"Your MBTI type according to AI: {mbti_type_llm}", ln=True)
|
118 |
+
|
119 |
+
# Save the PDF to a temporary file
|
120 |
+
pdf_output_path = "/tmp/mbti_report.pdf"
|
121 |
+
pdf.output(pdf_output_path)
|
122 |
+
|
123 |
+
return pdf_output_path
|
124 |
+
|
125 |
# Streamlit component to display the quiz and handle responses
|
126 |
def show_mbti_quiz():
|
127 |
st.title('FlexTemp Personality Test')
|
|
|
149 |
st.write(f"Your MBTI type based on weighted answers: {mbti_type_classic}")
|
150 |
|
151 |
# You can add LLM-based prediction if needed here (example OpenAI-based model)
|
152 |
+
mbti_type_llm = "Not Available" # Placeholder for now
|
153 |
+
|
154 |
+
# Run the LLM (GPT-4, for example) model to generate a personality type.
|
155 |
if api_key:
|
|
|
156 |
prompt = f"""
|
157 |
Determine a person's personality type based on their answers to the following Myers-Briggs Type Indicator (MBTI) questions:
|
158 |
The person has answered the following questions:
|
|
|
194 |
mime="application/json"
|
195 |
)
|
196 |
|
197 |
+
# Generate and add the button for the PDF report
|
198 |
+
pdf_report_path = generate_pdf_report(participant_name, mbti_type_classic, mbti_type_llm)
|
199 |
+
with open(pdf_report_path, "rb") as pdf_file:
|
200 |
+
st.download_button(
|
201 |
+
label="Download Generated Report",
|
202 |
+
data=pdf_file,
|
203 |
+
file_name="MBTI_Report.pdf",
|
204 |
+
mime="application/pdf"
|
205 |
+
)
|
206 |
+
|
207 |
else:
|
208 |
st.warning("Please answer all the questions!")
|
209 |
|
|
|
211 |
def main():
|
212 |
# Add instructions to the sidebar
|
213 |
with st.sidebar.expander("How This App Works", expanded=False):
|
214 |
+
st.write(""" ### FlexTemp Personality Test
|
|
|
215 |
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:
|
216 |
1. **Weighted MBTI Scoring**:
|
217 |
- Each question corresponds to a trait in the MBTI system.
|
|
|
220 |
2. **LLM-Based Prediction**:
|
221 |
- Optionally, you can also get your MBTI type based on the answers using a language model (LLM) like GPT-4. This provides an additional prediction that may offer insights into your personality.
|
222 |
- The LLM is trained on vast amounts of data and can generate responses based on patterns from psychological research and real-world interactions.
|
223 |
+
""")
|
224 |
|
225 |
if api_key:
|
226 |
show_mbti_quiz()
|