Spaces:
Sleeping
Sleeping
ahmad-fakhar
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -3,10 +3,10 @@ import streamlit as st
|
|
3 |
from groq import Groq
|
4 |
|
5 |
# Set the Groq API key
|
6 |
-
|
7 |
|
8 |
-
# Initialize
|
9 |
-
client = Groq(api_key=
|
10 |
|
11 |
# Define the LLaMA model to be used
|
12 |
MODEL_NAME = "llama3-8b-8192"
|
@@ -72,47 +72,90 @@ def mental_health_check_in(feelings):
|
|
72 |
prompt = f"Here are some examples of mental health advice:\n\n{examples}\n\nProvide advice based on the following feeling:\n{feelings}. Offer practical suggestions for improving well-being."
|
73 |
return call_groq_api(prompt)
|
74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
# Define Streamlit app
|
76 |
st.set_page_config(page_title="EduNexus", page_icon=":book:", layout="wide")
|
77 |
|
78 |
# Add custom styling using Streamlit
|
79 |
st.markdown("""
|
80 |
<style>
|
81 |
-
.css-1o7k8tt {
|
82 |
-
background-color: #
|
83 |
color: #ffffff;
|
84 |
}
|
85 |
.css-1o7k8tt h1 {
|
86 |
-
color: #
|
87 |
}
|
88 |
.stButton {
|
89 |
-
background-color: #
|
90 |
color: #000000;
|
91 |
border-radius: 12px;
|
92 |
padding: 10px 20px;
|
93 |
font-size: 16px;
|
94 |
}
|
95 |
.stButton:hover {
|
96 |
-
background-color: #
|
97 |
}
|
98 |
.stTextInput, .stTextArea {
|
99 |
-
border: 1px solid #
|
100 |
border-radius: 8px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
}
|
102 |
</style>
|
103 |
""", unsafe_allow_html=True)
|
104 |
|
105 |
# Define function to clear all inputs
|
106 |
def clear_chat():
|
107 |
-
st.session_state['
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
|
|
|
|
113 |
|
114 |
# Add Clear Chat button
|
115 |
-
if st.button("Clear All", key="clear_button"):
|
116 |
clear_chat()
|
117 |
|
118 |
# Navigation sidebar
|
@@ -124,6 +167,17 @@ selected_tool = st.sidebar.radio(
|
|
124 |
)
|
125 |
|
126 |
# Display tool based on selection
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
if selected_tool == "Personalized Learning Assistant":
|
128 |
st.header("Personalized Learning Assistant")
|
129 |
with st.form(key="learning_form"):
|
@@ -131,7 +185,9 @@ if selected_tool == "Personalized Learning Assistant":
|
|
131 |
submit_button = st.form_submit_button("Get Explanation")
|
132 |
if submit_button:
|
133 |
explanation = personalized_learning_assistant(topic_input)
|
134 |
-
st.
|
|
|
|
|
135 |
|
136 |
elif selected_tool == "AI Coding Mentor":
|
137 |
st.header("AI Coding Mentor")
|
@@ -140,40 +196,60 @@ elif selected_tool == "AI Coding Mentor":
|
|
140 |
submit_button = st.form_submit_button("Review Code")
|
141 |
if submit_button:
|
142 |
review = ai_coding_mentor(code_input)
|
143 |
-
st.
|
|
|
|
|
144 |
|
145 |
elif selected_tool == "Smart Document Summarizer":
|
146 |
st.header("Smart Document Summarizer")
|
147 |
with st.form(key="summarizer_form"):
|
148 |
-
document_input = st.text_area("
|
149 |
submit_button = st.form_submit_button("Summarize Document")
|
150 |
if submit_button:
|
151 |
summary = smart_document_summarizer(document_input)
|
152 |
-
st.
|
|
|
|
|
153 |
|
154 |
elif selected_tool == "Interactive Study Planner":
|
155 |
st.header("Interactive Study Planner")
|
156 |
with st.form(key="planner_form"):
|
157 |
-
schedule_input = st.text_area("Enter your exam schedule", placeholder="e.g., 3 exams in
|
158 |
-
submit_button = st.form_submit_button("
|
159 |
if submit_button:
|
160 |
study_plan = interactive_study_planner(schedule_input)
|
161 |
-
st.
|
|
|
|
|
162 |
|
163 |
elif selected_tool == "Real-Time Q&A Support":
|
164 |
st.header("Real-Time Q&A Support")
|
165 |
with st.form(key="qa_form"):
|
166 |
-
question_input = st.text_input("Ask
|
167 |
submit_button = st.form_submit_button("Get Answer")
|
168 |
if submit_button:
|
169 |
answer = real_time_qa_support(question_input)
|
170 |
-
st.
|
|
|
|
|
171 |
|
172 |
elif selected_tool == "Mental Health Check-In":
|
173 |
st.header("Mental Health Check-In")
|
174 |
-
with st.form(key="
|
175 |
-
feelings_input = st.text_area("How are you feeling?", placeholder="e.g., Stressed about exams")
|
176 |
-
submit_button = st.form_submit_button("
|
177 |
if submit_button:
|
178 |
advice = mental_health_check_in(feelings_input)
|
179 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
from groq import Groq
|
4 |
|
5 |
# Set the Groq API key
|
6 |
+
os.environ["GROQ_API_KEY"] = "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"
|
7 |
|
8 |
+
# Initialize Groq client
|
9 |
+
client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
|
10 |
|
11 |
# Define the LLaMA model to be used
|
12 |
MODEL_NAME = "llama3-8b-8192"
|
|
|
72 |
prompt = f"Here are some examples of mental health advice:\n\n{examples}\n\nProvide advice based on the following feeling:\n{feelings}. Offer practical suggestions for improving well-being."
|
73 |
return call_groq_api(prompt)
|
74 |
|
75 |
+
# Initialize session state if not already set
|
76 |
+
if 'responses' not in st.session_state:
|
77 |
+
st.session_state['responses'] = {
|
78 |
+
"personalized_learning_assistant": "",
|
79 |
+
"ai_coding_mentor": "",
|
80 |
+
"smart_document_summarizer": "",
|
81 |
+
"interactive_study_planner": "",
|
82 |
+
"real_time_qa_support": "",
|
83 |
+
"mental_health_check_in": ""
|
84 |
+
}
|
85 |
+
|
86 |
# Define Streamlit app
|
87 |
st.set_page_config(page_title="EduNexus", page_icon=":book:", layout="wide")
|
88 |
|
89 |
# Add custom styling using Streamlit
|
90 |
st.markdown("""
|
91 |
<style>
|
92 |
+
.css-1o7k8tt {
|
93 |
+
background-color: #1e1e2f;
|
94 |
color: #ffffff;
|
95 |
}
|
96 |
.css-1o7k8tt h1 {
|
97 |
+
color: #ff9a8b;
|
98 |
}
|
99 |
.stButton {
|
100 |
+
background-color: #ff9a8b;
|
101 |
color: #000000;
|
102 |
border-radius: 12px;
|
103 |
padding: 10px 20px;
|
104 |
font-size: 16px;
|
105 |
}
|
106 |
.stButton:hover {
|
107 |
+
background-color: #ff6f6f;
|
108 |
}
|
109 |
.stTextInput, .stTextArea {
|
110 |
+
border: 1px solid #ff9a8b;
|
111 |
border-radius: 8px;
|
112 |
+
background-color: #282c34;
|
113 |
+
color: #ffffff;
|
114 |
+
}
|
115 |
+
.stTextInput::placeholder, .stTextArea::placeholder {
|
116 |
+
color: #b0b0b0;
|
117 |
+
}
|
118 |
+
.stSidebar {
|
119 |
+
background-color: #2e2e3e;
|
120 |
+
}
|
121 |
+
.stSidebar .stMarkdown {
|
122 |
+
color: #ffffff;
|
123 |
+
}
|
124 |
+
.footer {
|
125 |
+
background-color: #1e1e2f;
|
126 |
+
padding: 10px;
|
127 |
+
text-align: center;
|
128 |
+
color: #ffffff;
|
129 |
+
border-top: 1px solid #ff9a8b;
|
130 |
+
}
|
131 |
+
.footer a {
|
132 |
+
color: #ff9a8b;
|
133 |
+
margin: 0 10px;
|
134 |
+
text-decoration: none;
|
135 |
+
font-size: 18px;
|
136 |
+
}
|
137 |
+
.footer a:hover {
|
138 |
+
color: #ffffff;
|
139 |
+
}
|
140 |
+
.footer i {
|
141 |
+
font-size: 20px;
|
142 |
}
|
143 |
</style>
|
144 |
""", unsafe_allow_html=True)
|
145 |
|
146 |
# Define function to clear all inputs
|
147 |
def clear_chat():
|
148 |
+
st.session_state['responses'] = {
|
149 |
+
"personalized_learning_assistant": "",
|
150 |
+
"ai_coding_mentor": "",
|
151 |
+
"smart_document_summarizer": "",
|
152 |
+
"interactive_study_planner": "",
|
153 |
+
"real_time_qa_support": "",
|
154 |
+
"mental_health_check_in": ""
|
155 |
+
}
|
156 |
|
157 |
# Add Clear Chat button
|
158 |
+
if st.sidebar.button("Clear All", key="clear_button"):
|
159 |
clear_chat()
|
160 |
|
161 |
# Navigation sidebar
|
|
|
167 |
)
|
168 |
|
169 |
# Display tool based on selection
|
170 |
+
st.title("EduNexus :book:")
|
171 |
+
|
172 |
+
# Common function to display response and download button
|
173 |
+
def display_response(response_key, response):
|
174 |
+
st.write(response)
|
175 |
+
st.download_button(
|
176 |
+
"Download Response",
|
177 |
+
response,
|
178 |
+
file_name=f"{response_key}.txt"
|
179 |
+
)
|
180 |
+
|
181 |
if selected_tool == "Personalized Learning Assistant":
|
182 |
st.header("Personalized Learning Assistant")
|
183 |
with st.form(key="learning_form"):
|
|
|
185 |
submit_button = st.form_submit_button("Get Explanation")
|
186 |
if submit_button:
|
187 |
explanation = personalized_learning_assistant(topic_input)
|
188 |
+
st.session_state['responses']['personalized_learning_assistant'] = explanation
|
189 |
+
if st.session_state['responses']['personalized_learning_assistant']:
|
190 |
+
display_response("personalized_learning_assistant", st.session_state['responses']['personalized_learning_assistant'])
|
191 |
|
192 |
elif selected_tool == "AI Coding Mentor":
|
193 |
st.header("AI Coding Mentor")
|
|
|
196 |
submit_button = st.form_submit_button("Review Code")
|
197 |
if submit_button:
|
198 |
review = ai_coding_mentor(code_input)
|
199 |
+
st.session_state['responses']['ai_coding_mentor'] = review
|
200 |
+
if st.session_state['responses']['ai_coding_mentor']:
|
201 |
+
display_response("ai_coding_mentor", st.session_state['responses']['ai_coding_mentor'])
|
202 |
|
203 |
elif selected_tool == "Smart Document Summarizer":
|
204 |
st.header("Smart Document Summarizer")
|
205 |
with st.form(key="summarizer_form"):
|
206 |
+
document_input = st.text_area("Paste your document text here", placeholder="e.g., The rise of electric vehicles...")
|
207 |
submit_button = st.form_submit_button("Summarize Document")
|
208 |
if submit_button:
|
209 |
summary = smart_document_summarizer(document_input)
|
210 |
+
st.session_state['responses']['smart_document_summarizer'] = summary
|
211 |
+
if st.session_state['responses']['smart_document_summarizer']:
|
212 |
+
display_response("smart_document_summarizer", st.session_state['responses']['smart_document_summarizer'])
|
213 |
|
214 |
elif selected_tool == "Interactive Study Planner":
|
215 |
st.header("Interactive Study Planner")
|
216 |
with st.form(key="planner_form"):
|
217 |
+
schedule_input = st.text_area("Enter your exam schedule", placeholder="e.g., 3 exams in one week")
|
218 |
+
submit_button = st.form_submit_button("Create Study Plan")
|
219 |
if submit_button:
|
220 |
study_plan = interactive_study_planner(schedule_input)
|
221 |
+
st.session_state['responses']['interactive_study_planner'] = study_plan
|
222 |
+
if st.session_state['responses']['interactive_study_planner']:
|
223 |
+
display_response("interactive_study_planner", st.session_state['responses']['interactive_study_planner'])
|
224 |
|
225 |
elif selected_tool == "Real-Time Q&A Support":
|
226 |
st.header("Real-Time Q&A Support")
|
227 |
with st.form(key="qa_form"):
|
228 |
+
question_input = st.text_input("Ask a question", placeholder="e.g., What is Newton's third law?")
|
229 |
submit_button = st.form_submit_button("Get Answer")
|
230 |
if submit_button:
|
231 |
answer = real_time_qa_support(question_input)
|
232 |
+
st.session_state['responses']['real_time_qa_support'] = answer
|
233 |
+
if st.session_state['responses']['real_time_qa_support']:
|
234 |
+
display_response("real_time_qa_support", st.session_state['responses']['real_time_qa_support'])
|
235 |
|
236 |
elif selected_tool == "Mental Health Check-In":
|
237 |
st.header("Mental Health Check-In")
|
238 |
+
with st.form(key="mental_health_form"):
|
239 |
+
feelings_input = st.text_area("How are you feeling today?", placeholder="e.g., Stressed about exams")
|
240 |
+
submit_button = st.form_submit_button("Get Advice")
|
241 |
if submit_button:
|
242 |
advice = mental_health_check_in(feelings_input)
|
243 |
+
st.session_state['responses']['mental_health_check_in'] = advice
|
244 |
+
if st.session_state['responses']['mental_health_check_in']:
|
245 |
+
display_response("mental_health_check_in", st.session_state['responses']['mental_health_check_in'])
|
246 |
+
|
247 |
+
# Add footer with contact information
|
248 |
+
st.markdown("""
|
249 |
+
<div class="footer">
|
250 |
+
<p>Powered by EduNexus</p>
|
251 |
+
<a href="https://twitter.com/yourhandle" target="_blank"><i class="fab fa-twitter"></i></a>
|
252 |
+
<a href="https://linkedin.com/in/yourprofile" target="_blank"><i class="fab fa-linkedin"></i></a>
|
253 |
+
<a href="mailto:[email protected]"><i class="fas fa-envelope"></i></a>
|
254 |
+
</div>
|
255 |
+
""", unsafe_allow_html=True)
|