Spaces:
Sleeping
Sleeping
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 | |
def personalized_learning_assistant(topic): | |
prompt = f"Provide a personalized learning plan for the topic: {topic}" | |
return call_groq_api(prompt) | |
def ai_coding_mentor(code_snippet): | |
prompt = f"Review this AI code snippet and provide suggestions or improvements:\n\n{code_snippet}" | |
return call_groq_api(prompt) | |
def smart_document_summarizer(document_text): | |
prompt = f"Summarize the following document:\n\n{document_text}" | |
return call_groq_api(prompt) | |
def interactive_study_planner(exam_schedule): | |
prompt = f"Create an interactive study plan based on this exam schedule:\n\n{exam_schedule}" | |
return call_groq_api(prompt) | |
def real_time_qa_support(question): | |
prompt = f"Provide an answer to the following academic question:\n\n{question}" | |
return call_groq_api(prompt) | |
def mental_health_check_in(feelings): | |
prompt = f"Provide some advice based on these feelings:\n\n{feelings}" | |
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": "" | |
} | |
if 'clear_all' not in st.session_state: | |
st.session_state['clear_all'] = False | |
# Add custom styling using Streamlit | |
st.markdown(""" | |
<style> | |
body { | |
background-color: #000000; /* Royal Black */ | |
color: #ffffff; /* White */ | |
} | |
.css-1o7k8tt { | |
background-color: #000000; /* Royal Black */ | |
color: #ffffff; /* White */ | |
} | |
.stButton { | |
background-color: #ffffff; /* White */ | |
color: #000000; /* Royal Black */ | |
border-radius: 12px; | |
padding: 12px 24px; | |
font-size: 16px; | |
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4); | |
transition: background-color 0.3s, box-shadow 0.3s; | |
} | |
.stButton:hover { | |
background-color: #d3d3d3; /* Light Gray */ | |
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.5); | |
} | |
.stTextInput, .stTextArea { | |
border: 1px solid #ffffff; /* White */ | |
border-radius: 12px; | |
background-color: #000000; /* Royal Black */ | |
color: #ffffff; /* White */ | |
} | |
.stTextInput::placeholder, .stTextArea::placeholder { | |
color: #ffffff; /* White */ | |
font-weight: bold; | |
} | |
.stSidebar { | |
background-color: #000000; /* Royal Black */ | |
color: #ffffff; /* White */ | |
} | |
.stSidebar .stMarkdown { | |
color: #ffffff; /* White */ | |
} | |
.footer { | |
background-color: #000000; /* Royal Black */ | |
padding: 15px; | |
text-align: center; | |
color: #ffffff; /* White */ | |
border-top: 1px solid #ffffff; /* White */ | |
position: fixed; | |
bottom: 0; | |
width: 100%; | |
} | |
.footer a { | |
color: #ffffff; /* White */ | |
margin: 0 15px; | |
text-decoration: none; | |
font-size: 18px; | |
} | |
.footer a:hover { | |
color: #d3d3d3; /* Light Gray */ | |
} | |
.footer i { | |
font-size: 22px; | |
} | |
.css-1n8h7zm .stTextArea::placeholder, | |
.css-1n8h7zm .stTextInput::placeholder { | |
color: #ffffff; /* White */ | |
font-weight: bold; | |
} | |
</style> | |
""", 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 layout based on selected task | |
def handle_task_form(task_key, prompt_function, input_label, response_key): | |
with st.form(key=f"{task_key}_form"): | |
st.markdown(f"<div style='color: #ffffff; font-weight: bold;'>{input_label}</div>", unsafe_allow_html=True) | |
user_input = st.text_area("", key=task_key) | |
submit_button = st.form_submit_button("Get Response") | |
clear_button = st.form_submit_button("Clear") | |
if submit_button: | |
response = prompt_function(user_input) | |
st.session_state['responses'][response_key] = response | |
st.write(response) | |
if clear_button: | |
st.session_state['responses'][response_key] = "" | |
st.session_state[task_key] = "" # Clear form input | |
st.session_state['clear_all'] = True | |
if selected_task == "π Personalized Learning Assistant": | |
st.header("Personalized Learning Assistant") | |
handle_task_form( | |
"personalized_learning_assistant", | |
personalized_learning_assistant, | |
"Enter the topic you want to learn about", | |
"personalized_learning_assistant" | |
) | |
elif selected_task == "π€ AI Coding Mentor": | |
st.header("AI Coding Mentor") | |
handle_task_form( | |
"ai_coding_mentor", | |
ai_coding_mentor, | |
"Paste your code snippet here", | |
"ai_coding_mentor" | |
) | |
elif selected_task == "π Smart Document Summarizer": | |
st.header("Smart Document Summarizer") | |
handle_task_form( | |
"smart_document_summarizer", | |
smart_document_summarizer, | |
"Paste your document text here", | |
"smart_document_summarizer" | |
) | |
elif selected_task == "ποΈ Interactive Study Planner": | |
st.header("Interactive Study Planner") | |
handle_task_form( | |
"interactive_study_planner", | |
interactive_study_planner, | |
"Enter your exam schedule here", | |
"interactive_study_planner" | |
) | |
elif selected_task == "π¬ Real-Time Q&A Support": | |
st.header("Real-Time Q&A Support") | |
handle_task_form( | |
"real_time_qa_support", | |
real_time_qa_support, | |
"Ask your academic question here", | |
"real_time_qa_support" | |
) | |
elif selected_task == "π§ Mental Health Check-In": | |
st.header("Mental Health Check-In") | |
with st.form(key="mental_health_check_in_form"): | |
st.markdown("<div style='color: #ffffff; font-weight: bold;'>Share how you are feeling today</div>", unsafe_allow_html=True) | |
feelings = st.text_area("", key="mental_health_check_in") | |
col1, col2 = st.columns([2, 1]) | |
with col1: | |
submit_button = st.form_submit_button("Get Advice") | |
with col2: | |
clear_button = st.form_submit_button("Clear") | |
if submit_button: | |
response = mental_health_check_in(feelings) | |
st.session_state['responses']['mental_health_check_in'] = response | |
st.write(response) | |
if clear_button: | |
st.session_state['responses']['mental_health_check_in'] = "" | |
st.session_state['mental_health_check_in'] = "" # Clear form input | |
st.session_state['clear_all'] = True | |
# Footer | |
st.markdown(""" | |
<div class="footer"> | |
<a href="https://github.com/muhammadibrahim313">GitHub</a> | | |
<a href="https://www.kaggle.com/itshappy">Kaggle</a> | | |
<a href="https://www.linkedin.com/in/muhammadibrahim313">LinkedIn</a> | |
<i>EduNexus 2024</i> | |
</div> | |
""", unsafe_allow_html=True) | |