Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| from datetime import date | |
| st.set_page_config(page_title="Male Intake Chatbot", layout="centered") | |
| st.title("๐ค Male Intake Chatbot") | |
| st.markdown("Welcome! I will guide you through the Male Intake Questionnaire step by step.") | |
| # Initialize session state | |
| if "step" not in st.session_state: | |
| st.session_state.step = 0 | |
| st.session_state.answers = {} | |
| questions = [ | |
| # Section: General Info | |
| ("general", "๐ง What is your full name?", "name", "text"), | |
| ("general", "๐ How old are you?", "age", "number"), | |
| ("general", "๐ What is your date of birth?", "dob", "date"), | |
| ("general", "๐ง What is your email address?", "email", "text"), | |
| ("general", "๐ What is your home address?", "address", "text"), | |
| ("general", "๐๏ธ City?", "city", "text"), | |
| ("general", "๐ State/Province?", "state", "text"), | |
| ("general", "๐ฎ Zip code?", "zip", "text"), | |
| # Section: Contact Info | |
| ("contact", "๐ Home phone number?", "phone_home", "text"), | |
| ("contact", "๐ฑ Cell phone number?", "phone_cell", "text"), | |
| ("contact", "โ๏ธ Work phone number?", "phone_work", "text"), | |
| # Section: Emergency | |
| ("emergency", "๐ค Emergency contact name?", "emergency_name", "text"), | |
| ("emergency", "๐ Relationship to you?", "emergency_relationship", "text"), | |
| ("emergency", "๐ Emergency contact home phone?", "emergency_phone_home", "text"), | |
| ("emergency", "๐ฑ Emergency contact cell phone?", "emergency_phone_cell", "text"), | |
| ("emergency", "โ๏ธ Emergency contact work phone?", "emergency_phone_work", "text"), | |
| # Section: Genetic Background | |
| ("genetic", "๐ What is your genetic background? (Separate multiple with commas)", "genetic_background", "text"), | |
| # Section: Nutrition | |
| ("nutrition", "๐ฅฆ Do you follow any special diets? (e.g., Vegan, Low Carb, etc.)", "special_diets", "text"), | |
| ("nutrition", "โ ๏ธ Do you have sensitivities to certain foods?", "food_sensitivities", "radio"), | |
| ("nutrition", "๐คข If yes, list the foods and symptoms", "sensitivity_details", "text"), | |
| ("nutrition", "๐ Do you have an aversion to certain foods?", "food_aversion", "radio"), | |
| ("nutrition", "๐ If yes, explain the aversion", "aversion_details", "text"), | |
| ("nutrition", "โค๏ธ Do you crave or binge on any food?", "food_cravings", "radio"), | |
| ("nutrition", "๐ซ If yes, what foods?", "craved_foods", "text"), | |
| # Section: Meals | |
| ("meals", "๐ฝ๏ธ Do you eat 3 meals per day?", "eat_3_meals", "radio"), | |
| ("meals", "๐ If no, how many meals?", "meals_count", "text"), | |
| ("meals", "๐ต Does skipping a meal affect you?", "skip_meal_effect", "radio"), | |
| ("meals", "๐ How many meals do you eat out per week? (0-1, 1-3, etc.)", "meals_out_per_week", "text"), | |
| # Section: Caffeine | |
| ("caffeine", "โ Do you drink caffeinated beverages?", "drink_caffeine", "radio"), | |
| ("caffeine", "โ Coffee (cups per day)?", "coffee_intake", "text"), | |
| ("caffeine", "๐ต Tea (cups per day)?", "tea_intake", "text"), | |
| ("caffeine", "๐ฅค Soda (cans per day)?", "soda_intake", "text"), | |
| ("caffeine", "๐ Any adverse reactions to caffeine?", "caffeine_reaction", "radio"), | |
| ("caffeine", "๐ If yes, explain:", "caffeine_reaction_detail", "text"), | |
| # Section: Smoking | |
| ("smoking", "๐ฌ Do you currently smoke?", "smoke_now", "radio"), | |
| ("smoking", "๐ฆ Packs per day?", "packs_per_day", "text"), | |
| ("smoking", "๐ Number of years?", "smoke_years", "text"), | |
| ("smoking", "๐ฆ What type? (Cigarette, Pipe, etc.)", "smoke_type", "text"), | |
| ("smoking", "๐ Have you tried quitting?", "tried_quit", "radio"), | |
| ("smoking", "๐ If yes, using what methods?", "quit_methods", "text"), | |
| # Section: Stress | |
| ("stress", "๐ฐ Do you feel you have too much stress?", "high_stress", "radio"), | |
| ("stress", "๐ง Can you handle stress easily?", "stress_handling", "radio"), | |
| ("stress", "๐ผ Rate work stress (1โ10)", "stress_work", "number"), | |
| ("stress", "๐จโ๐ฉโ๐งโ๐ฆ Rate family stress (1โ10)", "stress_family", "number"), | |
| ("stress", "๐ธ Rate financial stress (1โ10)", "stress_finance", "number"), | |
| # More sections like: History, Dental, Men's Health, Family, etc. can be added here similarly... | |
| ] | |
| # Step through questions | |
| if st.session_state.step < len(questions): | |
| section, question_text, field_name, field_type = questions[st.session_state.step] | |
| st.markdown(f"### Section: {section.capitalize()}") | |
| if field_type == "text": | |
| response = st.text_input(question_text) | |
| elif field_type == "number": | |
| response = st.number_input(question_text, step=1) | |
| elif field_type == "date": | |
| response = st.date_input(question_text, value=date(2000, 1, 1)) | |
| elif field_type == "radio": | |
| response = st.radio(question_text, ["Yes", "No"]) | |
| else: | |
| response = st.text_input(question_text) | |
| if response: | |
| st.session_state.answers[field_name] = response | |
| st.session_state.step += 1 | |
| st.experimental_rerun() | |
| else: | |
| st.success("๐ You've completed the intake chatbot!") | |
| st.json(st.session_state.answers) | |
| from reportlab.lib.pagesizes import letter | |
| from reportlab.pdfgen import canvas | |
| # Create a function to save intake form answers to PDF | |
| def save_intake_to_pdf(answers: dict, output_path: str): | |
| c = canvas.Canvas(output_path, pagesize=letter) | |
| width, height = letter | |
| line_height = 14 | |
| x_margin = 50 | |
| y = height - 50 | |
| c.setFont("Helvetica", 12) | |
| c.drawString(x_margin, y, "Male Intake Questionnaire - Summary") | |
| y -= line_height * 2 | |
| for key, value in answers.items(): | |
| # Wrap long values | |
| text = f"{key.replace('_', ' ').capitalize()}: {value}" | |
| lines = [] | |
| while len(text) > 90: | |
| split_pos = text.rfind(" ", 0, 90) | |
| lines.append(text[:split_pos]) | |
| text = text[split_pos+1:] | |
| lines.append(text) | |
| for line in lines: | |
| if y <= 50: | |
| c.showPage() | |
| y = height - 50 | |
| c.setFont("Helvetica", 12) | |
| c.drawString(x_margin, y, line) | |
| y -= line_height | |
| y -= 5 # extra spacing between entries | |
| c.save() | |
| return output_path | |
| # Example usage | |
| example_answers = { | |
| "name": "John Doe", | |
| "age": "35", | |
| "dob": "1989-03-15", | |
| "email": "[email protected]", | |
| "stress_work": 7, | |
| "smoke_now": "No", | |
| "food_sensitivities": "Yes", | |
| "sensitivity_details": "Dairy - causes bloating", | |
| } | |
| pdf_path = "intake_summary_example.pdf" | |
| save_intake_to_pdf(example_answers, pdf_path) | |