adhd_app_test / app.py
dizzafizza1's picture
Update app.py
7929442 verified
raw
history blame contribute delete
No virus
9.01 kB
import streamlit as st
import datetime
import time
import openai
# Set up OpenAI API key
openai.api_key = st.secrets["OPENAI_API_KEY"]
# Task Management
tasks = []
def add_task(task, due_date):
tasks.append({"task": task, "due_date": due_date, "completed": False})
def complete_task(index):
tasks[index]["completed"] = True
def task_management():
st.markdown(
f"""
<div class="main">
<h2>Task Management</h2>
<p>Create, organize, and prioritize tasks and to-do lists.</p>
<form>
<label for="task">Task:</label>
<input type="text" id="task" name="task" placeholder="Enter a task...">
<label for="due_date">Due Date:</label>
<input type="date" id="due_date" name="due_date">
<button type="submit">Add Task</button>
</form>
<h3>Tasks:</h3>
<ul>
{generate_task_list()}
</ul>
</div>
""",
unsafe_allow_html=True,
)
if st.button("Add Task"):
task = st.text_input("Task")
due_date = st.date_input("Due Date")
if task and due_date:
add_task(task, due_date)
def generate_task_list():
task_list = ""
for index, task in enumerate(tasks):
task_list += f'<li style="text-decoration: {"line-through" if task["completed"] else "none"}">{task["task"]} - Due: {task["due_date"]} <button onclick="complete_task({index})">Complete</button></li>'
return task_list
# Time Management
def pomodoro_timer(duration):
start_time = time.time()
end_time = start_time + duration * 60
while time.time() < end_time:
remaining_time = end_time - time.time()
minutes, seconds = divmod(remaining_time, 60)
timer_text = f"{int(minutes):02d}:{int(seconds):02d}"
st.markdown(
f"""
<div style="font-size: 48px; text-align: center; margin-top: 50px;">
{timer_text}
</div>
""",
unsafe_allow_html=True,
)
time.sleep(1)
st.markdown(
f"""
<div style="font-size: 48px; text-align: center; margin-top: 50px;">
Time's up!
</div>
""",
unsafe_allow_html=True,
)
def time_management():
st.markdown(
f"""
<div class="main">
<h2>Time Management</h2>
<p>Utilize timers, time-blocking, and scheduling tools to manage your time effectively.</p>
<h3>Pomodoro Timer</h3>
<div>
<label for="duration">Select duration (in minutes):</label>
<input type="number" id="duration" name="duration" min="1" max="60" value="25">
<button onclick="startTimer()">Start Timer</button>
</div>
<div id="timer"></div>
<h3>Time Blocking</h3>
<!-- Add time blocking calendar or schedule -->
</div>
""",
unsafe_allow_html=True,
)
duration = st.number_input("Select duration (in minutes)", min_value=1, max_value=60, value=25, step=1)
if st.button("Start Timer"):
pomodoro_timer(duration)
# Habit Tracking
habits = []
def add_habit(habit):
habits.append({"habit": habit, "streak": 0})
def increment_streak(index):
habits[index]["streak"] += 1
def habit_tracking():
st.markdown(
f"""
<div class="main">
<h2>Habit Tracking</h2>
<p>Set and track habits related to productivity, self-care, and well-being.</p>
<form>
<label for="habit">Habit:</label>
<input type="text" id="habit" name="habit" placeholder="Enter a habit...">
<button type="submit">Add Habit</button>
</form>
<h3>Habits:</h3>
<ul>
{generate_habit_list()}
</ul>
</div>
""",
unsafe_allow_html=True,
)
if st.button("Add Habit"):
habit = st.text_input("Habit")
if habit:
add_habit(habit)
def generate_habit_list():
habit_list = ""
for index, habit in enumerate(habits):
habit_list += f'<li>{habit["habit"]} - Streak: {habit["streak"]} <button onclick="increment_streak({index})">Increment Streak</button></li>'
return habit_list
# Workplace Strategies
def workplace_strategies():
st.markdown(
f"""
<div class="main">
<h2>Workplace Strategies</h2>
<p>Discover strategies for managing ADHD in the workplace.</p>
<ul>
<li>Use noise-canceling headphones to minimize distractions</li>
<li>Break tasks into smaller, manageable steps</li>
<li>Utilize visual organizers and calendars</li>
<li>Take regular breaks to recharge</li>
</ul>
</div>
""",
unsafe_allow_html=True,
)
# Resources
def resources():
st.markdown(
f"""
<div class="main">
<h2>Resources</h2>
<p>Explore a collection of helpful resources related to ADHD.</p>
<ul>
<li><a href="https://www.additudemag.com/" target="_blank">ADDitude Magazine</a></li>
<li><a href="https://chadd.org/" target="_blank">CHADD (Children and Adults with ADHD)</a></li>
<li><a href="https://www.understood.org/en/learning-thinking-differences/child-learning-disabilities/add-adhd" target="_blank">Understood.org - ADHD Resources</a></li>
</ul>
</div>
""",
unsafe_allow_html=True,
)
# AI-based Personalization
def get_chatgpt_response(prompt):
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant providing personalized recommendations for managing ADHD."},
{"role": "user", "content": prompt}
]
)
return response['choices'][0]['message']['content'].strip()
def personalization():
st.markdown(
f"""
<div class="main">
<h2>Personalization</h2>
<p>Get personalized recommendations for managing ADHD based on your responses.</p>
</div>
""",
unsafe_allow_html=True,
)
age = st.number_input("What is your age?", min_value=1, max_value=100, value=25, step=1)
occupation = st.text_input("What is your occupation?")
challenges = st.text_area("What are the main challenges you face with ADHD?")
if st.button("Get Personalized Recommendations"):
prompt = f"I am {age} years old, working as a {occupation}. The main challenges I face with ADHD are: {challenges}. Can you provide personalized recommendations for managing ADHD in my daily life and work?"
recommendations = get_chatgpt_response(prompt)
st.markdown(
f"""
<div class="main">
<h3>Personalized Recommendations:</h3>
<p>{recommendations}</p>
</div>
""",
unsafe_allow_html=True,
)
def main():
st.set_page_config(page_title="ADHD Toolkit", layout="wide")
# Define color scheme
primary_color = "#1E88E5"
secondary_color = "#90CAF9"
text_color = "#FFFFFF"
# Set up sidebar
st.markdown(
f"""
<style>
.sidebar .sidebar-content {{
background-color: {primary_color};
color: {text_color};
}}
.sidebar .sidebar-content a {{
color: {text_color};
}}
</style>
""",
unsafe_allow_html=True,
)
menu = ["Home", "Task Management", "Time Management", "Habit Tracking", "Workplace Strategies", "Resources", "Personalization"]
choice = st.sidebar.selectbox("Select a section", menu)
# Set up main content area
st.markdown(
f"""
<style>
.main {{
background-color: {secondary_color};
color: {text_color};
padding: 20px;
border-radius: 10px;
}}
</style>
""",
unsafe_allow_html=True,
)
if choice == "Home":
st.markdown(
f"""
<div class="main">
<h1>Welcome to the ADHD Toolkit!</h1>
<p>This app provides tools and resources to help manage ADHD.</p>
</div>
""",
unsafe_allow_html=True,
)
elif choice == "Task Management":
task_management()
elif choice == "Time Management":
time_management()
elif choice == "Habit Tracking":
habit_tracking()
elif choice == "Workplace Strategies":
workplace_strategies()
elif choice == "Resources":
resources()
elif choice == "Personalization":
personalization()
if __name__ == "__main__":
main()