Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -142,68 +142,6 @@ def load_profile():
|
|
| 142 |
return json.load(f)
|
| 143 |
return {}
|
| 144 |
|
| 145 |
-
# ========== RULE-BASED TEACHING ASSISTANT ==========
|
| 146 |
-
def generate_response(message, history, profile_data):
|
| 147 |
-
# Get learning style from profile
|
| 148 |
-
learning_style = profile_data.get("learning_style", "")
|
| 149 |
-
|
| 150 |
-
# Common responses
|
| 151 |
-
greetings = ["hi", "hello", "hey"]
|
| 152 |
-
study_help = ["study", "learn", "prepare"]
|
| 153 |
-
grade_help = ["grade", "gpa", "score"]
|
| 154 |
-
|
| 155 |
-
if any(greet in message.lower() for greet in greetings):
|
| 156 |
-
return f"Hello {profile_data.get('name', 'there')}! How can I help you today?"
|
| 157 |
-
|
| 158 |
-
elif any(word in message.lower() for word in study_help):
|
| 159 |
-
if "Visual" in learning_style:
|
| 160 |
-
return ("Based on your visual learning style, I recommend:\n"
|
| 161 |
-
"- Creating mind maps or diagrams\n"
|
| 162 |
-
"- Using color-coded notes\n"
|
| 163 |
-
"- Watching educational videos")
|
| 164 |
-
elif "Auditory" in learning_style:
|
| 165 |
-
return ("Based on your auditory learning style, I recommend:\n"
|
| 166 |
-
"- Recording lectures and listening to them\n"
|
| 167 |
-
"- Participating in study groups\n"
|
| 168 |
-
"- Explaining concepts out loud")
|
| 169 |
-
elif "Reading/Writing" in learning_style:
|
| 170 |
-
return ("Based on your reading/writing learning style, I recommend:\n"
|
| 171 |
-
"- Writing detailed notes\n"
|
| 172 |
-
"- Creating summaries in your own words\n"
|
| 173 |
-
"- Reading textbooks and articles")
|
| 174 |
-
elif "Kinesthetic" in learning_style:
|
| 175 |
-
return ("Based on your kinesthetic learning style, I recommend:\n"
|
| 176 |
-
"- Hands-on practice\n"
|
| 177 |
-
"- Creating physical models\n"
|
| 178 |
-
"- Taking frequent movement breaks")
|
| 179 |
-
else:
|
| 180 |
-
return ("Here are some general study tips:\n"
|
| 181 |
-
"- Break study sessions into 25-minute chunks\n"
|
| 182 |
-
"- Review material regularly\n"
|
| 183 |
-
"- Teach concepts to someone else")
|
| 184 |
-
|
| 185 |
-
elif any(word in message.lower() for word in grade_help):
|
| 186 |
-
gpa = profile_data.get("transcript", {}).get("gpa", {})
|
| 187 |
-
return (f"Your GPA information:\n"
|
| 188 |
-
f"- Unweighted: {gpa.get('unweighted', 'N/A')}\n"
|
| 189 |
-
f"- Weighted: {gpa.get('weighted', 'N/A')}\n\n"
|
| 190 |
-
"To improve your grades, try:\n"
|
| 191 |
-
"- Setting specific goals\n"
|
| 192 |
-
"- Meeting with teachers\n"
|
| 193 |
-
"- Developing a study schedule")
|
| 194 |
-
|
| 195 |
-
elif "help" in message.lower():
|
| 196 |
-
return ("I can help with:\n"
|
| 197 |
-
"- Study tips based on your learning style\n"
|
| 198 |
-
"- GPA and grade information\n"
|
| 199 |
-
"- General academic advice\n\n"
|
| 200 |
-
"Try asking about study strategies or your grades!")
|
| 201 |
-
|
| 202 |
-
else:
|
| 203 |
-
return ("I'm your personalized teaching assistant. "
|
| 204 |
-
"I can help with study tips, grade information, and academic advice. "
|
| 205 |
-
"Try asking about how to study for your classes!")
|
| 206 |
-
|
| 207 |
# ========== GRADIO INTERFACE ==========
|
| 208 |
with gr.Blocks() as app:
|
| 209 |
# Profile tabs
|
|
@@ -253,17 +191,4 @@ with gr.Blocks() as app:
|
|
| 253 |
outputs=save_output
|
| 254 |
)
|
| 255 |
|
| 256 |
-
# Teaching Assistant Tab
|
| 257 |
-
with gr.Tab("🤖 Teaching Assistant"):
|
| 258 |
-
gr.Markdown("## Your Personalized Learning Assistant")
|
| 259 |
-
chatbot = gr.ChatInterface(
|
| 260 |
-
fn=lambda message, history: generate_response(message, history, load_profile()),
|
| 261 |
-
examples=[
|
| 262 |
-
"How should I study for my next test?",
|
| 263 |
-
"What's my GPA information?",
|
| 264 |
-
"Help me with study strategies",
|
| 265 |
-
"How can I improve my grades?"
|
| 266 |
-
]
|
| 267 |
-
)
|
| 268 |
-
|
| 269 |
app.launch()
|
|
|
|
| 142 |
return json.load(f)
|
| 143 |
return {}
|
| 144 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
# ========== GRADIO INTERFACE ==========
|
| 146 |
with gr.Blocks() as app:
|
| 147 |
# Profile tabs
|
|
|
|
| 191 |
outputs=save_output
|
| 192 |
)
|
| 193 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
app.launch()
|