Spaces:
Sleeping
Sleeping
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: #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: #a0a0a0; /* Gray */ | |
} | |
.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; | |
} | |
</style> | |
""", unsafe_allow_html=True) | |
# 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 | |
if selected_task == "Personalized Learning Assistant": | |
st.header("Personalized Learning Assistant") | |
with st.form(key="personalized_learning_assistant_form"): | |
topic = st.text_area("Enter the topic you want to learn about") | |
submit_button = st.form_submit_button("Get Explanation") | |
if submit_button: | |
response = personalized_learning_assistant(topic) | |
st.write(response) | |
elif selected_task == "AI Coding Mentor": | |
st.header("AI Coding Mentor") | |
with st.form(key="ai_coding_mentor_form"): | |
code_snippet = st.text_area("Paste your code snippet here") | |
submit_button = st.form_submit_button("Get Review") | |
if submit_button: | |
response = ai_coding_mentor(code_snippet) | |
st.write(response) | |
elif selected_task == "Smart Document Summarizer": | |
st.header("Smart Document Summarizer") | |
with st.form(key="smart_document_summarizer_form"): | |
document_text = st.text_area("Paste your document text here") | |
submit_button = st.form_submit_button("Get Summary") | |
if submit_button: | |
response = smart_document_summarizer(document_text) | |
st.write(response) | |
elif selected_task == "Interactive Study Planner": | |
st.header("Interactive Study Planner") | |
with st.form(key="interactive_study_planner_form"): | |
exam_schedule = st.text_area("Enter your exam schedule here") | |
submit_button = st.form_submit_button("Create Study Plan") | |
if submit_button: | |
response = interactive_study_planner(exam_schedule) | |
st.write(response) | |
elif selected_task == "Real-Time Q&A Support": | |
st.header("Real-Time Q&A Support") | |
with st.form(key="real_time_qa_support_form"): | |
question = st.text_area("Ask your academic question here") | |
submit_button = st.form_submit_button("Get Answer") | |
if submit_button: | |
response = real_time_qa_support(question) | |
st.write(response) | |
elif selected_task == "Mental Health Check-In": | |
st.header("Mental Health Check-In") | |
with st.form(key="mental_health_check_in_form"): | |
feelings = st.text_area("Share how you are feeling today") | |
submit_button = st.form_submit_button("Get Advice") | |
if submit_button: | |
response = mental_health_check_in(feelings) | |
st.write(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) | |