Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,87 @@
|
|
|
|
1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
# Define Streamlit app
|
4 |
st.set_page_config(page_title="EduNexus", page_icon=":book:", layout="wide")
|
@@ -62,12 +145,6 @@ st.markdown("""
|
|
62 |
|
63 |
# Define function to clear all inputs
|
64 |
def clear_chat():
|
65 |
-
st.session_state['personalized_learning_assistant'] = ""
|
66 |
-
st.session_state['ai_coding_mentor'] = ""
|
67 |
-
st.session_state['smart_document_summarizer'] = ""
|
68 |
-
st.session_state['interactive_study_planner'] = ""
|
69 |
-
st.session_state['real_time_qa_support'] = ""
|
70 |
-
st.session_state['mental_health_check_in'] = ""
|
71 |
st.session_state['responses'] = {
|
72 |
"personalized_learning_assistant": "",
|
73 |
"ai_coding_mentor": "",
|
@@ -125,8 +202,8 @@ elif selected_tool == "AI Coding Mentor":
|
|
125 |
|
126 |
elif selected_tool == "Smart Document Summarizer":
|
127 |
st.header("Smart Document Summarizer")
|
128 |
-
with st.form(key="
|
129 |
-
document_input = st.text_area("
|
130 |
submit_button = st.form_submit_button("Summarize Document")
|
131 |
if submit_button:
|
132 |
summary = smart_document_summarizer(document_input)
|
@@ -136,19 +213,19 @@ elif selected_tool == "Smart Document Summarizer":
|
|
136 |
|
137 |
elif selected_tool == "Interactive Study Planner":
|
138 |
st.header("Interactive Study Planner")
|
139 |
-
with st.form(key="
|
140 |
-
|
141 |
-
submit_button = st.form_submit_button("
|
142 |
if submit_button:
|
143 |
-
|
144 |
-
st.session_state['responses']['interactive_study_planner'] =
|
145 |
if st.session_state['responses']['interactive_study_planner']:
|
146 |
display_response("interactive_study_planner", st.session_state['responses']['interactive_study_planner'])
|
147 |
|
148 |
elif selected_tool == "Real-Time Q&A Support":
|
149 |
st.header("Real-Time Q&A Support")
|
150 |
with st.form(key="qa_form"):
|
151 |
-
question_input = st.text_input("
|
152 |
submit_button = st.form_submit_button("Get Answer")
|
153 |
if submit_button:
|
154 |
answer = real_time_qa_support(question_input)
|
@@ -159,7 +236,7 @@ elif selected_tool == "Real-Time Q&A Support":
|
|
159 |
elif selected_tool == "Mental Health Check-In":
|
160 |
st.header("Mental Health Check-In")
|
161 |
with st.form(key="mental_health_form"):
|
162 |
-
feelings_input = st.text_area("How are you feeling?", placeholder="e.g., Stressed about exams")
|
163 |
submit_button = st.form_submit_button("Get Advice")
|
164 |
if submit_button:
|
165 |
advice = mental_health_check_in(feelings_input)
|
@@ -167,12 +244,12 @@ elif selected_tool == "Mental Health Check-In":
|
|
167 |
if st.session_state['responses']['mental_health_check_in']:
|
168 |
display_response("mental_health_check_in", st.session_state['responses']['mental_health_check_in'])
|
169 |
|
170 |
-
#
|
171 |
st.markdown("""
|
172 |
<div class="footer">
|
173 |
-
<p>
|
174 |
-
<a href="https://
|
175 |
-
<a href="https://
|
176 |
-
<a href="
|
177 |
</div>
|
178 |
""", unsafe_allow_html=True)
|
|
|
1 |
+
import os
|
2 |
import streamlit as st
|
3 |
+
from groq import Groq
|
4 |
+
|
5 |
+
# Set the Groq API key
|
6 |
+
os.environ["GROQ_API_KEY"] = "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"
|
7 |
+
|
8 |
+
# Initialize Groq client
|
9 |
+
client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
|
10 |
+
|
11 |
+
# Define the LLaMA model to be used
|
12 |
+
MODEL_NAME = "llama3-8b-8192"
|
13 |
+
|
14 |
+
# Function to call Groq API
|
15 |
+
def call_groq_api(prompt):
|
16 |
+
try:
|
17 |
+
chat_completion = client.chat.completions.create(
|
18 |
+
messages=[{"role": "user", "content": prompt}],
|
19 |
+
model=MODEL_NAME
|
20 |
+
)
|
21 |
+
return chat_completion.choices[0].message.content
|
22 |
+
except Exception as e:
|
23 |
+
return f"Error: {str(e)}"
|
24 |
+
|
25 |
+
# Define functions for each tool
|
26 |
+
def personalized_learning_assistant(topic):
|
27 |
+
examples = [
|
28 |
+
"Explain quantum mechanics with a real-world example.",
|
29 |
+
"Describe general relativity and its significance.",
|
30 |
+
"Provide a simple explanation of machine learning and its applications."
|
31 |
+
]
|
32 |
+
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."
|
33 |
+
return call_groq_api(prompt)
|
34 |
+
|
35 |
+
def ai_coding_mentor(code_snippet):
|
36 |
+
examples = [
|
37 |
+
"Review this code snippet for optimization opportunities:\n\nCode: 'for i in range(10): print(i)'\nSuggestion: Use list comprehension for more efficient code.",
|
38 |
+
"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."
|
39 |
+
]
|
40 |
+
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."
|
41 |
+
return call_groq_api(prompt)
|
42 |
+
|
43 |
+
def smart_document_summarizer(document_text):
|
44 |
+
examples = [
|
45 |
+
"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.'",
|
46 |
+
"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.'"
|
47 |
+
]
|
48 |
+
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."
|
49 |
+
return call_groq_api(prompt)
|
50 |
+
|
51 |
+
def interactive_study_planner(exam_schedule):
|
52 |
+
examples = [
|
53 |
+
"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.'",
|
54 |
+
"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.'"
|
55 |
+
]
|
56 |
+
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."
|
57 |
+
return call_groq_api(prompt)
|
58 |
+
|
59 |
+
def real_time_qa_support(question):
|
60 |
+
examples = [
|
61 |
+
"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.'",
|
62 |
+
"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.'"
|
63 |
+
]
|
64 |
+
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."
|
65 |
+
return call_groq_api(prompt)
|
66 |
+
|
67 |
+
def mental_health_check_in(feelings):
|
68 |
+
examples = [
|
69 |
+
"Offer advice for managing exam stress:\n\nFeeling: 'Stressed about upcoming exams'\nAdvice: 'Develop a study schedule, take regular breaks, and practice relaxation techniques.'",
|
70 |
+
"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.'"
|
71 |
+
]
|
72 |
+
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."
|
73 |
+
return call_groq_api(prompt)
|
74 |
+
|
75 |
+
# Initialize session state if not already set
|
76 |
+
if 'responses' not in st.session_state:
|
77 |
+
st.session_state['responses'] = {
|
78 |
+
"personalized_learning_assistant": "",
|
79 |
+
"ai_coding_mentor": "",
|
80 |
+
"smart_document_summarizer": "",
|
81 |
+
"interactive_study_planner": "",
|
82 |
+
"real_time_qa_support": "",
|
83 |
+
"mental_health_check_in": ""
|
84 |
+
}
|
85 |
|
86 |
# Define Streamlit app
|
87 |
st.set_page_config(page_title="EduNexus", page_icon=":book:", layout="wide")
|
|
|
145 |
|
146 |
# Define function to clear all inputs
|
147 |
def clear_chat():
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
st.session_state['responses'] = {
|
149 |
"personalized_learning_assistant": "",
|
150 |
"ai_coding_mentor": "",
|
|
|
202 |
|
203 |
elif selected_tool == "Smart Document Summarizer":
|
204 |
st.header("Smart Document Summarizer")
|
205 |
+
with st.form(key="summarizer_form"):
|
206 |
+
document_input = st.text_area("Paste your document text here", placeholder="e.g., The rise of electric vehicles...")
|
207 |
submit_button = st.form_submit_button("Summarize Document")
|
208 |
if submit_button:
|
209 |
summary = smart_document_summarizer(document_input)
|
|
|
213 |
|
214 |
elif selected_tool == "Interactive Study Planner":
|
215 |
st.header("Interactive Study Planner")
|
216 |
+
with st.form(key="planner_form"):
|
217 |
+
schedule_input = st.text_area("Enter your exam schedule", placeholder="e.g., 3 exams in one week")
|
218 |
+
submit_button = st.form_submit_button("Create Study Plan")
|
219 |
if submit_button:
|
220 |
+
study_plan = interactive_study_planner(schedule_input)
|
221 |
+
st.session_state['responses']['interactive_study_planner'] = study_plan
|
222 |
if st.session_state['responses']['interactive_study_planner']:
|
223 |
display_response("interactive_study_planner", st.session_state['responses']['interactive_study_planner'])
|
224 |
|
225 |
elif selected_tool == "Real-Time Q&A Support":
|
226 |
st.header("Real-Time Q&A Support")
|
227 |
with st.form(key="qa_form"):
|
228 |
+
question_input = st.text_input("Ask a question", placeholder="e.g., What is Newton's third law?")
|
229 |
submit_button = st.form_submit_button("Get Answer")
|
230 |
if submit_button:
|
231 |
answer = real_time_qa_support(question_input)
|
|
|
236 |
elif selected_tool == "Mental Health Check-In":
|
237 |
st.header("Mental Health Check-In")
|
238 |
with st.form(key="mental_health_form"):
|
239 |
+
feelings_input = st.text_area("How are you feeling today?", placeholder="e.g., Stressed about exams")
|
240 |
submit_button = st.form_submit_button("Get Advice")
|
241 |
if submit_button:
|
242 |
advice = mental_health_check_in(feelings_input)
|
|
|
244 |
if st.session_state['responses']['mental_health_check_in']:
|
245 |
display_response("mental_health_check_in", st.session_state['responses']['mental_health_check_in'])
|
246 |
|
247 |
+
# Add footer with contact information
|
248 |
st.markdown("""
|
249 |
<div class="footer">
|
250 |
+
<p>Powered by EduNexus</p>
|
251 |
+
<a href="https://twitter.com/yourhandle" target="_blank"><i class="fab fa-twitter"></i></a>
|
252 |
+
<a href="https://linkedin.com/in/yourprofile" target="_blank"><i class="fab fa-linkedin"></i></a>
|
253 |
+
<a href="mailto:your.email@example.com"><i class="fas fa-envelope"></i></a>
|
254 |
</div>
|
255 |
""", unsafe_allow_html=True)
|