import streamlit as st import os from groq import Groq from streamlit.components.v1 import html import random # Set up page configuration st.set_page_config(page_title="EduNexus ๐Ÿš€", page_icon="๐Ÿš€", layout="wide") api_key = st.secrets["GROQ_API_KEY"] client = Groq(api_key=api_key) # Define the LLaMA model to be used MODEL_NAME = "llama3-8b-8192" # Replace with your actual model name # 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 (unchanged) def personalized_learning_assistant(topic): # ... (unchanged) def ai_coding_mentor(code_snippet): # ... (unchanged) def smart_document_summarizer(document_text): # ... (unchanged) def interactive_study_planner(exam_schedule): # ... (unchanged) def real_time_qa_support(question): # ... (unchanged) def mental_health_check_in(feelings): # ... (unchanged) # 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] = "" # Function to load custom CSS def load_css(): return """ """ # Inject custom CSS st.markdown(load_css(), unsafe_allow_html=True) # Main content area with 3D-inspired title st.markdown("

๐Ÿš€ Welcome to EduNexus

", unsafe_allow_html=True) st.markdown("

Your AI-powered learning companion for the 21st century

", unsafe_allow_html=True) # Sidebar with navigation options st.sidebar.markdown("

๐Ÿง  EduNexus Tools

", unsafe_allow_html=True) selected_task = st.sidebar.radio("Select a Tool", [ "๐Ÿง‘โ€๐ŸŽ“ Personalized Learning Assistant", "๐Ÿค– AI Coding Mentor", "๐Ÿ“„ Smart Document Summarizer", "๐Ÿ—“ Interactive Study Planner", "โ“ Real-Time Q&A Support", "๐Ÿ’ฌ Mental Health Check-In" ]) # Display the selected task based on user selection st.markdown(f"

{selected_task}

", unsafe_allow_html=True) if selected_task == "๐Ÿง‘โ€๐ŸŽ“ Personalized Learning Assistant": st.markdown("""

๐ŸŽ“Create Your Learning Journey

Enter a topic you're interested in, and let our AI craft a personalized learning plan just for you!

""", unsafe_allow_html=True) topic = st.text_input("What would you like to learn about? ๐Ÿค”") col1, col2 = st.columns([1, 3]) with col1: if st.button("๐Ÿงน Clear"): st.session_state['responses']["personalized_learning_assistant"] = "" st.rerun() with col2: if st.button("๐Ÿš€ Generate Learning Plan"): if topic: with st.spinner("Crafting your personalized learning journey..."): st.session_state['responses']["personalized_learning_assistant"] = personalized_learning_assistant(topic) else: st.session_state['responses']["personalized_learning_assistant"] = "Please enter a topic to get started on your learning adventure! ๐Ÿ“š" st.markdown("
", unsafe_allow_html=True) st.markdown("### Your Personalized Learning Plan:") st.markdown(st.session_state['responses']["personalized_learning_assistant"]) st.markdown("
", unsafe_allow_html=True) elif selected_task == "๐Ÿค– AI Coding Mentor": st.markdown("""

๐Ÿ’ปGet Expert Code Review

Paste your code snippet below, and our AI mentor will provide insightful suggestions and improvements!

""", unsafe_allow_html=True) code_snippet = st.text_area("Paste your code here for review ๐Ÿ‘จโ€๐Ÿ’ป") col1, col2 = st.columns([1, 3]) with col1: if st.button("๐Ÿงน Clear"): st.session_state['responses']["ai_coding_mentor"] = "" st.rerun() with col2: if st.button("๐Ÿ” Analyze Code"): if code_snippet: with st.spinner("Analyzing your code with AI precision..."): st.session_state['responses']["ai_coding_mentor"] = ai_coding_mentor(code_snippet) else: st.session_state['responses']["ai_coding_mentor"] = "Please enter a code snippet for our AI to review and enhance! ๐Ÿ–ฅ๏ธ" st.markdown("
", unsafe_allow_html=True) st.markdown("### AI Code Review Results:") st.code(st.session_state['responses']["ai_coding_mentor"]) st.markdown("
", unsafe_allow_html=True) elif selected_task == "๐Ÿ“„ Smart Document Summarizer": st.markdown("""

๐Ÿ“šSummarize Any Document

Paste your document text, and watch as our AI distills it into a concise, informative summary!

