shukdevdatta123 commited on
Commit
d183d81
·
verified ·
1 Parent(s): d8eeeab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -7
app.py CHANGED
@@ -98,10 +98,13 @@ def generate_pdf_report(participant_name, responses, mbti_type_classic, mbti_typ
98
  pdf.cell(200, 10, txt=f"Your MBTI Type (Weighted): {mbti_type_classic}", ln=True)
99
  pdf.cell(200, 10, txt=f"Your MBTI Type (AI Prediction): {mbti_type_llm}", ln=True)
100
 
101
- # Save PDF
102
- file_path = f"{participant_name}_MBTI_report.pdf" # Save in the current directory
103
- pdf.output(file_path)
104
- return file_path
 
 
 
105
 
106
  # Streamlit component to display the quiz and handle responses
107
  def show_mbti_quiz():
@@ -141,7 +144,7 @@ def show_mbti_quiz():
141
  """
142
  try:
143
  response = openai.ChatCompletion.create(
144
- model="gpt-4o",
145
  messages=[{"role": "system", "content": "You are a helpful assistant."},
146
  {"role": "user", "content": prompt}]
147
  )
@@ -151,8 +154,15 @@ def show_mbti_quiz():
151
  st.error(f"Error occurred: {e}")
152
 
153
  # Generate PDF Report
154
- file_path = generate_pdf_report(participant_name, responses, mbti_type_classic, mbti_type_llm)
155
- st.download_button("Download your MBTI report", file_path)
 
 
 
 
 
 
 
156
 
157
  else:
158
  st.warning("Please answer all the questions!")
 
98
  pdf.cell(200, 10, txt=f"Your MBTI Type (Weighted): {mbti_type_classic}", ln=True)
99
  pdf.cell(200, 10, txt=f"Your MBTI Type (AI Prediction): {mbti_type_llm}", ln=True)
100
 
101
+ # Save PDF to a memory buffer
102
+ from io import BytesIO
103
+ pdf_output = BytesIO()
104
+ pdf.output(pdf_output)
105
+ pdf_output.seek(0) # Reset pointer to the start of the buffer
106
+
107
+ return pdf_output
108
 
109
  # Streamlit component to display the quiz and handle responses
110
  def show_mbti_quiz():
 
144
  """
145
  try:
146
  response = openai.ChatCompletion.create(
147
+ model="gpt-4",
148
  messages=[{"role": "system", "content": "You are a helpful assistant."},
149
  {"role": "user", "content": prompt}]
150
  )
 
154
  st.error(f"Error occurred: {e}")
155
 
156
  # Generate PDF Report
157
+ pdf_output = generate_pdf_report(participant_name, responses, mbti_type_classic, mbti_type_llm)
158
+
159
+ # Create a download button for the PDF
160
+ st.download_button(
161
+ label="Download your MBTI report",
162
+ data=pdf_output,
163
+ file_name=f"{participant_name}_MBTI_report.pdf",
164
+ mime="application/pdf"
165
+ )
166
 
167
  else:
168
  st.warning("Please answer all the questions!")