import os import streamlit as st from groq import Groq # Set your API key here os.environ["GROQ_API_KEY"] = "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" # Initialize Groq API client client = Groq(api_key=os.environ.get("GROQ_API_KEY")) # Streamlit Interface st.title("Personalized Study Assistant Chatbot") st.write("Optimize your study plan with tailored guidance based on your schedule and goals.") # Collect user input subject = st.text_input("Enter the subject or exam you're preparing for:") days = st.number_input("Enter the number of days you have to prepare:", min_value=1) hours_per_day = st.number_input("Enter the number of hours you can dedicate per day:", min_value=1) if st.button("Generate Study Plan"): if subject and days > 0 and hours_per_day > 0: # Construct prompt for the study assistant chatbot prompt = (f"I am preparing for {subject} with {days} days to study and " f"{hours_per_day} hours available each day. Provide a structured study plan, " "including daily milestones, recommended study resources, " "and time management tips for optimal preparation.") # Use Groq API to get the completion chat_completion = client.chat.completions.create( messages=[ { "role": "user", "content": prompt, } ], model="llama3-8b-8192", ) # Display the generated study plan response = chat_completion.choices[0].message.content st.subheader("Your Personalized Study Plan:") st.write(response) else: st.warning("Please fill in all fields to generate your study plan.") # Optional: Motivational Message Button if st.button("Need Motivation?"): motivation_prompt = "Provide a brief motivational message for a student preparing for exams." motivation_completion = client.chat.completions.create( messages=[{"role": "user", "content": motivation_prompt}], model="llama3-8b-8192", ) motivation_message = motivation_completion.choices[0].message.content st.write(motivation_message)