import streamlit as st import os from groq import Groq # Set up page configuration st.set_page_config(page_title="EduNexus", page_icon=":book:", layout="wide") # Set the Groq API key os.environ["GROQ_API_KEY"] = "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" # Replace with your actual API key # Initialize Groq client client = Groq(api_key=os.environ.get("GROQ_API_KEY")) # Define the LLaMA model to be used MODEL_NAME = "llama3-8b-8192" # Function to call Groq API def call_groq_api(prompt): try: chat_completion = client.chat.completions.create( messages=[{"role": "user", "content": prompt}], model=MODEL_NAME ) return chat_completion.choices[0].message.content except Exception as e: return f"Error: {str(e)}" # Define functions for each tool with few-shot examples def personalized_learning_assistant(topic): prompt = f""" Provide a personalized learning plan for the topic: {topic}. Example 1: For 'Machine Learning': 'Create a plan with courses on supervised learning, unsupervised learning, and neural networks. Include practical exercises and projects.' Example 2: For 'Data Science': 'Suggest a plan with a focus on data analysis, visualization, and statistical modeling. Recommend tools like Python, R, and SQL.' Example 3: For 'Web Development': 'Outline a plan that covers front-end and back-end development, including HTML, CSS, JavaScript, and server-side technologies.' Example 4: For '{topic}':""" return call_groq_api(prompt) def ai_coding_mentor(code_snippet): prompt = f""" Review this AI code snippet and provide suggestions or improvements: {code_snippet} Example 1: 'In the provided code, consider using a different activation function to improve performance.' Example 2: 'The code can be optimized by reducing redundant calculations and enhancing readability.' Example 3: 'Add comments to explain complex sections of the code for better understanding.' Example 4: 'For the provided snippet, suggest improvements or fixes:''' return call_groq_api(prompt) def smart_document_summarizer(document_text): prompt = f""" Summarize the following document: {document_text} Example 1: 'The document discusses the impact of climate change on global agriculture, emphasizing the need for sustainable practices.' Example 2: 'It provides an overview of recent advancements in AI technology and its applications in various fields.' Example 3: 'The text outlines the historical development of renewable energy sources and their future potential.' Example 4: 'Summarize this document:''' return call_groq_api(prompt) def interactive_study_planner(exam_schedule): prompt = f""" Create an interactive study plan based on this exam schedule: {exam_schedule} Example 1: 'For an exam schedule with subjects A, B, and C, create a plan that allocates study time for each subject and includes breaks.' Example 2: 'Plan should include daily study goals and revision sessions leading up to the exams.' Example 3: 'Suggest a study plan that balances subject preparation with relaxation to avoid burnout.' Example 4: 'Based on the provided schedule, create a study plan:''' return call_groq_api(prompt) def real_time_qa_support(question): prompt = f""" Provide an answer to the following academic question: {question} Example 1: 'Question: What is the capital of France? Answer: Paris.' Example 2: 'Question: Explain the theory of relativity. Answer: The theory of relativity, developed by Albert Einstein, includes two theories: special relativity and general relativity, explaining the relationship between space, time, and gravity.' Example 3: 'Question: What is the process of photosynthesis? Answer: Photosynthesis is the process by which green plants use sunlight to synthesize foods with the help of chlorophyll, water, and carbon dioxide.' Example 4: 'Answer this question:''' return call_groq_api(prompt) def mental_health_check_in(feelings): prompt = f""" Provide some advice based on these feelings: {feelings} Example 1: 'Feeling stressed? Try practicing mindfulness and deep breathing exercises to calm your mind.' Example 2: 'If you're feeling anxious, consider talking to a trusted friend or counselor for support.' Example 3: 'Feeling overwhelmed? Break your tasks into smaller steps and focus on completing them one at a time.' Example 4: 'Based on these feelings, provide advice:''' return call_groq_api(prompt) # Initialize session state if not already set if 'responses' not in st.session_state: st.session_state['responses'] = { "personalized_learning_assistant": "", "ai_coding_mentor": "", "smart_document_summarizer": "", "interactive_study_planner": "", "real_time_qa_support": "", "mental_health_check_in": "" } # Function to clear session state values def clear_session_state(): for key in st.session_state.keys(): if key.startswith('responses'): st.session_state[key] = "" if key in ['personalized_learning_assistant', 'ai_coding_mentor', 'smart_document_summarizer', 'interactive_study_planner', 'real_time_qa_support', 'mental_health_check_in']: st.session_state[key] = "" # Add custom styling using Streamlit st.markdown(""" """, unsafe_allow_html=True) # Display main title st.title("EduNexus") # Sidebar with tasks st.sidebar.title("Tasks") tasks = [ "📚 Personalized Learning Assistant", "🤖 AI Coding Mentor", "📄 Smart Document Summarizer", "🗓 Interactive Study Planner", "❓ Real-Time Q&A Support", "💬 Mental Health Check-In" ] selected_task = st.sidebar.radio("Select a task", tasks) # Main content area based on selected task st.header(f"Selected Task: {selected_task}") if selected_task == "📚 Personalized Learning Assistant": topic = st.text_input("Enter the topic for the learning plan:") if st.button("Generate Learning Plan"): st.session_state['responses']["personalized_learning_assistant"] = personalized_learning_assistant(topic) st.write(st.session_state['responses']["personalized_learning_assistant"]) elif selected_task == "🤖 AI Coding Mentor": code_snippet = st.text_area("Paste your AI code snippet here:") if st.button("Review Code"): st.session_state['responses']["ai_coding_mentor"] = ai_coding_mentor(code_snippet) st.write(st.session_state['responses']["ai_coding_mentor"]) elif selected_task == "📄 Smart Document Summarizer": document_text = st.text_area("Paste your document text here:") if st.button("Summarize Document"): st.session_state['responses']["smart_document_summarizer"] = smart_document_summarizer(document_text) st.write(st.session_state['responses']["smart_document_summarizer"]) elif selected_task == "🗓 Interactive Study Planner": exam_schedule = st.text_area("Enter your exam schedule here:") if st.button("Create Study Plan"): st.session_state['responses']["interactive_study_planner"] = interactive_study_planner(exam_schedule) st.write(st.session_state['responses']["interactive_study_planner"]) elif selected_task == "❓ Real-Time Q&A Support": question = st.text_input("Enter your academic question here:") if st.button("Get Answer"): st.session_state['responses']["real_time_qa_support"] = real_time_qa_support(question) st.write(st.session_state['responses']["real_time_qa_support"]) elif selected_task == "💬 Mental Health Check-In": feelings = st.text_input("How are you feeling today?") if st.button("Get Advice"): st.session_state['responses']["mental_health_check_in"] = mental_health_check_in(feelings) st.write(st.session_state['responses']["mental_health_check_in"]) # Add a footer with contact information st.markdown(""" """, unsafe_allow_html=True)