EduNeXus / app.py
ibrahim313's picture
Update app.py
7fd2fab verified
raw
history blame
6.65 kB
import streamlit as st
import os
from groq import Groq
# Set the Groq API key
os.environ["GROQ_API_KEY"] = "your_groq_api_key_here" # 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": ""
}
# Set up page configuration
st.set_page_config(page_title="EduNexus", page_icon=":book:", layout="wide")
# Add custom styling using Streamlit
st.markdown("""
<style>
body {
background-color: #1e1e2d;
color: #e0e0e0;
}
.css-1o7k8tt {
background-color: #2f2f6f;
color: #ffffff;
}
.css-1o7k8tt h1 {
color: #d6a4a0;
}
.stButton {
background-color: #d6a4a0;
color: #ffffff;
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: #b35b5b;
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.5);
}
.stTextInput, .stTextArea {
border: 1px solid #d6a4a0;
border-radius: 12px;
background-color: #2f2f4f;
color: #ffffff;
}
.stTextInput::placeholder, .stTextArea::placeholder {
color: #a0a0a0;
}
.stSidebar {
background-color: #3e3e5f;
}
.stSidebar .stMarkdown {
color: #ffffff;
}
.footer {
background-color: #2e2e3e;
padding: 15px;
text-align: center;
color: #ffffff;
border-top: 1px solid #d6a4a0;
position: fixed;
bottom: 0;
width: 100%;
box-shadow: 0 -6px 12px rgba(0, 0, 0, 0.4);
}
.footer a {
color: #d6a4a0;
margin: 0 15px;
text-decoration: none;
font-size: 18px;
}
.footer a:hover {
color: #ffffff;
}
.footer i {
font-size: 22px;
}
</style>
""", unsafe_allow_html=True)
# Define function to clear all inputs
def clear_chat():
st.session_state['responses'] = {
"personalized_learning_assistant": "",
"ai_coding_mentor": "",
"smart_document_summarizer": "",
"interactive_study_planner": "",
"real_time_qa_support": "",
"mental_health_check_in": ""
}
# Initialize layout for buttons
def display_response(response_key, response):
st.write(response)
col1, col2 = st.columns([4, 1])
with col1:
st.download_button(
"Download Response",
response,
file_name=f"{response_key}.txt"
)
with col2:
if st.button("Clear", key=f"clear_{response_key}"):
st.session_state['responses'][response_key] = "" # Clear the response for the specific tool
# Initialize layout for form
def display_tool_form(tool_key, submit_function, placeholder):
with st.form(key=f"{tool_key}_form"):
input_text = st.text_area(f"Enter your {tool_key.replace('_', ' ')}", placeholder=placeholder)
col1, col2 = st.columns([3, 1])
with col1:
submit_button = st.form_submit_button("Get Explanation")
with col2:
clear_button = st.form_submit_button("Clear")
if submit_button:
response = submit_function(input_text)
st.session_state['responses'][tool_key] = response
if clear_button:
st.session_state['responses'][tool_key] = ""
st.title("EduNexus: Your Academic Assistant")
# Display forms for each tool
st.header("1. Personalized Learning Assistant")
display_tool_form("personalized_learning_assistant", personalized_learning_assistant, "Enter the topic you want to learn about...")
st.header("2. AI Coding Mentor")
display_tool_form("ai_coding_mentor", ai_coding_mentor, "Paste your code snippet here...")
st.header("3. Smart Document Summarizer")
display_tool_form("smart_document_summarizer", smart_document_summarizer, "Paste your document text here...")
st.header("4. Interactive Study Planner")
display_tool_form("interactive_study_planner", interactive_study_planner, "Enter your exam schedule here...")
st.header("5. Real-Time Q&A Support")
display_tool_form("real_time_qa_support", real_time_qa_support, "Ask your academic question here...")
st.header("6. Mental Health Check-In")
display_tool_form("mental_health_check_in", mental_health_check_in, "Share how you are feeling today...")
# Display responses
st.write("### Responses")
for key, response in st.session_state['responses'].items():
if response:
display_response(key, response)
# Footer
st.markdown("""
<div class="footer">
<a href="https://github.com/your-repo">GitHub</a> |
<a href="https://twitter.com/your-profile">Twitter</a> |
<a href="https://linkedin.com/in/your-profile">LinkedIn</a>
<br>
<i>EduNexus © 2024</i>
</div>
""", unsafe_allow_html=True)