Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,9 @@ os.environ["GROQ_API_KEY"] = "gsk_BYXg06vIXpWdFjwDMLnFWGdyb3FYjlovjvzUzo5jtu5A1I
|
|
7 |
# Initialize Groq client
|
8 |
client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
|
9 |
|
|
|
|
|
|
|
10 |
# Define the LLaMA model to be used
|
11 |
MODEL_NAME = "llama3-8b-8192"
|
12 |
|
@@ -24,107 +27,83 @@ def call_groq_api(prompt):
|
|
24 |
# Define functions for each tool
|
25 |
def personalized_learning_assistant(topic):
|
26 |
examples = [
|
27 |
-
"Explain quantum mechanics
|
28 |
-
"
|
29 |
-
"
|
30 |
]
|
31 |
-
prompt = f"Here are some
|
32 |
return call_groq_api(prompt)
|
33 |
|
34 |
def ai_coding_mentor(code_snippet):
|
35 |
examples = [
|
36 |
-
"Review
|
37 |
-
"
|
38 |
]
|
39 |
-
prompt = f"Here are some
|
40 |
return call_groq_api(prompt)
|
41 |
|
42 |
def smart_document_summarizer(document_text):
|
43 |
examples = [
|
44 |
-
"Summarize
|
45 |
-
"
|
46 |
]
|
47 |
-
prompt = f"Here are some
|
48 |
return call_groq_api(prompt)
|
49 |
|
50 |
def interactive_study_planner(exam_schedule):
|
51 |
examples = [
|
52 |
-
"
|
53 |
-
"
|
54 |
]
|
55 |
-
prompt = f"Here are some
|
56 |
return call_groq_api(prompt)
|
57 |
|
58 |
def real_time_qa_support(question):
|
59 |
examples = [
|
60 |
-
"
|
61 |
-
"
|
62 |
]
|
63 |
-
prompt = f"Here are some examples of
|
64 |
return call_groq_api(prompt)
|
65 |
|
66 |
def mental_health_check_in(feelings):
|
67 |
examples = [
|
68 |
-
"
|
69 |
-
"
|
70 |
]
|
71 |
-
prompt = f"Here are some examples of mental health advice:\n\n{examples}\n\nProvide advice
|
72 |
return call_groq_api(prompt)
|
73 |
|
74 |
# Define Streamlit app
|
75 |
st.set_page_config(page_title="EduNexus", page_icon=":book:", layout="wide")
|
76 |
|
77 |
-
# Add custom
|
78 |
st.markdown("""
|
79 |
<style>
|
80 |
-
|
81 |
-
background:
|
82 |
-
color: #
|
83 |
-
font-family: 'Arial', sans-serif;
|
84 |
-
overflow-x: hidden;
|
85 |
}
|
86 |
-
.
|
87 |
-
|
88 |
-
color: #ff0081;
|
89 |
-
text-shadow: ;
|
90 |
-
margin-bottom: 20px;
|
91 |
-
}
|
92 |
-
.neon-border {
|
93 |
-
border: 2px solid #ff0081;
|
94 |
-
border-radius: 8px;
|
95 |
-
padding: 15px;
|
96 |
-
margin-bottom: 20px;
|
97 |
-
box-shadow: 0 0 15px #ff0081;
|
98 |
}
|
99 |
-
.
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
border: none;
|
104 |
-
border-radius: 8px;
|
105 |
padding: 10px 20px;
|
106 |
font-size: 16px;
|
107 |
-
cursor: pointer;
|
108 |
-
margin: 10px 0;
|
109 |
-
}
|
110 |
-
.animated-button:hover {
|
111 |
-
background-color: #cc0077;
|
112 |
}
|
113 |
-
.
|
114 |
-
|
115 |
}
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
100% { transform: scale(1); }
|
120 |
}
|
121 |
</style>
|
122 |
""", unsafe_allow_html=True)
|
123 |
|
124 |
-
# Title and introduction
|
125 |
-
st.title("EduNexus: The Ultimate AI-Powered Student Companion")
|
126 |
-
st.markdown("<div class='neon-text'>Welcome to EduNexus! Choose a tool below to get started.</div>", unsafe_allow_html=True)
|
127 |
-
|
128 |
# Define function to clear all inputs
|
129 |
def clear_chat():
|
130 |
st.session_state['personalized_learning_assistant'] = ""
|
@@ -134,72 +113,69 @@ def clear_chat():
|
|
134 |
st.session_state['real_time_qa_support'] = ""
|
135 |
st.session_state['mental_health_check_in'] = ""
|
136 |
|
137 |
-
# Add Clear Chat button
|
138 |
-
if st.button("Clear All", key="clear_button"
|
139 |
clear_chat()
|
140 |
|
141 |
-
#
|
142 |
-
st.
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
st.
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
st.
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
if
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
st.
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
st.write(mental_health_check_in(feelings_input))
|
204 |
-
else:
|
205 |
-
st.write("Please describe your feelings.")
|
|
|
7 |
# Initialize Groq client
|
8 |
client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
|
9 |
|
10 |
+
|
11 |
+
|
12 |
+
|
13 |
# Define the LLaMA model to be used
|
14 |
MODEL_NAME = "llama3-8b-8192"
|
15 |
|
|
|
27 |
# Define functions for each tool
|
28 |
def personalized_learning_assistant(topic):
|
29 |
examples = [
|
30 |
+
"Explain quantum mechanics with a real-world example.",
|
31 |
+
"Describe general relativity and its significance.",
|
32 |
+
"Provide a simple explanation of machine learning and its applications."
|
33 |
]
|
34 |
+
prompt = f"Here are some example explanations:\n\n{examples}\n\nNow, explain the topic: {topic}. Provide a detailed, yet simple explanation with a practical example."
|
35 |
return call_groq_api(prompt)
|
36 |
|
37 |
def ai_coding_mentor(code_snippet):
|
38 |
examples = [
|
39 |
+
"Review this code snippet for optimization opportunities:\n\nCode: 'for i in range(10): print(i)'\nSuggestion: Use list comprehension for more efficient code.",
|
40 |
+
"Analyze this code snippet for best practices:\n\nCode: 'def add(a, b): return a + b'\nSuggestion: Include type hints to improve readability and maintainability."
|
41 |
]
|
42 |
+
prompt = f"Here are some code review examples:\n\n{examples}\n\nReview the following code snippet and provide suggestions for improvement:\n{code_snippet}. Include any potential issues or improvements."
|
43 |
return call_groq_api(prompt)
|
44 |
|
45 |
def smart_document_summarizer(document_text):
|
46 |
examples = [
|
47 |
+
"Summarize this text:\n\nText: 'Quantum computing represents a revolutionary approach to computing that leverages quantum mechanics.'\nSummary: 'Quantum computing uses quantum mechanics to advance computing technology.'",
|
48 |
+
"Create a summary for this passage:\n\nText: 'The rise of electric vehicles is a major step towards reducing global carbon emissions and combating climate change.'\nSummary: 'Electric vehicles help reduce carbon emissions and fight climate change.'"
|
49 |
]
|
50 |
+
prompt = f"Here are some document summarization examples:\n\n{examples}\n\nSummarize the following document text concisely:\n{document_text}. Focus on capturing the main points clearly."
|
51 |
return call_groq_api(prompt)
|
52 |
|
53 |
def interactive_study_planner(exam_schedule):
|
54 |
examples = [
|
55 |
+
"Generate a study plan for a schedule with multiple exams in a week:\n\nSchedule: '3 exams in one week'\nPlan: 'Allocate 2 hours per subject each day, with review sessions on weekends.'",
|
56 |
+
"Create a study plan for preparing for exams over a period of 2 weeks:\n\nSchedule: 'Exams in 2 weeks'\nPlan: 'Prioritize subjects based on difficulty and importance, with daily reviews and mock tests.'"
|
57 |
]
|
58 |
+
prompt = f"Here are some study planning examples:\n\n{examples}\n\nCreate a tailored study plan based on the following schedule:\n{exam_schedule}. Include daily study goals and break times."
|
59 |
return call_groq_api(prompt)
|
60 |
|
61 |
def real_time_qa_support(question):
|
62 |
examples = [
|
63 |
+
"Provide an answer to this question:\n\nQuestion: 'What is Newton's third law of motion?'\nAnswer: 'Newton's third law states that for every action, there is an equal and opposite reaction.'",
|
64 |
+
"Explain this concept:\n\nQuestion: 'What is the principle of conservation of energy?'\nAnswer: 'The principle of conservation of energy states that energy cannot be created or destroyed, only transformed from one form to another.'"
|
65 |
]
|
66 |
+
prompt = f"Here are some examples of answers to academic questions:\n\n{examples}\n\nAnswer the following question:\n{question}. Provide a clear and comprehensive explanation."
|
67 |
return call_groq_api(prompt)
|
68 |
|
69 |
def mental_health_check_in(feelings):
|
70 |
examples = [
|
71 |
+
"Offer advice for managing exam stress:\n\nFeeling: 'Stressed about upcoming exams'\nAdvice: 'Develop a study schedule, take regular breaks, and practice relaxation techniques.'",
|
72 |
+
"Provide support for feeling overwhelmed:\n\nFeeling: 'Feeling overwhelmed with coursework'\nAdvice: 'Break tasks into smaller, manageable parts and seek support from peers or a counselor.'"
|
73 |
]
|
74 |
+
prompt = f"Here are some examples of mental health advice:\n\n{examples}\n\nProvide advice based on the following feeling:\n{feelings}. Offer practical suggestions for improving well-being."
|
75 |
return call_groq_api(prompt)
|
76 |
|
77 |
# Define Streamlit app
|
78 |
st.set_page_config(page_title="EduNexus", page_icon=":book:", layout="wide")
|
79 |
|
80 |
+
# Add custom styling using Streamlit
|
81 |
st.markdown("""
|
82 |
<style>
|
83 |
+
.css-1o7k8tt {
|
84 |
+
background-color: #282c34;
|
85 |
+
color: #ffffff;
|
|
|
|
|
86 |
}
|
87 |
+
.css-1o7k8tt h1 {
|
88 |
+
color: #61dafb;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
}
|
90 |
+
.stButton {
|
91 |
+
background-color: #61dafb;
|
92 |
+
color: #000000;
|
93 |
+
border-radius: 12px;
|
|
|
|
|
94 |
padding: 10px 20px;
|
95 |
font-size: 16px;
|
|
|
|
|
|
|
|
|
|
|
96 |
}
|
97 |
+
.stButton:hover {
|
98 |
+
background-color: #4fa3d1;
|
99 |
}
|
100 |
+
.stTextInput, .stTextArea {
|
101 |
+
border: 1px solid #61dafb;
|
102 |
+
border-radius: 8px;
|
|
|
103 |
}
|
104 |
</style>
|
105 |
""", unsafe_allow_html=True)
|
106 |
|
|
|
|
|
|
|
|
|
107 |
# Define function to clear all inputs
|
108 |
def clear_chat():
|
109 |
st.session_state['personalized_learning_assistant'] = ""
|
|
|
113 |
st.session_state['real_time_qa_support'] = ""
|
114 |
st.session_state['mental_health_check_in'] = ""
|
115 |
|
116 |
+
# Add Clear Chat button
|
117 |
+
if st.button("Clear All", key="clear_button"):
|
118 |
clear_chat()
|
119 |
|
120 |
+
# Navigation sidebar
|
121 |
+
st.sidebar.title("EduNexus Tools")
|
122 |
+
selected_tool = st.sidebar.radio(
|
123 |
+
"Select a tool",
|
124 |
+
("Personalized Learning Assistant", "AI Coding Mentor", "Smart Document Summarizer",
|
125 |
+
"Interactive Study Planner", "Real-Time Q&A Support", "Mental Health Check-In")
|
126 |
+
)
|
127 |
+
|
128 |
+
# Display tool based on selection
|
129 |
+
if selected_tool == "Personalized Learning Assistant":
|
130 |
+
st.header("Personalized Learning Assistant")
|
131 |
+
with st.form(key="learning_form"):
|
132 |
+
topic_input = st.text_input("Enter a topic you want to learn about", placeholder="e.g., Quantum Mechanics")
|
133 |
+
submit_button = st.form_submit_button("Get Explanation")
|
134 |
+
if submit_button:
|
135 |
+
explanation = personalized_learning_assistant(topic_input)
|
136 |
+
st.write(explanation)
|
137 |
+
|
138 |
+
elif selected_tool == "AI Coding Mentor":
|
139 |
+
st.header("AI Coding Mentor")
|
140 |
+
with st.form(key="coding_form"):
|
141 |
+
code_input = st.text_area("Enter your code snippet", placeholder="e.g., def add(a, b): return a + b")
|
142 |
+
submit_button = st.form_submit_button("Review Code")
|
143 |
+
if submit_button:
|
144 |
+
review = ai_coding_mentor(code_input)
|
145 |
+
st.write(review)
|
146 |
+
|
147 |
+
elif selected_tool == "Smart Document Summarizer":
|
148 |
+
st.header("Smart Document Summarizer")
|
149 |
+
with st.form(key="summarizer_form"):
|
150 |
+
document_input = st.text_area("Enter the text you want to summarize", placeholder="Paste document text here...")
|
151 |
+
submit_button = st.form_submit_button("Summarize Document")
|
152 |
+
if submit_button:
|
153 |
+
summary = smart_document_summarizer(document_input)
|
154 |
+
st.write(summary)
|
155 |
+
|
156 |
+
elif selected_tool == "Interactive Study Planner":
|
157 |
+
st.header("Interactive Study Planner")
|
158 |
+
with st.form(key="planner_form"):
|
159 |
+
schedule_input = st.text_area("Enter your exam schedule", placeholder="e.g., 3 exams in 1 week")
|
160 |
+
submit_button = st.form_submit_button("Generate Study Plan")
|
161 |
+
if submit_button:
|
162 |
+
study_plan = interactive_study_planner(schedule_input)
|
163 |
+
st.write(study_plan)
|
164 |
+
|
165 |
+
elif selected_tool == "Real-Time Q&A Support":
|
166 |
+
st.header("Real-Time Q&A Support")
|
167 |
+
with st.form(key="qa_form"):
|
168 |
+
question_input = st.text_input("Ask any academic question", placeholder="e.g., What is Newton's second law?")
|
169 |
+
submit_button = st.form_submit_button("Get Answer")
|
170 |
+
if submit_button:
|
171 |
+
answer = real_time_qa_support(question_input)
|
172 |
+
st.write(answer)
|
173 |
+
|
174 |
+
elif selected_tool == "Mental Health Check-In":
|
175 |
+
st.header("Mental Health Check-In")
|
176 |
+
with st.form(key="checkin_form"):
|
177 |
+
feelings_input = st.text_area("How are you feeling?", placeholder="e.g., Stressed about exams")
|
178 |
+
submit_button = st.form_submit_button("Check In")
|
179 |
+
if submit_button:
|
180 |
+
advice = mental_health_check_in(feelings_input)
|
181 |
+
st.write(advice)
|
|
|
|
|
|