Dannyar608 commited on
Commit
a6c95c9
·
verified ·
1 Parent(s): 1c96b69

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +78 -85
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
- "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)]
@@ -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
- 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'),
@@ -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("## 🎓 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()
 
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()