Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,6 @@ import streamlit as st
|
|
| 2 |
import openai
|
| 3 |
import json
|
| 4 |
import os
|
| 5 |
-
from fpdf import FPDF
|
| 6 |
from dotenv import load_dotenv
|
| 7 |
|
| 8 |
# Load the OpenAI API Key
|
|
@@ -95,28 +94,6 @@ def save_personality_to_output_json(username, mbti_type_classic, mbti_type_llm):
|
|
| 95 |
with open("Output.json", "w") as json_file:
|
| 96 |
json.dump(output_data, json_file, indent=4)
|
| 97 |
|
| 98 |
-
# Function to generate PDF
|
| 99 |
-
def generate_pdf(mbti_type_classic, mbti_type_llm, participant_name):
|
| 100 |
-
pdf = FPDF()
|
| 101 |
-
pdf.set_auto_page_break(auto=True, margin=15)
|
| 102 |
-
pdf.add_page()
|
| 103 |
-
|
| 104 |
-
pdf.set_font("Arial", size=16, style="B")
|
| 105 |
-
pdf.cell(200, 10, txt="FlexTemp Personality Test Results", ln=True, align="C")
|
| 106 |
-
|
| 107 |
-
pdf.ln(10)
|
| 108 |
-
pdf.set_font("Arial", size=12)
|
| 109 |
-
|
| 110 |
-
pdf.cell(200, 10, txt=f"Name: {participant_name}", ln=True)
|
| 111 |
-
pdf.cell(200, 10, txt=f"Your MBTI type based on weighted answers: {mbti_type_classic}", ln=True)
|
| 112 |
-
pdf.cell(200, 10, txt=f"Your MBTI type according to AI: {mbti_type_llm}", ln=True)
|
| 113 |
-
|
| 114 |
-
# Save the PDF to a file
|
| 115 |
-
pdf_output = f"{participant_name}_mbti_results.pdf"
|
| 116 |
-
pdf.output(pdf_output)
|
| 117 |
-
|
| 118 |
-
return pdf_output
|
| 119 |
-
|
| 120 |
# Streamlit component to display the quiz and handle responses
|
| 121 |
def show_mbti_quiz():
|
| 122 |
st.title('FlexTemp Personality Test')
|
|
@@ -144,7 +121,6 @@ def show_mbti_quiz():
|
|
| 144 |
st.write(f"Your MBTI type based on weighted answers: {mbti_type_classic}")
|
| 145 |
|
| 146 |
# You can add LLM-based prediction if needed here (example OpenAI-based model)
|
| 147 |
-
mbti_type_llm = ""
|
| 148 |
if api_key:
|
| 149 |
# Run the LLM (GPT-4, for example) model to generate a personality type.
|
| 150 |
prompt = f"""
|
|
@@ -155,7 +131,7 @@ def show_mbti_quiz():
|
|
| 155 |
"""
|
| 156 |
try:
|
| 157 |
response = openai.ChatCompletion.create(
|
| 158 |
-
model="gpt-
|
| 159 |
messages=[{"role": "system", "content": "You are a helpful assistant."},
|
| 160 |
{"role": "user", "content": prompt}]
|
| 161 |
)
|
|
@@ -168,17 +144,6 @@ def show_mbti_quiz():
|
|
| 168 |
save_responses_to_json(participant_name, responses)
|
| 169 |
save_personality_to_output_json(participant_name, mbti_type_classic, mbti_type_llm)
|
| 170 |
|
| 171 |
-
# Generate and provide PDF download
|
| 172 |
-
pdf_output = generate_pdf(mbti_type_classic, mbti_type_llm, participant_name)
|
| 173 |
-
with open(pdf_output, "rb") as pdf_file:
|
| 174 |
-
st.download_button(
|
| 175 |
-
label="Download your MBTI results (PDF)",
|
| 176 |
-
data=pdf_file,
|
| 177 |
-
file_name=pdf_output,
|
| 178 |
-
mime="application/pdf"
|
| 179 |
-
)
|
| 180 |
-
|
| 181 |
-
# Provide options to download the JSON files
|
| 182 |
with open("Output.json", "r") as json_file:
|
| 183 |
json_data = json_file.read()
|
| 184 |
|
|
@@ -206,7 +171,7 @@ def show_mbti_quiz():
|
|
| 206 |
def main():
|
| 207 |
# Add instructions to the sidebar
|
| 208 |
with st.sidebar.expander("How This App Works", expanded=False):
|
| 209 |
-
st.write("""
|
| 210 |
### FlexTemp Personality Test
|
| 211 |
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:
|
| 212 |
1. **Weighted MBTI Scoring**:
|
|
@@ -224,4 +189,4 @@ def main():
|
|
| 224 |
st.info("Please enter your OpenAI API Key to begin the quiz.")
|
| 225 |
|
| 226 |
if __name__ == "__main__":
|
| 227 |
-
main()
|
|
|
|
| 2 |
import openai
|
| 3 |
import json
|
| 4 |
import os
|
|
|
|
| 5 |
from dotenv import load_dotenv
|
| 6 |
|
| 7 |
# Load the OpenAI API Key
|
|
|
|
| 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 |
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"""
|
|
|
|
| 131 |
"""
|
| 132 |
try:
|
| 133 |
response = openai.ChatCompletion.create(
|
| 134 |
+
model="gpt-4o",
|
| 135 |
messages=[{"role": "system", "content": "You are a helpful assistant."},
|
| 136 |
{"role": "user", "content": prompt}]
|
| 137 |
)
|
|
|
|
| 144 |
save_responses_to_json(participant_name, responses)
|
| 145 |
save_personality_to_output_json(participant_name, mbti_type_classic, mbti_type_llm)
|
| 146 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
with open("Output.json", "r") as json_file:
|
| 148 |
json_data = json_file.read()
|
| 149 |
|
|
|
|
| 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 |
st.info("Please enter your OpenAI API Key to begin the quiz.")
|
| 190 |
|
| 191 |
if __name__ == "__main__":
|
| 192 |
+
main()
|