ibrahim313 commited on
Commit
caefa3d
Β·
verified Β·
1 Parent(s): 67f281c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -84
app.py CHANGED
@@ -6,7 +6,7 @@ from groq import Groq
6
  st.set_page_config(page_title="EduNexus", page_icon=":book:", layout="wide")
7
 
8
  # Set the Groq API key
9
- os.environ["GROQ_API_KEY"] = "your_groq_api_key_here" # Replace with your actual API key
10
 
11
  # Initialize Groq client
12
  client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
@@ -25,7 +25,7 @@ def call_groq_api(prompt):
25
  except Exception as e:
26
  return f"Error: {str(e)}"
27
 
28
- # Define functions for each tool with examples
29
  def personalized_learning_assistant(topic):
30
  prompt = f"""
31
  Provide a personalized learning plan for the topic: {topic}.
@@ -99,6 +99,8 @@ if 'responses' not in st.session_state:
99
  # Function to clear session state values
100
  def clear_session_state():
101
  for key in st.session_state.keys():
 
 
102
  if key in ['personalized_learning_assistant', 'ai_coding_mentor', 'smart_document_summarizer', 'interactive_study_planner', 'real_time_qa_support', 'mental_health_check_in']:
103
  st.session_state[key] = ""
104
 
@@ -109,6 +111,10 @@ st.markdown("""
109
  background-color: #000000; /* Royal Black */
110
  color: #ffffff; /* White */
111
  }
 
 
 
 
