shukdevdatta123 commited on
Commit
64d92ad
·
verified ·
1 Parent(s): 7457612

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -58
app.py CHANGED
@@ -1,8 +1,8 @@
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,49 +94,6 @@ 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
- # 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
- # Add full Output.json content (including AI prediction and all data)
124
- pdf.ln(10)
125
- pdf.cell(200, 10, txt="Full Output Information:", ln=True)
126
-
127
- # Break the full AI prediction into lines to avoid overflow
128
- full_output = json.dumps(output_data, indent=4)
129
- pdf.multi_cell(0, 10, full_output)
130
-
131
- # Save the PDF to a file
132
- pdf_file_path = 'flex_temp_personality_report.pdf'
133
- pdf.output(pdf_file_path)
134
-
135
- return pdf_file_path
136
- except Exception as e:
137
- st.error(f"Error occurred while generating the PDF report: {e}")
138
- return None
139
-
140
  # Streamlit component to display the quiz and handle responses
141
  def show_mbti_quiz():
142
  st.title('FlexTemp Personality Test')
@@ -174,7 +131,7 @@ def show_mbti_quiz():
174
  """
175
  try:
176
  response = openai.ChatCompletion.create(
177
- model="gpt-4",
178
  messages=[{"role": "system", "content": "You are a helpful assistant."},
179
  {"role": "user", "content": prompt}]
180
  )
@@ -207,17 +164,6 @@ def show_mbti_quiz():
207
  mime="application/json"
208
  )
209
 
210
- # Add the Download PDF button
211
- pdf_file_path = generate_pdf_report()
212
-
213
- if pdf_file_path:
214
- st.download_button(
215
- label="Download PDF Report",
216
- data=open(pdf_file_path, "rb").read(),
217
- file_name="FlexTemp_Personality_Report.pdf",
218
- mime="application/pdf"
219
- )
220
-
221
  else:
222
  st.warning("Please answer all the questions!")
223
 
@@ -225,7 +171,7 @@ def show_mbti_quiz():
225
  def main():
226
  # Add instructions to the sidebar
227
  with st.sidebar.expander("How This App Works", expanded=False):
228
- st.write("""
229
  ### FlexTemp Personality Test
230
  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:
231
  1. **Weighted MBTI Scoring**:
@@ -243,4 +189,4 @@ def main():
243
  st.info("Please enter your OpenAI API Key to begin the quiz.")
244
 
245
  if __name__ == "__main__":
246
- main()
 
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
  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')
 
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
  )
 
164
  mime="application/json"
165
  )
166
 
 
 
 
 
 
 
 
 
 
 
 
167
  else:
168
  st.warning("Please answer all the questions!")
169
 
 
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()