import streamlit as st
import os
from groq import Groq
import random
api_key="3ey76"
# Set up page configuration
st.set_page_config(page_title="EduNexus ๐", page_icon="๐", layout="wide")
# Initialize Groq client with API key
api_key = st.secrets["GROQ_API_KEY"]
client = Groq(api_key=api_key)
# Define the LLaMA model
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 tool functions
def personalized_learning_assistant(topic):
prompt = f"Create a personalized learning plan for the topic: {topic}"
return call_groq_api(prompt)
def ai_coding_mentor(code_snippet):
prompt = f"Review this code and provide improvements:\n{code_snippet}"
return call_groq_api(prompt)
def smart_document_summarizer(document_text):
prompt = f"Summarize this document:\n{document_text}"
return call_groq_api(prompt)
def interactive_study_planner(exam_schedule):
prompt = f"Create a study plan based on this exam schedule:\n{exam_schedule}"
return call_groq_api(prompt)
def real_time_qa_support(question):
prompt = f"Answer this question:\n{question}"
return call_groq_api(prompt)
def mental_health_check_in(feelings):
prompt = f"Provide supportive advice for someone feeling:\n{feelings}"
return call_groq_api(prompt)
# Initialize session state
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
def clear_response(key):
st.session_state['responses'][key] = ""
# Custom CSS
st.markdown("""
""", unsafe_allow_html=True)
# Main app
def main():
# Title
st.markdown("
๐ Welcome to EduNexus
", unsafe_allow_html=True)
st.markdown("Your AI-powered learning companion
", unsafe_allow_html=True)
# Sidebar navigation
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"
])
# Tool implementations
tools = {
"๐งโ๐ Personalized Learning Assistant": {
"key": "personalized_learning_assistant",
"function": personalized_learning_assistant,
"input_label": "What would you like to learn about? ๐ค",
"input_type": "text_input",
"description": "Create a personalized learning plan just for you!"
},
"๐ค AI Coding Mentor": {
"key": "ai_coding_mentor",
"function": ai_coding_mentor,
"input_label": "Paste your code here for review ๐จโ๐ป",
"input_type": "text_area",
"description": "Get expert code review and suggestions!"
},
# Add similar configurations for other tools
}
tool = tools.get(selected_task)
if tool:
st.markdown(f"""
""", unsafe_allow_html=True)
# Input field
if tool["input_type"] == "text_input":
user_input = st.text_input(tool["input_label"])
else:
user_input = st.text_area(tool["input_label"])
# Action buttons
col1, col2 = st.columns([1, 3])
with col1:
if st.button("๐งน Clear"):
clear_response(tool["key"])
st.rerun()
with col2:
if st.button("๐ Generate"):
if user_input:
with st.spinner("Processing..."):
st.session_state['responses'][tool["key"]] = tool["function"](user_input)
else:
st.session_state['responses'][tool["key"]] = "Please provide input to continue."
# Display response
st.markdown("", unsafe_allow_html=True)
st.markdown("### Response:")
st.markdown(st.session_state['responses'][tool["key"]])
st.markdown("
", unsafe_allow_html=True)
# Footer
st.markdown("""
""", unsafe_allow_html=True)
# 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()