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"", unsafe_allow_html=True)
if selected_task == "๐งโ๐ Personalized Learning Assistant":
st.markdown("""
""", 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("""
""", 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("""
""", 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("""
""", 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("""
""", 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("""
""", 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()