Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,10 +5,6 @@ import os
|
|
5 |
import re
|
6 |
from PyPDF2 import PdfReader
|
7 |
from collections import defaultdict
|
8 |
-
from openai import OpenAI # pip install openai
|
9 |
-
|
10 |
-
# Initialize OpenAI client (you'll need an API key)
|
11 |
-
client = OpenAI(api_key="your-api-key-here") # Replace with your actual API key
|
12 |
|
13 |
# ========== TRANSCRIPT PARSING FUNCTIONS ==========
|
14 |
def parse_transcript(file):
|
@@ -126,50 +122,77 @@ def save_profile(name, age, interests, transcript, learning_style, favorites, bl
|
|
126 |
return "Profile saved successfully!"
|
127 |
|
128 |
def load_profile():
|
129 |
-
|
130 |
-
if
|
131 |
-
with open(
|
132 |
return json.load(f)
|
133 |
return {}
|
134 |
|
135 |
-
# ==========
|
136 |
def generate_response(message, history, profile_data):
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
169 |
|
170 |
# ========== GRADIO INTERFACE ==========
|
171 |
with gr.Blocks() as app:
|
172 |
-
# Profile tabs
|
173 |
with gr.Tab("Step 1: Upload Transcript"):
|
174 |
transcript_file = gr.File(label="Upload your transcript (PDF)")
|
175 |
transcript_output = gr.Textbox(label="Transcript Output")
|
@@ -220,14 +243,14 @@ with gr.Blocks() as app:
|
|
220 |
)
|
221 |
|
222 |
# AI Teaching Assistant Tab
|
223 |
-
with gr.Tab("🤖
|
224 |
gr.Markdown("## Your Personalized Learning Assistant")
|
225 |
chatbot = gr.ChatInterface(
|
226 |
fn=lambda message, history: generate_response(message, history, load_profile()),
|
227 |
examples=[
|
228 |
"How should I study for my next test?",
|
229 |
-
"
|
230 |
-
"
|
231 |
"How can I improve my grades?"
|
232 |
]
|
233 |
)
|
|
|
5 |
import re
|
6 |
from PyPDF2 import PdfReader
|
7 |
from collections import defaultdict
|
|
|
|
|
|
|
|
|
8 |
|
9 |
# ========== TRANSCRIPT PARSING FUNCTIONS ==========
|
10 |
def parse_transcript(file):
|
|
|
122 |
return "Profile saved successfully!"
|
123 |
|
124 |
def load_profile():
|
125 |
+
files = [f for f in os.listdir("student_profiles") if f.endswith('.json')]
|
126 |
+
if files:
|
127 |
+
with open(os.path.join("student_profiles", files[0]), "r") as f:
|
128 |
return json.load(f)
|
129 |
return {}
|
130 |
|
131 |
+
# ========== RULE-BASED TEACHING ASSISTANT ==========
|
132 |
def generate_response(message, history, profile_data):
|
133 |
+
# Get learning style from profile
|
134 |
+
learning_style = profile_data.get("learning_style", "")
|
135 |
+
|
136 |
+
# Common responses
|
137 |
+
greetings = ["hi", "hello", "hey"]
|
138 |
+
study_help = ["study", "learn", "prepare"]
|
139 |
+
grade_help = ["grade", "gpa", "score"]
|
140 |
+
|
141 |
+
if any(greet in message.lower() for greet in greetings):
|
142 |
+
return f"Hello {profile_data.get('name', 'there')}! How can I help you today?"
|
143 |
+
|
144 |
+
elif any(word in message.lower() for word in study_help):
|
145 |
+
if "Visual" in learning_style:
|
146 |
+
return ("Based on your visual learning style, I recommend:\n"
|
147 |
+
"- Creating mind maps or diagrams\n"
|
148 |
+
"- Using color-coded notes\n"
|
149 |
+
"- Watching educational videos")
|
150 |
+
elif "Auditory" in learning_style:
|
151 |
+
return ("Based on your auditory learning style, I recommend:\n"
|
152 |
+
"- Recording lectures and listening to them\n"
|
153 |
+
"- Participating in study groups\n"
|
154 |
+
"- Explaining concepts out loud")
|
155 |
+
elif "Reading/Writing" in learning_style:
|
156 |
+
return ("Based on your reading/writing learning style, I recommend:\n"
|
157 |
+
"- Writing detailed notes\n"
|
158 |
+
"- Creating summaries in your own words\n"
|
159 |
+
"- Reading textbooks and articles")
|
160 |
+
elif "Kinesthetic" in learning_style:
|
161 |
+
return ("Based on your kinesthetic learning style, I recommend:\n"
|
162 |
+
"- Hands-on practice\n"
|
163 |
+
"- Creating physical models\n"
|
164 |
+
"- Taking frequent movement breaks")
|
165 |
+
else:
|
166 |
+
return ("Here are some general study tips:\n"
|
167 |
+
"- Break study sessions into 25-minute chunks\n"
|
168 |
+
"- Review material regularly\n"
|
169 |
+
"- Teach concepts to someone else")
|
170 |
+
|
171 |
+
elif any(word in message.lower() for word in grade_help):
|
172 |
+
gpa = profile_data.get("transcript", {}).get("gpa", {})
|
173 |
+
return (f"Your GPA information:\n"
|
174 |
+
f"- Unweighted: {gpa.get('unweighted', 'N/A')}\n"
|
175 |
+
f"- Weighted: {gpa.get('weighted', 'N/A')}\n\n"
|
176 |
+
"To improve your grades, try:\n"
|
177 |
+
"- Setting specific goals\n"
|
178 |
+
"- Meeting with teachers\n"
|
179 |
+
"- Developing a study schedule")
|
180 |
+
|
181 |
+
elif "help" in message.lower():
|
182 |
+
return ("I can help with:\n"
|
183 |
+
"- Study tips based on your learning style\n"
|
184 |
+
"- GPA and grade information\n"
|
185 |
+
"- General academic advice\n\n"
|
186 |
+
"Try asking about study strategies or your grades!")
|
187 |
+
|
188 |
+
else:
|
189 |
+
return ("I'm your personalized teaching assistant. "
|
190 |
+
"I can help with study tips, grade information, and academic advice. "
|
191 |
+
"Try asking about how to study for your classes!")
|
192 |
|
193 |
# ========== GRADIO INTERFACE ==========
|
194 |
with gr.Blocks() as app:
|
195 |
+
# Profile tabs
|
196 |
with gr.Tab("Step 1: Upload Transcript"):
|
197 |
transcript_file = gr.File(label="Upload your transcript (PDF)")
|
198 |
transcript_output = gr.Textbox(label="Transcript Output")
|
|
|
243 |
)
|
244 |
|
245 |
# AI Teaching Assistant Tab
|
246 |
+
with gr.Tab("🤖 Teaching Assistant"):
|
247 |
gr.Markdown("## Your Personalized Learning Assistant")
|
248 |
chatbot = gr.ChatInterface(
|
249 |
fn=lambda message, history: generate_response(message, history, load_profile()),
|
250 |
examples=[
|
251 |
"How should I study for my next test?",
|
252 |
+
"What's my GPA information?",
|
253 |
+
"Help me with study strategies",
|
254 |
"How can I improve my grades?"
|
255 |
]
|
256 |
)
|