""", unsafe_allow_html=True) document_text = st.text_area("Paste your document text here ๐Ÿ“") col1, col2 = st.columns([1, 3]) with col1: if st.button("๐Ÿงน Clear"): st.session_state['responses']["smart_document_summarizer"] = "" st.rerun() with col2: if st.button("๐Ÿ“Š Summarize"): if document_text: with st.spinner("Condensing your document into a brilliant summary..."): st.session_state['responses']["smart_document_summarizer"] = smart_document_summarizer(document_text) else: st.session_state['responses']["smart_document_summarizer"] = "Please paste a document for our AI to summarize! ๐Ÿ“„" st.markdown("
", unsafe_allow_html=True) st.markdown("### Your Document Summary:") st.markdown(st.session_state['responses']["smart_document_summarizer"]) st.markdown("
", unsafe_allow_html=True) elif selected_task == "๐Ÿ—“ Interactive Study Planner": st.markdown("""

๐Ÿ“…Plan Your Study Schedule

Input your exam dates and subjects, and let our AI create a tailored study plan to maximize your success!

""", unsafe_allow_html=True) exam_schedule = st.text_area("Enter your exam schedule (e.g., 'Math: May 15, Physics: May 20') ๐Ÿ“†") col1, col2 = st.columns([1, 3]) with col1: if st.button("๐Ÿงน Clear"): st.session_state['responses']["interactive_study_planner"] = "" st.rerun() with col2: if st.button("๐ŸŽฏ Create Study Plan"): if exam_schedule: with st.spinner("Crafting your personalized study strategy..."): st.session_state['responses']["interactive_study_planner"] = interactive_study_planner(exam_schedule) else: st.session_state['responses']["interactive_study_planner"] = "Please enter your exam schedule to get a customized study plan! ๐Ÿ“š" st.markdown("
", unsafe_allow_html=True) st.markdown("### Your Personalized Study Plan:") st.markdown(st.session_state['responses']["interactive_study_planner"]) st.markdown("
", unsafe_allow_html=True) elif selected_task == "โ“ Real-Time Q&A Support": st.markdown("""

๐Ÿค”Ask Anything, Anytime

Got a burning question? Our AI is ready to provide instant, accurate answers to fuel your curiosity!

""", unsafe_allow_html=True) question = st.text_input("What's your question? ๐Ÿง") col1, col2 = st.columns([1, 3]) with col1: if st.button("๐Ÿงน Clear"): st.session_state['responses']["real_time_qa_support"] = "" st.rerun() with col2: if st.button("๐Ÿ’ก Get Answer"): if question: with st.spinner("Searching the depths of knowledge for your answer..."): st.session_state['responses']["real_time_qa_support"] = real_time_qa_support(question) else: st.session_state['responses']["real_time_qa_support"] = "Please ask a question to unlock the wisdom of our AI! ๐Ÿ”“" st.markdown("
", unsafe_allow_html=True) st.markdown("### Your Answer:") st.markdown(st.session_state['responses']["real_time_qa_support"]) st.markdown("
", unsafe_allow_html=True) elif selected_task == "๐Ÿ’ฌ Mental Health Check-In": st.markdown("""

๐ŸŒˆYour Emotional Wellness Companion

Share how you're feeling, and let our AI provide supportive advice and resources for your mental well-being.

""", unsafe_allow_html=True) feelings = st.text_input("How are you feeling today? ๐Ÿ’ญ") col1, col2 = st.columns([1, 3]) with col1: if st.button("๐Ÿงน Clear"): st.session_state['responses']["mental_health_check_in"] = "" st.rerun() with col2: if st.button("๐Ÿค— Get Support"): if feelings: with st.spinner("Analyzing your emotions with care and empathy..."): st.session_state['responses']["mental_health_check_in"] = mental_health_check_in(feelings) else: st.session_state['responses']["mental_health_check_in"] = "Please share how you're feeling so we can offer personalized support. ๐Ÿ’–" st.markdown("
", unsafe_allow_html=True) st.markdown("### Your Personalized Support:") st.markdown(st.session_state['responses']["mental_health_check_in"]) st.markdown("
", unsafe_allow_html=True) # Animated background st.markdown("""
""", unsafe_allow_html=True) # Footer with contact information st.markdown(""" """, unsafe_allow_html=True) # Add some playful elements st.balloons() # Display a random inspirational quote quotes = [ "The capacity to learn is a gift; the ability to learn is a skill; the willingness to learn is a choice. - Brian Herbert", "Education is the passport to the future, for tomorrow belongs to those who prepare for it today. - Malcolm X", "The beautiful thing about learning is that nobody can take it away from you. - B.B. King", "The more that you read, the more things you will know. The more that you learn, the more places you'll go. - Dr. Seuss", "Live as if you were to die tomorrow. Learn as if you were to live forever. - Mahatma Gandhi" ] st.sidebar.markdown(f"### ๐Ÿ’ก Quote of the Day\n\n*{random.choice(quotes)}*") if __name__ == "__main__": main()