ibrahim313 commited on
Commit
6cedbe6
Β·
verified Β·
1 Parent(s): 8a40a74

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +86 -88
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"Provide a personalized learning plan for the topic: {topic}"
 
 
 
 
 
31
  return call_groq_api(prompt)
32
 
33
  def ai_coding_mentor(code_snippet):
34
- prompt = f"Review this AI code snippet and provide suggestions or improvements:\n\n{code_snippet}"
 
 
 
 
 
 
35
  return call_groq_api(prompt)
36
 
37
  def smart_document_summarizer(document_text):
38
- prompt = f"Summarize the following document:\n\n{document_text}"
 
 
 
 
 
 
39
  return call_groq_api(prompt)
40
 
41
  def interactive_study_planner(exam_schedule):
42
- prompt = f"Create an interactive study plan based on this exam schedule:\n\n{exam_schedule}"
 
 
 
 
 
 
43
  return call_groq_api(prompt)
44
 
45
  def real_time_qa_support(question):
46
- prompt = f"Provide an answer to the following academic question:\n\n{question}"
 
 
 
 
 
 
47
  return call_groq_api(prompt)
48
 
49
  def mental_health_check_in(feelings):
50
- prompt = f"Provide some advice based on these feelings:\n\n{feelings}"
 
 
 
 
 
 
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
- if key.startswith('responses'):
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
- "πŸ’¬ Real-Time Q&A Support",
157
- "🧠 Mental Health Check-In"
158
  ]
159
-
160
  selected_task = st.sidebar.radio("Select a task", tasks)
161
 
162
- # Main layout based on selected task
163
- def handle_task_form(task_key, prompt_function, input_label, response_key):
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.header("Personalized Learning Assistant")
181
- handle_task_form(
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.header("AI Coding Mentor")
190
- handle_task_form(
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.header("Smart Document Summarizer")
199
- handle_task_form(
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.header("Interactive Study Planner")
208
- handle_task_form(
209
- "interactive_study_planner",
210
- interactive_study_planner,
211
- "Enter your exam schedule here",
212
- "interactive_study_planner"
213
- )
214
-
215
- elif selected_task == "πŸ’¬ Real-Time Q&A Support":
216
- st.header("Real-Time Q&A Support")
217
- handle_task_form(
218
- "real_time_qa_support",
219
- real_time_qa_support,
220
- "Ask your academic question here",
221
- "real_time_qa_support"
222
- )
223
-
224
- elif selected_task == "🧠 Mental Health Check-In":
225
- st.header("Mental Health Check-In")
226
- with st.form(key="mental_health_check_in_form"):
227
- st.markdown("<div style='color: #000000; font-weight: bold; background-color: #ffffff; padding: 5px;'>Share how you are feeling today</div>", unsafe_allow_html=True)
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://github.com/muhammadibrahim313">GitHub</a> |
244
- <a href="https://www.kaggle.com/itshappy">Kaggle</a> |
245
- <a href="https://www.linkedin.com/in/muhammad-ibrahim313">LinkedIn</a>
246
- <br>
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)