drkareemkamal commited on
Commit
814a280
Β·
verified Β·
1 Parent(s): b489ee9

Update chatbot_app.py

Browse files
Files changed (1) hide show
  1. chatbot_app.py +54 -1
chatbot_app.py CHANGED
@@ -100,4 +100,57 @@ if st.session_state.step < len(questions):
100
  st.experimental_rerun()
101
  else:
102
  st.success("πŸŽ‰ You've completed the intake chatbot!")
103
- st.json(st.session_state.answers)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  st.experimental_rerun()
101
  else:
102
  st.success("πŸŽ‰ You've completed the intake chatbot!")
103
+ st.json(st.session_state.answers)
104
+
105
+
106
+ from reportlab.lib.pagesizes import letter
107
+ from reportlab.pdfgen import canvas
108
+
109
+ # Create a function to save intake form answers to PDF
110
+ def save_intake_to_pdf(answers: dict, output_path: str):
111
+ c = canvas.Canvas(output_path, pagesize=letter)
112
+ width, height = letter
113
+ line_height = 14
114
+ x_margin = 50
115
+ y = height - 50
116
+
117
+ c.setFont("Helvetica", 12)
118
+ c.drawString(x_margin, y, "Male Intake Questionnaire - Summary")
119
+ y -= line_height * 2
120
+
121
+ for key, value in answers.items():
122
+ # Wrap long values
123
+ text = f"{key.replace('_', ' ').capitalize()}: {value}"
124
+ lines = []
125
+ while len(text) > 90:
126
+ split_pos = text.rfind(" ", 0, 90)
127
+ lines.append(text[:split_pos])
128
+ text = text[split_pos+1:]
129
+ lines.append(text)
130
+
131
+ for line in lines:
132
+ if y <= 50:
133
+ c.showPage()
134
+ y = height - 50
135
+ c.setFont("Helvetica", 12)
136
+ c.drawString(x_margin, y, line)
137
+ y -= line_height
138
+
139
+ y -= 5 # extra spacing between entries
140
+
141
+ c.save()
142
+ return output_path
143
+
144
+ # Example usage
145
+ example_answers = {
146
+ "name": "John Doe",
147
+ "age": "35",
148
+ "dob": "1989-03-15",
149
+ "email": "[email protected]",
150
+ "stress_work": 7,
151
+ "smoke_now": "No",
152
+ "food_sensitivities": "Yes",
153
+ "sensitivity_details": "Dairy - causes bloating",
154
+ }
155
+ pdf_path = "intake_summary_example.pdf"
156
+ save_intake_to_pdf(example_answers, pdf_path)