112
  .stButton {
113
  background-color: #ffffff; /* White */
114
  color: #000000; /* Royal Black */
@@ -132,6 +138,16 @@ st.markdown("""
132
  color: #000000; /* Royal Black */
133
  font-weight: bold;
134
  }
 
 
 
 
 
 
 
 
 
 
135
  .footer {
136
  background-color: #000000; /* Royal Black */
137
  padding: 15px;
@@ -154,6 +170,11 @@ st.markdown("""
154
  .footer i {
155
  font-size: 22px;
156
  }
 
 
 
 
 
157
  </style>
158
  """, unsafe_allow_html=True)
159
 
@@ -166,98 +187,62 @@ tasks = [
166
  "πŸ“š Personalized Learning Assistant",
167
  "πŸ€– AI Coding Mentor",
168
  "πŸ“„ Smart Document Summarizer",
169
- "πŸ—“οΈ Interactive Study Planner",
170
- "πŸ’¬ Real-Time Q&A Support",
171
- "🧠 Mental Health Check-In"
172
  ]
173
-
174
  selected_task = st.sidebar.radio("Select a task", tasks)
175
 
176
- # Main layout based on selected task
177
- def handle_task_form(task_key, prompt_function, input_label, response_key, example_prompt):
178
- # Display form
179
- with st.form(key=f"{task_key}_form"):
180
- st.markdown(f"<div style='color: #000000; font-weight: bold; background-color: #ffffff; padding: 5px;'>{input_label}</div>", unsafe_allow_html=True)
181
- user_input = st.text_area("", key=task_key)
182
- submit_button = st.form_submit_button("Get Response")
183
-
184
- if submit_button:
185
- response = prompt_function(user_input)
186
- st.session_state['responses'][response_key] = response
187
- st.write(response)
188
-
189
- # Display example prompt
190
- st.markdown(f"**Example Prompt:** {example_prompt}")
191
-
192
- # Clear button outside of form to avoid modification errors
193
- if st.button("Clear"):
194
- clear_session_state()
195
 
196
  if selected_task == "πŸ“š Personalized Learning Assistant":
197
- st.header("Personalized Learning Assistant")
198
- handle_task_form(
199
- "personalized_learning_assistant",
200
- personalized_learning_assistant,
201
- "Enter the topic you want to learn about",
202
- "personalized_learning_assistant",
203
- "e.g., 'Create a study plan for learning Machine Learning with Python'"
204
- )
205
 
206
  elif selected_task == "πŸ€– AI Coding Mentor":
207
- st.header("AI Coding Mentor")
208
- handle_task_form(
209
- "ai_coding_mentor",
210
- ai_coding_mentor,
211
- "Paste your AI code snippet here",
212
- "ai_coding_mentor",
213
- "e.g., 'Suggest improvements for this AI code snippet: ...'"
214
- )
215
 
216
  elif selected_task == "πŸ“„ Smart Document Summarizer":
217
- st.header("Smart Document Summarizer")
218
- handle_task_form(
219
- "smart_document_summarizer",
220
- smart_document_summarizer,
221
- "Paste the document text here",
222
- "smart_document_summarizer",
223
- "e.g., 'Summarize this document: ...'"
224
- )
225
-
226
- elif selected_task == "πŸ—“οΈ Interactive Study Planner":
227
- st.header("Interactive Study Planner")
228
- handle_task_form(
229
- "interactive_study_planner",
230
- interactive_study_planner,
231
- "Enter your exam schedule here",
232
- "interactive_study_planner",
233
- "e.g., 'Create a study plan for these exams: ...'"
234
- )
235
-
236
- elif selected_task == "πŸ’¬ Real-Time Q&A Support":
237
- st.header("Real-Time Q&A Support")
238
- handle_task_form(
239
- "real_time_qa_support",
240
- real_time_qa_support,
241
- "Ask your academic question here",
242
- "real_time_qa_support",
243
- "e.g., 'Answer this question: ...'"
244
- )
245
-
246
- elif selected_task == "🧠 Mental Health Check-In":
247
- st.header("Mental Health Check-In")
248
- handle_task_form(
249
- "mental_health_check_in",
250
- mental_health_check_in,
251
- "Share your feelings or concerns",
252
- "mental_health_check_in",
253
- "e.g., 'Feeling stressed? Here's some advice: ...'"
254
- )
255
-
256
- # Display footer
257
  st.markdown("""
258
  <div class="footer">
259
- <a href="https://twitter.com/yourprofile" target="_blank"><i class="fab fa-twitter"></i></a>
260
- <a href="https://github.com/yourprofile" target="_blank"><i class="fab fa-github"></i></a>
261
- <a href="mailto:your.email@example.com"><i class="fas fa-envelope"></i></a>
 
262
  </div>
263
  """, unsafe_allow_html=True)
 
 
 
 
 
 
6
  st.set_page_config(page_title="EduNexus", page_icon=":book:", layout="wide")
7
 
8
  # Set the Groq API key
9
+ os.environ["GROQ_API_KEY"] = "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" # Replace with your actual API key
10
 
11
  # Initialize Groq client
12
  client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
 
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}.
 
99
  # Function to clear session state values
100
  def clear_session_state():
101
  for key in st.session_state.keys():
102
+ if key.startswith('responses'):
103
+ st.session_state[key] = ""
104
  if key in ['personalized_learning_assistant', 'ai_coding_mentor', 'smart_document_summarizer', 'interactive_study_planner', 'real_time_qa_support', 'mental_health_check_in']:
105
  st.session_state[key] = ""
106
 
 
111
  background-color: #000000; /* Royal Black */
112
  color: #ffffff; /* White */
113
  }
114
+ .css-1o7k8tt {
115
+ background-color: #000000; /* Royal Black */
116
+ color: #ffffff; /* White */
117
+ }
118
  .stButton {
119
  background-color: #ffffff; /* White */
120
  color: #000000; /* Royal Black */
 
138
  color: #000000; /* Royal Black */
139
  font-weight: bold;
140
  }
141
+ .stMarkdown, .stTextInput, .stTextArea {
142
+ border-radius: 12px;
143
+ }
144
+ .stSidebar {
145
+ background-color: #000000; /* Royal Black */
146
+ color: #ffffff; /* White */
147
+ }
148
+ .stSidebar .stMarkdown {
149
+ color: #ffffff; /* White */
150
+ }
151
  .footer {
152
  background-color: #000000; /* Royal Black */
153
  padding: 15px;
 
170
  .footer i {
171
  font-size: 22px;
172
  }
173
+ .css-1n8h7zm .stTextArea::placeholder,
174
+ .css-1n8h7zm .stTextInput::placeholder {
175
+ color: #000000; /* Royal Black */
176
+ font-weight: bold;
177
+ }
178
  </style>
179
  """, unsafe_allow_html=True)
180
 
 
187
  "πŸ“š Personalized Learning Assistant",
188
  "πŸ€– AI Coding Mentor",
189
  "πŸ“„ Smart Document Summarizer",
190
+ "πŸ—“ Interactive Study Planner",
191
+ "❓ Real-Time Q&A Support",
192
+ "πŸ’¬ Mental Health Check-In"
193
  ]
 
