Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -4,9 +4,7 @@ import PyPDF2
|
|
4 |
import json
|
5 |
import re
|
6 |
|
7 |
-
#
|
8 |
-
# 1. Parse uploaded transcript
|
9 |
-
# -------------------------
|
10 |
def parse_transcript(file):
|
11 |
if file.name.endswith('.csv'):
|
12 |
df = pd.read_csv(file.name)
|
@@ -22,6 +20,7 @@ def parse_transcript(file):
|
|
22 |
raise ValueError("Unsupported file format. Use .csv, .xlsx, or .pdf")
|
23 |
return df
|
24 |
|
|
|
25 |
def extract_transcript_info(df):
|
26 |
transcript_text = df['Transcript_Text'].iloc[0] if 'Transcript_Text' in df.columns else ''
|
27 |
info = {}
|
@@ -36,83 +35,80 @@ def extract_transcript_info(df):
|
|
36 |
info['Courses'] = list(set([c[0].strip() for c in courses]))
|
37 |
return info
|
38 |
|
39 |
-
#
|
40 |
-
# 2. Learning Style Quiz
|
41 |
-
# -------------------------
|
42 |
learning_style_questions = [
|
43 |
-
"
|
44 |
-
"
|
45 |
-
"
|
46 |
-
"
|
47 |
-
"
|
48 |
-
"
|
49 |
-
"
|
50 |
-
"
|
51 |
-
"
|
|
|
52 |
]
|
53 |
|
54 |
learning_style_answers = [
|
55 |
-
["
|
56 |
-
["
|
57 |
-
["
|
58 |
-
["
|
59 |
-
["
|
60 |
-
["
|
61 |
-
["
|
62 |
-
["
|
63 |
-
["
|
|
|
64 |
]
|
65 |
|
66 |
-
|
67 |
-
0:
|
68 |
-
1:
|
69 |
-
2:
|
70 |
}
|
71 |
|
|
|
72 |
def learning_style_quiz(*answers):
|
73 |
-
|
74 |
for ans in answers:
|
75 |
-
|
76 |
-
best = max(
|
77 |
return best.capitalize()
|
78 |
|
79 |
-
#
|
80 |
-
# 3. PanoramaEd "Get to Know You" Categories
|
81 |
-
# -------------------------
|
82 |
get_to_know_categories = {
|
83 |
"All About Me": [
|
84 |
-
"What’s your favorite way to spend a day off?",
|
85 |
-
"If you could only eat one food for the rest of your life, what would it be?",
|
86 |
-
"Do you have any pets? If so, what are their names?",
|
87 |
-
"If you could travel anywhere in the world, where would you go?",
|
88 |
-
"What’s your favorite holiday or tradition?"
|
89 |
],
|
90 |
"Hopes and Dreams": [
|
91 |
-
"What do you want to be when you grow up?",
|
92 |
-
"What’s something you hope to achieve this year?",
|
93 |
-
"If you could change the world in one way, what would you do?",
|
94 |
-
"What are you most proud of?",
|
95 |
-
"What’s a big dream you have for your future?"
|
96 |
],
|
97 |
"School Life": [
|
98 |
-
"What’s your favorite subject in school?",
|
99 |
-
"What’s something that makes learning easier for you?",
|
100 |
-
"Do you prefer working alone or in groups?",
|
101 |
-
"What helps you feel confident in class?",
|
102 |
-
"What’s something you’re good at in school?"
|
103 |
],
|
104 |
"Relationships": [
|
105 |
-
"Who do you look up to and why?",
|
106 |
-
"Who is someone that makes you feel safe and supported?",
|
107 |
-
"Do you have a best friend? What do you like to do together?",
|
108 |
-
"What’s one thing you wish people knew about you?",
|
109 |
-
"What’s something kind you’ve done for someone else?"
|
110 |
]
|
111 |
}
|
112 |
|
113 |
-
#
|
114 |
-
# 4. Save Profile Logic
|
115 |
-
# -------------------------
|
116 |
def save_profile(file, *inputs):
|
117 |
quiz_answers = inputs[:len(learning_style_questions)]
|
118 |
about_me = inputs[len(learning_style_questions)]
|
@@ -124,12 +120,11 @@ def save_profile(file, *inputs):
|
|
124 |
transcript_info = extract_transcript_info(df)
|
125 |
learning_type = learning_style_quiz(*quiz_answers)
|
126 |
|
127 |
-
if not blog_opt_in:
|
128 |
-
|
129 |
-
if blog_text.strip() == "":
|
130 |
-
blog_text = "[User chose to skip this section]"
|
131 |
|
132 |
-
|
|
|
133 |
|
134 |
profile = {
|
135 |
"transcript": df.to_dict(orient='records'),
|
@@ -145,42 +140,40 @@ def save_profile(file, *inputs):
|
|
145 |
|
146 |
return f"✅ Profile saved! Your learning style is: {learning_type}"
|
147 |
|
148 |
-
#
|
149 |
-
# 5. Gradio UI
|
150 |
-
# -------------------------
|
151 |
with gr.Blocks() as demo:
|
152 |
-
gr.Markdown("## 🎓
|
153 |
|
154 |
-
|
|
|
155 |
|
156 |
-
gr.
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
gr.Radio(
|
161 |
-
choices=
|
162 |
label=f"{i+1}. {question}"
|
163 |
-
)
|
164 |
-
)
|
165 |
|
166 |
-
gr.
|
167 |
-
|
168 |
-
|
169 |
-
|
|
|
170 |
|
171 |
category_inputs = []
|
172 |
for category, questions in get_to_know_categories.items():
|
173 |
gr.Markdown(f"### 📘 {category}")
|
174 |
-
for
|
175 |
-
category_inputs.append(gr.Textbox(label=
|
176 |
|
177 |
submit = gr.Button("📥 Save My Profile")
|
178 |
-
output = gr.Textbox(label="
|
179 |
|
180 |
submit.click(fn=save_profile,
|
181 |
-
inputs=[file, *
|
182 |
outputs=[output])
|
183 |
|
184 |
-
# Run the app
|
185 |
if __name__ == '__main__':
|
186 |
-
demo.launch()
|
|
|
4 |
import json
|
5 |
import re
|
6 |
|
7 |
+
# Parse uploaded transcript file
|
|
|
|
|
8 |
def parse_transcript(file):
|
9 |
if file.name.endswith('.csv'):
|
10 |
df = pd.read_csv(file.name)
|
|
|
20 |
raise ValueError("Unsupported file format. Use .csv, .xlsx, or .pdf")
|
21 |
return df
|
22 |
|
23 |
+
# Extract student info
|
24 |
def extract_transcript_info(df):
|
25 |
transcript_text = df['Transcript_Text'].iloc[0] if 'Transcript_Text' in df.columns else ''
|
26 |
info = {}
|
|
|
35 |
info['Courses'] = list(set([c[0].strip() for c in courses]))
|
36 |
return info
|
37 |
|
38 |
+
# Learning style questions - from educationplanner.org
|
|
|
|
|
39 |
learning_style_questions = [
|
40 |
+
"When you are learning something new, you prefer to:",
|
41 |
+
"When you are at home, you like to:",
|
42 |
+
"When you spell a word, you remember it by:",
|
43 |
+
"When you read, you:",
|
44 |
+
"When you write, you:",
|
45 |
+
"When you listen to music, you:",
|
46 |
+
"When you work at solving a problem, you:",
|
47 |
+
"When you give someone directions, you:",
|
48 |
+
"When you are concentrating, you:",
|
49 |
+
"When you meet someone new, you remember them by:"
|
50 |
]
|
51 |
|
52 |
learning_style_answers = [
|
53 |
+
["Watch a demonstration", "Listen to instructions", "Read about it"],
|
54 |
+
["Watch TV or play games", "Listen to music or talk", "Read books or write"],
|
55 |
+
["Seeing the word", "Hearing the word", "Writing the word"],
|
56 |
+
["See the characters in your mind", "Hear the words in your mind", "Focus on the meaning of the words"],
|
57 |
+
["Prefer diagrams or charts", "Prefer to discuss ideas", "Prefer to write detailed explanations"],
|
58 |
+
["Enjoy the sound and rhythm", "Remember lyrics easily", "Analyze the meaning"],
|
59 |
+
["Visualize the problem", "Talk it through", "Write out steps"],
|
60 |
+
["Use maps or draw it", "Give verbal directions", "Write down directions"],
|
61 |
+
["Create mental pictures", "Repeat things aloud", "Take notes or read quietly"],
|
62 |
+
["Facial features", "Voice or name", "Spelling or written form"]
|
63 |
]
|
64 |
|
65 |
+
style_count_map = {
|
66 |
+
0: 'visual',
|
67 |
+
1: 'auditory',
|
68 |
+
2: 'reading/writing'
|
69 |
}
|
70 |
|
71 |
+
# Quiz logic to analyze learning style
|
72 |
def learning_style_quiz(*answers):
|
73 |
+
scores = {'visual': 0, 'auditory': 0, 'reading/writing': 0}
|
74 |
for ans in answers:
|
75 |
+
scores[ans] += 1
|
76 |
+
best = max(scores, key=scores.get)
|
77 |
return best.capitalize()
|
78 |
|
79 |
+
# PanoramaEd categories and multiple choice questions
|
|
|
|
|
80 |
get_to_know_categories = {
|
81 |
"All About Me": [
|
82 |
+
("What’s your favorite way to spend a day off?", []),
|
83 |
+
("If you could only eat one food for the rest of your life, what would it be?", []),
|
84 |
+
("Do you have any pets? If so, what are their names?", []),
|
85 |
+
("If you could travel anywhere in the world, where would you go?", []),
|
86 |
+
("What’s your favorite holiday or tradition?", [])
|
87 |
],
|
88 |
"Hopes and Dreams": [
|
89 |
+
("What do you want to be when you grow up?", []),
|
90 |
+
("What’s something you hope to achieve this year?", []),
|
91 |
+
("If you could change the world in one way, what would you do?", []),
|
92 |
+
("What are you most proud of?", []),
|
93 |
+
("What’s a big dream you have for your future?", [])
|
94 |
],
|
95 |
"School Life": [
|
96 |
+
("What’s your favorite subject in school?", []),
|
97 |
+
("What’s something that makes learning easier for you?", []),
|
98 |
+
("Do you prefer working alone or in groups?", []),
|
99 |
+
("What helps you feel confident in class?", []),
|
100 |
+
("What’s something you’re good at in school?", [])
|
101 |
],
|
102 |
"Relationships": [
|
103 |
+
("Who do you look up to and why?", []),
|
104 |
+
("Who is someone that makes you feel safe and supported?", []),
|
105 |
+
("Do you have a best friend? What do you like to do together?", []),
|
106 |
+
("What’s one thing you wish people knew about you?", []),
|
107 |
+
("What’s something kind you’ve done for someone else?", [])
|
108 |
]
|
109 |
}
|
110 |
|
111 |
+
# Save all answers into profile
|
|
|
|
|
112 |
def save_profile(file, *inputs):
|
113 |
quiz_answers = inputs[:len(learning_style_questions)]
|
114 |
about_me = inputs[len(learning_style_questions)]
|
|
|
120 |
transcript_info = extract_transcript_info(df)
|
121 |
learning_type = learning_style_quiz(*quiz_answers)
|
122 |
|
123 |
+
if not blog_opt_in and blog_text.strip() == "":
|
124 |
+
blog_text = "[User chose to skip this section]"
|
|
|
|
|
125 |
|
126 |
+
question_texts = [q for cat in get_to_know_categories.values() for q, _ in cat]
|
127 |
+
responses = dict(zip(question_texts, category_answers))
|
128 |
|
129 |
profile = {
|
130 |
"transcript": df.to_dict(orient='records'),
|
|
|
140 |
|
141 |
return f"✅ Profile saved! Your learning style is: {learning_type}"
|
142 |
|
143 |
+
# Build Gradio UI
|
|
|
|
|
144 |
with gr.Blocks() as demo:
|
145 |
+
gr.Markdown("## 🎓 Personalized AI Student Assistant")
|
146 |
|
147 |
+
with gr.Row():
|
148 |
+
file = gr.File(label="📄 Upload Your Transcript (.csv, .xlsx, .pdf)")
|
149 |
|
150 |
+
with gr.Column():
|
151 |
+
gr.Markdown("### 🧠 Learning Style Discovery")
|
152 |
+
quiz_components = []
|
153 |
+
for i, (question, options) in enumerate(zip(learning_style_questions, learning_style_answers)):
|
154 |
+
quiz_components.append(gr.Radio(
|
155 |
+
choices=options,
|
156 |
label=f"{i+1}. {question}"
|
157 |
+
))
|
|
|
158 |
|
159 |
+
with gr.Column():
|
160 |
+
gr.Markdown("### ❤️ About You")
|
161 |
+
about_me = gr.Textbox(lines=6, label="Answer a few questions: \n1. What’s a fun fact about you? \n2. Favorite music/artist? \n3. Your dream job?")
|
162 |
+
blog_opt_in = gr.Checkbox(label="I want to write a personal blog for better personalization")
|
163 |
+
blog_text = gr.Textbox(lines=5, label="✍️ Optional: Write a mini blog about your life", visible=True)
|
164 |
|
165 |
category_inputs = []
|
166 |
for category, questions in get_to_know_categories.items():
|
167 |
gr.Markdown(f"### 📘 {category}")
|
168 |
+
for q_text, _ in questions:
|
169 |
+
category_inputs.append(gr.Textbox(label=q_text))
|
170 |
|
171 |
submit = gr.Button("📥 Save My Profile")
|
172 |
+
output = gr.Textbox(label="Status")
|
173 |
|
174 |
submit.click(fn=save_profile,
|
175 |
+
inputs=[file, *quiz_components, about_me, blog_opt_in, blog_text, *category_inputs],
|
176 |
outputs=[output])
|
177 |
|
|
|
178 |
if __name__ == '__main__':
|
179 |
+
demo.launch()
|