import os
import streamlit as st
from groq import Groq
# Set up the Groq client and API key
GROQ_API_KEY = "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"
os.environ["GROQ_API_KEY"] = GROQ_API_KEY
client = Groq(api_key=os.getenv("GROQ_API_KEY"))
# Define the response fetching function
def get_study_plan(prompt):
chat_completion = client.chat.completions.create(
messages=[{"role": "user", "content": prompt}],
model="llama3-8b-8192"
)
return chat_completion.choices[0].message.content
# Streamlit UI
st.set_page_config(page_title="Personalized Study Chatbot", layout="wide")
st.markdown(
"
Developed by Muhammad Khaqan Nasir
",
unsafe_allow_html=True
)
# LinkedIn icon and link
st.markdown(
"""
""",
unsafe_allow_html=True
)
st.title("📘 Personalized Study Plan Generator")
st.write("Quickly generate a tailored study plan with tips and resources to help you prepare efficiently!")
# Include Poppins font and increase font size globally, set content width to 100%
st.markdown(
"""
""", unsafe_allow_html=True
)
# Input fields for user details
study_goal = st.text_input("🎯 Study Goal (e.g., pass physics exam, learn programming basics):", placeholder="Your study objective")
total_days = st.number_input("📅 Number of days to prepare:", min_value=1, max_value=365, step=1)
hours_per_day = st.number_input("⏰ Hours available per day:", min_value=1, max_value=24, step=1)
# Button to generate the study plan
if st.button("Generate My Study Plan"):
prompt = (
f"You are a personalized study assistant chatbot designed to help users prepare for exams and master subjects. "
f"The user has {total_days} days to prepare, dedicating {hours_per_day} hours per day. "
f"Their goal is: '{study_goal}'. Create a structured plan with practical tips, links to high-quality, free learning resources, "
f"and include the best YouTube channels if applicable."
"\nIf direct links are unavailable, provide names of resources. Add a summary, schedule, study tips, and 2–3 recommended resources (e.g., Khan Academy, Coursera) for free access.\n"
)
# Fetch response
response = get_study_plan(prompt)
# Display the response with enhanced styling
st.markdown("Your Personalized Study Plan
", unsafe_allow_html=True)
st.markdown(f"{response}
", unsafe_allow_html=True)
# Additional Resources Section
st.markdown("📚 Recommended Learning Resources
", unsafe_allow_html=True)
st.write("Here are some highly recommended resources for your study:")
st.markdown(
"""
- [Khan Academy](https://www.khanacademy.org) - Comprehensive courses on a variety of topics.
- [Coursera](https://www.coursera.org) - Free courses from top universities.
- [OpenStax](https://openstax.org/) - Free textbooks on many subjects.
- [YouTube](https://www.youtube.com) - Search for trusted channels like CrashCourse, 3Blue1Brown, or freeCodeCamp.
""", unsafe_allow_html=True
)
# Optional Additional UX Enhancements with expander section
with st.expander("🛠️ Additional Tips & Enhancements"):
st.write("1. **Set Clear Goals:** Break down your study goal into smaller, actionable tasks.")
st.write("2. **Daily Reflections:** Reflect on what you've learned to retain information better.")
st.write("3. **Mock Tests:** Simulate exam conditions to test your knowledge.")