194
  selected_task = st.sidebar.radio("Select a task", tasks)
195
 
196
+ # Main content area based on selected task
197
+ st.header(f"Selected Task: {selected_task}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
 
199
  if selected_task == "πŸ“š Personalized Learning Assistant":
200
+ topic = st.text_input("Enter the topic for the learning plan:")
201
+ if st.button("Generate Learning Plan"):
202
+ st.session_state['responses']["personalized_learning_assistant"] = personalized_learning_assistant(topic)
203
+ st.write(st.session_state['responses']["personalized_learning_assistant"])
 
 
 
 
204
 
205
  elif selected_task == "πŸ€– AI Coding Mentor":
206
+ code_snippet = st.text_area("Paste your AI code snippet here:")
207
+ if st.button("Review Code"):
208
+ st.session_state['responses']["ai_coding_mentor"] = ai_coding_mentor(code_snippet)
209
+ st.write(st.session_state['responses']["ai_coding_mentor"])
 
 
 
 
210
 
211
  elif selected_task == "πŸ“„ Smart Document Summarizer":
212
+ document_text = st.text_area("Paste your document text here:")
213
+ if st.button("Summarize Document"):
214
+ st.session_state['responses']["smart_document_summarizer"] = smart_document_summarizer(document_text)
215
+ st.write(st.session_state['responses']["smart_document_summarizer"])
216
+
217
+ elif selected_task == "πŸ—“ Interactive Study Planner":
218
+ exam_schedule = st.text_area("Enter your exam schedule details:")
219
+ if st.button("Generate Study Plan"):
220
+ st.session_state['responses']["interactive_study_planner"] = interactive_study_planner(exam_schedule)
221
+ st.write(st.session_state['responses']["interactive_study_planner"])
222
+
223
+ elif selected_task == "❓ Real-Time Q&A Support":
224
+ question = st.text_input("Ask your academic question:")
225
+ if st.button("Get Answer"):
226
+ st.session_state['responses']["real_time_qa_support"] = real_time_qa_support(question)
227
+ st.write(st.session_state['responses']["real_time_qa_support"])
228
+
229
+ elif selected_task == "πŸ’¬ Mental Health Check-In":
230
+ feelings = st.text_area("Describe your current feelings:")
231
+ if st.button("Get Advice"):
232
+ st.session_state['responses']["mental_health_check_in"] = mental_health_check_in(feelings)
233
+ st.write(st.session_state['responses']["mental_health_check_in"])
234
+
235
+ # Footer
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
236
  st.markdown("""
237
  <div class="footer">
238
+ <a href="https://www.yourwebsite.com">Home</a>
239
+ <a href="https://www.yourwebsite.com/about">About</a>
240
+ <a href="https://www.yourwebsite.com/contact">Contact</a>
241
+ <a href="https://www.yourwebsite.com/privacy">Privacy</a>
242
  </div>
243
  """, unsafe_allow_html=True)
244
+
245
+ # Clear session state button
246
+ if st.button("Clear Session"):
247
+ clear_session_state()
248
+ st.write("Session cleared.")