Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -25,29 +25,64 @@ def call_groq_api(prompt):
|
|
25 |
except Exception as e:
|
26 |
return f"Error: {str(e)}"
|
27 |
|
28 |
-
# Define functions for each tool
|
29 |
def personalized_learning_assistant(topic):
|
30 |
-
prompt = f"
|
|
|
|
|
|
|
|
|
|
|
31 |
return call_groq_api(prompt)
|
32 |
|
33 |
def ai_coding_mentor(code_snippet):
|
34 |
-
prompt = f"
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
return call_groq_api(prompt)
|
36 |
|
37 |
def smart_document_summarizer(document_text):
|
38 |
-
prompt = f"
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
return call_groq_api(prompt)
|
40 |
|
41 |
def interactive_study_planner(exam_schedule):
|
42 |
-
prompt = f"
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
return call_groq_api(prompt)
|
44 |
|
45 |
def real_time_qa_support(question):
|
46 |
-
prompt = f"
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
return call_groq_api(prompt)
|
48 |
|
49 |
def mental_health_check_in(feelings):
|
50 |
-
prompt = f"
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
return call_groq_api(prompt)
|
52 |
|
53 |
# Initialize session state if not already set
|
@@ -63,11 +98,8 @@ if 'responses' not in st.session_state:
|
|
63 |
|
64 |
# Function to clear session state values
|
65 |
def clear_session_state():
|
66 |
-
for key in st.session_state.keys():
|
67 |
-
|
68 |
-
st.session_state[key] = ""
|
69 |
-
if key in ['personalized_learning_assistant', 'ai_coding_mentor', 'smart_document_summarizer', 'interactive_study_planner', 'real_time_qa_support', 'mental_health_check_in']:
|
70 |
-
st.session_state[key] = ""
|
71 |
|
72 |
# Add custom styling using Streamlit
|
73 |
st.markdown("""
|
@@ -153,97 +185,63 @@ tasks = [
|
|
153 |
"π€ AI Coding Mentor",
|
154 |
"π Smart Document Summarizer",
|
155 |
"ποΈ Interactive Study Planner",
|
156 |
-
"
|
157 |
-
"
|
158 |
]
|
159 |
-
|
160 |
selected_task = st.sidebar.radio("Select a task", tasks)
|
161 |
|
162 |
-
# Main
|
163 |
-
|
164 |
-
# Display form
|
165 |
-
with st.form(key=f"{task_key}_form"):
|
166 |
-
st.markdown(f"<div style='color: #000000; font-weight: bold; background-color: #ffffff; padding: 5px;'>{input_label}</div>", unsafe_allow_html=True)
|
167 |
-
user_input = st.text_area("", key=task_key)
|
168 |
-
submit_button = st.form_submit_button("Get Response")
|
169 |
-
|
170 |
-
if submit_button:
|
171 |
-
response = prompt_function(user_input)
|
172 |
-
st.session_state['responses'][response_key] = response
|
173 |
-
st.write(response)
|
174 |
-
|
175 |
-
# Clear button outside of form to avoid modification errors
|
176 |
-
if st.button("Clear"):
|
177 |
-
clear_session_state()
|
178 |
|
179 |
if selected_task == "π Personalized Learning Assistant":
|
180 |
-
st.
|
181 |
-
|
182 |
-
"personalized_learning_assistant"
|
183 |
-
personalized_learning_assistant
|
184 |
-
"Enter the topic you want to learn about",
|
185 |
-
"personalized_learning_assistant"
|
186 |
-
)
|
187 |
|
188 |
elif selected_task == "π€ AI Coding Mentor":
|
189 |
-
st.
|
190 |
-
|
191 |
-
"ai_coding_mentor"
|
192 |
-
ai_coding_mentor
|
193 |
-
"Paste your code snippet here",
|
194 |
-
"ai_coding_mentor"
|
195 |
-
)
|
196 |
|
197 |
elif selected_task == "π Smart Document Summarizer":
|
198 |
-
st.
|
199 |
-
|
200 |
-
"smart_document_summarizer"
|
201 |
-
smart_document_summarizer
|
202 |
-
"Paste your document text here",
|
203 |
-
"smart_document_summarizer"
|
204 |
-
)
|
205 |
|
206 |
elif selected_task == "ποΈ Interactive Study Planner":
|
207 |
-
st.
|
208 |
-
|
209 |
-
"interactive_study_planner"
|
210 |
-
interactive_study_planner
|
211 |
-
|
212 |
-
|
213 |
-
)
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
"
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
feelings = st.text_area("", key="mental_health_check_in")
|
229 |
-
submit_button = st.form_submit_button("Get Advice")
|
230 |
-
|
231 |
-
if submit_button:
|
232 |
-
response = mental_health_check_in(feelings)
|
233 |
-
st.session_state['responses']['mental_health_check_in'] = response
|
234 |
-
st.write(response)
|
235 |
-
|
236 |
-
# Clear button outside of form to avoid modification errors
|
237 |
-
if st.button("Clear"):
|
238 |
clear_session_state()
|
|
|
239 |
|
240 |
# Footer
|
241 |
st.markdown("""
|
242 |
<div class="footer">
|
243 |
-
<a href="https://
|
244 |
-
<a href="https://www.
|
245 |
-
<a href="https://www.
|
246 |
-
<
|
247 |
-
<i>EduNexus 2024</i>
|
248 |
</div>
|
249 |
""", unsafe_allow_html=True)
|
|
|
25 |
except Exception as e:
|
26 |
return f"Error: {str(e)}"
|
27 |
|
28 |
+
# Define functions for each tool with few-shot examples
|
29 |
def personalized_learning_assistant(topic):
|
30 |
+
prompt = f"""
|
31 |
+
Provide a personalized learning plan for the topic: {topic}.
|
32 |
+
Example 1: For 'Machine Learning': 'Create a plan with courses on supervised learning, unsupervised learning, and neural networks. Include practical exercises and projects.'
|
33 |
+
Example 2: For 'Data Science': 'Suggest a plan with a focus on data analysis, visualization, and statistical modeling. Recommend tools like Python, R, and SQL.'
|
34 |
+
Example 3: For 'Web Development': 'Outline a plan that covers front-end and back-end development, including HTML, CSS, JavaScript, and server-side technologies.'
|
35 |
+
Example 4: For '{topic}':"""
|
36 |
return call_groq_api(prompt)
|
37 |
|
38 |
def ai_coding_mentor(code_snippet):
|
39 |
+
prompt = f"""
|
40 |
+
Review this AI code snippet and provide suggestions or improvements:
|
41 |
+
{code_snippet}
|
42 |
+
Example 1: 'In the provided code, consider using a different activation function to improve performance.'
|
43 |
+
Example 2: 'The code can be optimized by reducing redundant calculations and enhancing readability.'
|
44 |
+
Example 3: 'Add comments to explain complex sections of the code for better understanding.'
|
45 |
+
Example 4: 'For the provided snippet, suggest improvements or fixes:'''
|
46 |
return call_groq_api(prompt)
|
47 |
|
48 |
def smart_document_summarizer(document_text):
|
49 |
+
prompt = f"""
|
50 |
+
Summarize the following document:
|
51 |
+
{document_text}
|
52 |
+
Example 1: 'The document discusses the impact of climate change on global agriculture, emphasizing the need for sustainable practices.'
|
53 |
+
Example 2: 'It provides an overview of recent advancements in AI technology and its applications in various fields.'
|
54 |
+
Example 3: 'The text outlines the historical development of renewable energy sources and their future potential.'
|
55 |
+
Example 4: 'Summarize this document:'''
|
56 |
return call_groq_api(prompt)
|
57 |
|
58 |
def interactive_study_planner(exam_schedule):
|
59 |
+
prompt = f"""
|
60 |
+
Create an interactive study plan based on this exam schedule:
|
61 |
+
{exam_schedule}
|
62 |
+
Example 1: 'For an exam schedule with subjects A, B, and C, create a plan that allocates study time for each subject and includes breaks.'
|
63 |
+
Example 2: 'Plan should include daily study goals and revision sessions leading up to the exams.'
|
64 |
+
Example 3: 'Suggest a study plan that balances subject preparation with relaxation to avoid burnout.'
|
65 |
+
Example 4: 'Based on the provided schedule, create a study plan:'''
|
66 |
return call_groq_api(prompt)
|
67 |
|
68 |
def real_time_qa_support(question):
|
69 |
+
prompt = f"""
|
70 |
+
Provide an answer to the following academic question:
|
71 |
+
{question}
|
72 |
+
Example 1: 'Question: What is the capital of France? Answer: Paris.'
|
73 |
+
Example 2: 'Question: Explain the theory of relativity. Answer: The theory of relativity, developed by Albert Einstein, includes two theories: special relativity and general relativity, explaining the relationship between space, time, and gravity.'
|
74 |
+
Example 3: 'Question: What is the process of photosynthesis? Answer: Photosynthesis is the process by which green plants use sunlight to synthesize foods with the help of chlorophyll, water, and carbon dioxide.'
|
75 |
+
Example 4: 'Answer this question:'''
|
76 |
return call_groq_api(prompt)
|
77 |
|
78 |
def mental_health_check_in(feelings):
|
79 |
+
prompt = f"""
|
80 |
+
Provide some advice based on these feelings:
|
81 |
+
{feelings}
|
82 |
+
Example 1: 'Feeling stressed? Try practicing mindfulness and deep breathing exercises to calm your mind.'
|
83 |
+
Example 2: 'If you're feeling anxious, consider talking to a trusted friend or counselor for support.'
|
84 |
+
Example 3: 'Feeling overwhelmed? Break your tasks into smaller steps and focus on completing them one at a time.'
|
85 |
+
Example 4: 'Based on these feelings, provide advice:'''
|
86 |
return call_groq_api(prompt)
|
87 |
|
88 |
# Initialize session state if not already set
|
|
|
98 |
|
99 |
# Function to clear session state values
|
100 |
def clear_session_state():
|
101 |
+
for key in st.session_state['responses'].keys():
|
102 |
+
st.session_state['responses'][key] = ""
|
|
|
|
|
|
|
103 |
|
104 |
# Add custom styling using Streamlit
|
105 |
st.markdown("""
|
|
|
185 |
"π€ AI Coding Mentor",
|
186 |
"π Smart Document Summarizer",
|
187 |
"ποΈ Interactive Study Planner",
|
188 |
+
"β Real-Time Q&A Support",
|
189 |
+
"π¬ Mental Health Check-In"
|
190 |
]
|
|
|
191 |
selected_task = st.sidebar.radio("Select a task", tasks)
|
192 |
|
193 |
+
# Main content area based on selected task
|
194 |
+
st.header(f"Selected Task: {selected_task}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
195 |
|
196 |
if selected_task == "π Personalized Learning Assistant":
|
197 |
+
topic = st.text_input("Enter the topic for the learning plan:")
|
198 |
+
if st.button("Generate Learning Plan"):
|
199 |
+
st.session_state['responses']["personalized_learning_assistant"] = personalized_learning_assistant(topic)
|
200 |
+
st.write(st.session_state['responses']["personalized_learning_assistant"])
|
|
|
|
|
|
|
201 |
|
202 |
elif selected_task == "π€ AI Coding Mentor":
|
203 |
+
code_snippet = st.text_area("Paste your AI code snippet here:")
|
204 |
+
if st.button("Review Code"):
|
205 |
+
st.session_state['responses']["ai_coding_mentor"] = ai_coding_mentor(code_snippet)
|
206 |
+
st.write(st.session_state['responses']["ai_coding_mentor"])
|
|
|
|
|
|
|
207 |
|
208 |
elif selected_task == "π Smart Document Summarizer":
|
209 |
+
document_text = st.text_area("Paste your document text here:")
|
210 |
+
if st.button("Summarize Document"):
|
211 |
+
st.session_state['responses']["smart_document_summarizer"] = smart_document_summarizer(document_text)
|
212 |
+
st.write(st.session_state['responses']["smart_document_summarizer"])
|
|
|
|
|
|
|
213 |
|
214 |
elif selected_task == "ποΈ Interactive Study Planner":
|
215 |
+
exam_schedule = st.text_area("Enter your exam schedule details:")
|
216 |
+
if st.button("Generate Study Plan"):
|
217 |
+
st.session_state['responses']["interactive_study_planner"] = interactive_study_planner(exam_schedule)
|
218 |
+
st.write(st.session_state['responses']["interactive_study_planner"])
|
219 |
+
|
220 |
+
elif selected_task == "β Real-Time Q&A Support":
|
221 |
+
question = st.text_input("Ask your academic question:")
|
222 |
+
if st.button("Get Answer"):
|
223 |
+
st.session_state['responses']["real_time_qa_support"] = real_time_qa_support(question)
|
224 |
+
st.write(st.session_state['responses']["real_time_qa_support"])
|
225 |
+
|
226 |
+
elif selected_task == "π¬ Mental Health Check-In":
|
227 |
+
feelings = st.text_area("Describe your current feelings:")
|
228 |
+
if st.button("Get Advice"):
|
229 |
+
st.session_state['responses']["mental_health_check_in"] = mental_health_check_in(feelings)
|
230 |
+
st.write(st.session_state['responses']["mental_health_check_in"])
|
231 |
+
|
232 |
+
# Layout for buttons side-by-side
|
233 |
+
col1, col2 = st.columns([3, 1])
|
234 |
+
with col1:
|
235 |
+
if st.button("Clear Session"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
236 |
clear_session_state()
|
237 |
+
st.write("Session cleared.")
|
238 |
|
239 |
# Footer
|
240 |
st.markdown("""
|
241 |
<div class="footer">
|
242 |
+
<a href="https://www.yourwebsite.com">Home</a>
|
243 |
+
<a href="https://www.yourwebsite.com/about">About</a>
|
244 |
+
<a href="https://www.yourwebsite.com/contact">Contact</a>
|
245 |
+
<a href="https://www.yourwebsite.com/privacy">Privacy</a>
|
|
|
246 |
</div>
|
247 |
""", unsafe_allow_html=True)
|