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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +83 -67
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"] = "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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,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 few-shot examples
29
  def personalized_learning_assistant(topic):
30
  prompt = f"""
31
  Provide a personalized learning plan for the topic: {topic}.
@@ -98,8 +98,9 @@ if 'responses' not in st.session_state:
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("""
@@ -108,10 +109,6 @@ st.markdown("""
108
  background-color: #000000; /* Royal Black */
109
  color: #ffffff; /* White */
110
  }
111
- .css-1o7k8tt {
112
- background-color: #000000; /* Royal Black */
113
- color: #ffffff; /* White */
114
- }
115
  .stButton {
116
  background-color: #ffffff; /* White */
117
  color: #000000; /* Royal Black */
@@ -135,16 +132,6 @@ st.markdown("""
135
  color: #000000; /* Royal Black */
136
  font-weight: bold;
137
  }
138
- .stMarkdown, .stTextInput, .stTextArea {
139
- border-radius: 12px;
140
- }
141
- .stSidebar {
142
- background-color: #000000; /* Royal Black */
143
- color: #ffffff; /* White */
144
- }
145
- .stSidebar .stMarkdown {
146
- color: #ffffff; /* White */
147
- }
148
  .footer {
149
  background-color: #000000; /* Royal Black */
150
  padding: 15px;
@@ -167,11 +154,6 @@ st.markdown("""
167
  .footer i {
168
  font-size: 22px;
169
  }
170
- .css-1n8h7zm .stTextArea::placeholder,
171
- .css-1n8h7zm .stTextInput::placeholder {
172
- color: #000000; /* Royal Black */
173
- font-weight: bold;
174
- }
175
  </style>
176
  """, unsafe_allow_html=True)
177
 
@@ -185,63 +167,97 @@ tasks = [
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)
 
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
  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}.
 
98
 
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
 
105
  # Add custom styling using Streamlit
106
  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
  color: #000000; /* Royal Black */
133
  font-weight: bold;
134
  }
 
 
 
 
 
 
 
 
 
 
135
  .footer {
136
  background-color: #000000; /* Royal Black */
137
  padding: 15px;
 
154
  .footer i {
155
  font-size: 22px;
156
  }
 
 
 
 
 
157
  </style>
158
  """, unsafe_allow_html=True)
159
 
 
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)