Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,9 @@ import PyPDF2
|
|
4 |
import json
|
5 |
import re
|
6 |
|
7 |
-
#
|
|
|
|
|
8 |
def parse_transcript(file):
|
9 |
if file.name.endswith('.csv'):
|
10 |
df = pd.read_csv(file.name)
|
@@ -20,7 +22,6 @@ def parse_transcript(file):
|
|
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,29 +36,107 @@ def extract_transcript_info(df):
|
|
35 |
info['Courses'] = list(set([c[0].strip() for c in courses]))
|
36 |
return info
|
37 |
|
38 |
-
#
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
return best.capitalize()
|
46 |
|
47 |
-
#
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
df = parse_transcript(file)
|
50 |
transcript_info = extract_transcript_info(df)
|
51 |
-
learning_type = learning_style_quiz(
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
-
|
54 |
-
blog_text = "[User chose to skip this section]"
|
55 |
|
56 |
profile = {
|
57 |
"transcript": df.to_dict(orient='records'),
|
58 |
"transcript_info": transcript_info,
|
59 |
"learning_style": learning_type,
|
60 |
"about_me": about_me,
|
|
|
61 |
"blog": blog_text
|
62 |
}
|
63 |
|
@@ -66,32 +145,42 @@ def save_profile(file, q1, q2, q3, about_me, blog_text, blog_opt_in):
|
|
66 |
|
67 |
return f"✅ Profile saved! Your learning style is: {learning_type}"
|
68 |
|
69 |
-
#
|
|
|
|
|
70 |
with gr.Blocks() as demo:
|
71 |
-
gr.Markdown("## 🎓 Personalized
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
|
89 |
submit = gr.Button("📥 Save My Profile")
|
90 |
-
output = gr.Textbox(label="Status")
|
91 |
|
92 |
submit.click(fn=save_profile,
|
93 |
-
inputs=[file,
|
94 |
outputs=[output])
|
95 |
|
|
|
96 |
if __name__ == '__main__':
|
97 |
-
demo.launch()
|
|
|
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 |
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 |
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 |
+
"You are about to give directions to a person. You would:",
|
44 |
+
"You are not sure whether a word should be spelled 'dependent' or 'dependant'. You would:",
|
45 |
+
"You’re planning a vacation for a group. You want people to appreciate it. You would:",
|
46 |
+
"You are going to cook something as a special treat. You would:",
|
47 |
+
"A group of tourists wants to learn about the parks or wildlife. You would:",
|
48 |
+
"You are not sure how a word is spelled. You would:",
|
49 |
+
"You prefer a teacher who likes to use:",
|
50 |
+
"You are trying to remember a phone number. You would:",
|
51 |
+
"You want to learn a new program, game, or app on your phone. You would:"
|
52 |
+
]
|
53 |
+
|
54 |
+
learning_style_answers = [
|
55 |
+
["draw a map", "tell them directions", "write down the directions"],
|
56 |
+
["look it up in a dictionary", "sound it out", "write both forms down"],
|
57 |
+
["show them the brochures/pictures", "tell them what's planned", "list the itinerary"],
|
58 |
+
["cook from a recipe", "call a friend", "improvise based on what you know"],
|
59 |
+
["show maps", "talk about nature", "hand out leaflets with info"],
|
60 |
+
["look it up visually", "say it aloud", "write it a few times"],
|
61 |
+
["diagrams/charts", "discussions", "reading material"],
|
62 |
+
["see it in your head", "say it to yourself", "write it down"],
|
63 |
+
["watch tutorials", "talk to someone who knows", "read instructions"]
|
64 |
+
]
|
65 |
+
|
66 |
+
style_key_map = {
|
67 |
+
0: "visual",
|
68 |
+
1: "auditory",
|
69 |
+
2: "reading/writing"
|
70 |
+
}
|
71 |
+
|
72 |
+
def learning_style_quiz(*answers):
|
73 |
+
counts = {'visual': 0, 'auditory': 0, 'reading/writing': 0}
|
74 |
+
for ans in answers:
|
75 |
+
counts[ans] += 1
|
76 |
+
best = max(counts, key=counts.get)
|
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)]
|
119 |
+
blog_opt_in = inputs[len(learning_style_questions)+1]
|
120 |
+
blog_text = inputs[len(learning_style_questions)+2]
|
121 |
+
category_answers = inputs[len(learning_style_questions)+3:]
|
122 |
+
|
123 |
df = parse_transcript(file)
|
124 |
transcript_info = extract_transcript_info(df)
|
125 |
+
learning_type = learning_style_quiz(*quiz_answers)
|
126 |
+
|
127 |
+
if not blog_opt_in:
|
128 |
+
confirm = gr.Textbox.show(label="Skipping the blog might reduce personalization. Do you really want to skip?")
|
129 |
+
if blog_text.strip() == "":
|
130 |
+
blog_text = "[User chose to skip this section]"
|
131 |
|
132 |
+
responses = dict(zip([q for cat in get_to_know_categories.values() for q in cat], category_answers))
|
|
|
133 |
|
134 |
profile = {
|
135 |
"transcript": df.to_dict(orient='records'),
|
136 |
"transcript_info": transcript_info,
|
137 |
"learning_style": learning_type,
|
138 |
"about_me": about_me,
|
139 |
+
"get_to_know_answers": responses,
|
140 |
"blog": blog_text
|
141 |
}
|
142 |
|
|
|
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("## 🎓 Build Your Personalized Learning Profile")
|
153 |
+
|
154 |
+
file = gr.File(label="📤 Upload Your Transcript (.pdf, .csv, .xlsx)")
|
155 |
+
|
156 |
+
gr.Markdown("### 🧠 Learning Style Questions")
|
157 |
+
quiz_inputs = []
|
158 |
+
for i, question in enumerate(learning_style_questions):
|
159 |
+
quiz_inputs.append(
|
160 |
+
gr.Radio(
|
161 |
+
choices=["visual", "auditory", "reading/writing"],
|
162 |
+
label=f"{i+1}. {question}"
|
163 |
+
)
|
164 |
+
)
|
165 |
+
|
166 |
+
gr.Markdown("### ✨ Tell Me About You")
|
167 |
+
about_me = gr.Textbox(lines=3, label="Tell me a fun fact, favorite music, or dream job!")
|
168 |
+
blog_opt_in = gr.Checkbox(label="📝 I want to write a short blog")
|
169 |
+
blog_text = gr.Textbox(lines=5, label="Write a short blog about your life")
|
170 |
+
|
171 |
+
category_inputs = []
|
172 |
+
for category, questions in get_to_know_categories.items():
|
173 |
+
gr.Markdown(f"### 📘 {category}")
|
174 |
+
for question in questions:
|
175 |
+
category_inputs.append(gr.Textbox(label=question))
|
176 |
|
177 |
submit = gr.Button("📥 Save My Profile")
|
178 |
+
output = gr.Textbox(label="✅ Status")
|
179 |
|
180 |
submit.click(fn=save_profile,
|
181 |
+
inputs=[file, *quiz_inputs, about_me, blog_opt_in, blog_text, *category_inputs],
|
182 |
outputs=[output])
|
183 |
|
184 |
+
# Run the app
|
185 |
if __name__ == '__main__':
|
186 |
+
demo.launch()
|