Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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"] = "
|
| 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
|
| 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
|
| 102 |
-
|
|
|
|
| 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 |
-
"
|
| 189 |
-
"
|
| 190 |
]
|
|
|
|
| 191 |
selected_task = st.sidebar.radio("Select a task", tasks)
|
| 192 |
|
| 193 |
-
# Main
|
| 194 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
|
| 196 |
if selected_task == "π Personalized Learning Assistant":
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
|
| 202 |
elif selected_task == "π€ AI Coding Mentor":
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
|
| 208 |
elif selected_task == "π Smart Document Summarizer":
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
|
| 214 |
elif selected_task == "ποΈ Interactive Study Planner":
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
|
| 239 |
-
#
|
| 240 |
st.markdown("""
|
| 241 |
<div class="footer">
|
| 242 |
-
<a href="https://
|
| 243 |
-
<a href="https://
|
| 244 |
-
<a href="
|
| 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)
|