Spaces:
Runtime error
Runtime error
File size: 7,255 Bytes
1d5a1b0 1c96b69 1d5a1b0 1c96b69 1d5a1b0 1c96b69 1d5a1b0 1c96b69 1d5a1b0 1c96b69 1d5a1b0 1c96b69 1d5a1b0 1c96b69 1d5a1b0 1c96b69 1d5a1b0 1c96b69 1d5a1b0 1c96b69 1d5a1b0 1c96b69 1d5a1b0 1c96b69 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 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 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
import gradio as gr
import pandas as pd
import PyPDF2
import json
import re
# -------------------------
# 1. Parse uploaded transcript
# -------------------------
def parse_transcript(file):
if file.name.endswith('.csv'):
df = pd.read_csv(file.name)
elif file.name.endswith(('.xls', '.xlsx')):
df = pd.read_excel(file.name)
elif file.name.endswith('.pdf'):
reader = PyPDF2.PdfReader(file)
text = ""
for page in reader.pages:
text += page.extract_text() or ""
df = pd.DataFrame({'Transcript_Text': [text]})
else:
raise ValueError("Unsupported file format. Use .csv, .xlsx, or .pdf")
return df
def extract_transcript_info(df):
transcript_text = df['Transcript_Text'].iloc[0] if 'Transcript_Text' in df.columns else ''
info = {}
gpa_match = re.search(r'(GPA|Grade Point Average)[^\d]*(\d+\.\d+)', transcript_text, re.IGNORECASE)
if gpa_match:
info['GPA'] = gpa_match.group(2)
grade_match = re.search(r'Grade:?\s*(\d{1,2})', transcript_text, re.IGNORECASE)
if grade_match:
info['Grade_Level'] = grade_match.group(1)
courses = re.findall(r'(?i)\b([A-Z][a-zA-Z\s&/]+)\s+(\d{1,3})\b', transcript_text)
if courses:
info['Courses'] = list(set([c[0].strip() for c in courses]))
return info
# -------------------------
# 2. Learning Style Quiz
# -------------------------
learning_style_questions = [
"You are about to give directions to a person. You would:",
"You are not sure whether a word should be spelled 'dependent' or 'dependant'. You would:",
"You’re planning a vacation for a group. You want people to appreciate it. You would:",
"You are going to cook something as a special treat. You would:",
"A group of tourists wants to learn about the parks or wildlife. You would:",
"You are not sure how a word is spelled. You would:",
"You prefer a teacher who likes to use:",
"You are trying to remember a phone number. You would:",
"You want to learn a new program, game, or app on your phone. You would:"
]
learning_style_answers = [
["draw a map", "tell them directions", "write down the directions"],
["look it up in a dictionary", "sound it out", "write both forms down"],
["show them the brochures/pictures", "tell them what's planned", "list the itinerary"],
["cook from a recipe", "call a friend", "improvise based on what you know"],
["show maps", "talk about nature", "hand out leaflets with info"],
["look it up visually", "say it aloud", "write it a few times"],
["diagrams/charts", "discussions", "reading material"],
["see it in your head", "say it to yourself", "write it down"],
["watch tutorials", "talk to someone who knows", "read instructions"]
]
style_key_map = {
0: "visual",
1: "auditory",
2: "reading/writing"
}
def learning_style_quiz(*answers):
counts = {'visual': 0, 'auditory': 0, 'reading/writing': 0}
for ans in answers:
counts[ans] += 1
best = max(counts, key=counts.get)
return best.capitalize()
# -------------------------
# 3. PanoramaEd "Get to Know You" Categories
# -------------------------
get_to_know_categories = {
"All About Me": [
"What’s your favorite way to spend a day off?",
"If you could only eat one food for the rest of your life, what would it be?",
"Do you have any pets? If so, what are their names?",
"If you could travel anywhere in the world, where would you go?",
"What’s your favorite holiday or tradition?"
],
"Hopes and Dreams": [
"What do you want to be when you grow up?",
"What’s something you hope to achieve this year?",
"If you could change the world in one way, what would you do?",
"What are you most proud of?",
"What’s a big dream you have for your future?"
],
"School Life": [
"What’s your favorite subject in school?",
"What’s something that makes learning easier for you?",
"Do you prefer working alone or in groups?",
"What helps you feel confident in class?",
"What’s something you’re good at in school?"
],
"Relationships": [
"Who do you look up to and why?",
"Who is someone that makes you feel safe and supported?",
"Do you have a best friend? What do you like to do together?",
"What’s one thing you wish people knew about you?",
"What’s something kind you’ve done for someone else?"
]
}
# -------------------------
# 4. Save Profile Logic
# -------------------------
def save_profile(file, *inputs):
quiz_answers = inputs[:len(learning_style_questions)]
about_me = inputs[len(learning_style_questions)]
blog_opt_in = inputs[len(learning_style_questions)+1]
blog_text = inputs[len(learning_style_questions)+2]
category_answers = inputs[len(learning_style_questions)+3:]
df = parse_transcript(file)
transcript_info = extract_transcript_info(df)
learning_type = learning_style_quiz(*quiz_answers)
if not blog_opt_in:
confirm = gr.Textbox.show(label="Skipping the blog might reduce personalization. Do you really want to skip?")
if blog_text.strip() == "":
blog_text = "[User chose to skip this section]"
responses = dict(zip([q for cat in get_to_know_categories.values() for q in cat], category_answers))
profile = {
"transcript": df.to_dict(orient='records'),
"transcript_info": transcript_info,
"learning_style": learning_type,
"about_me": about_me,
"get_to_know_answers": responses,
"blog": blog_text
}
with open("student_profile.json", "w") as f:
json.dump(profile, f, indent=4)
return f"✅ Profile saved! Your learning style is: {learning_type}"
# -------------------------
# 5. Gradio UI
# -------------------------
with gr.Blocks() as demo:
gr.Markdown("## 🎓 Build Your Personalized Learning Profile")
file = gr.File(label="📤 Upload Your Transcript (.pdf, .csv, .xlsx)")
gr.Markdown("### 🧠 Learning Style Questions")
quiz_inputs = []
for i, question in enumerate(learning_style_questions):
quiz_inputs.append(
gr.Radio(
choices=["visual", "auditory", "reading/writing"],
label=f"{i+1}. {question}"
)
)
gr.Markdown("### ✨ Tell Me About You")
about_me = gr.Textbox(lines=3, label="Tell me a fun fact, favorite music, or dream job!")
blog_opt_in = gr.Checkbox(label="📝 I want to write a short blog")
blog_text = gr.Textbox(lines=5, label="Write a short blog about your life")
category_inputs = []
for category, questions in get_to_know_categories.items():
gr.Markdown(f"### 📘 {category}")
for question in questions:
category_inputs.append(gr.Textbox(label=question))
submit = gr.Button("📥 Save My Profile")
output = gr.Textbox(label="✅ Status")
submit.click(fn=save_profile,
inputs=[file, *quiz_inputs, about_me, blog_opt_in, blog_text, *category_inputs],
outputs=[output])
# Run the app
if __name__ == '__main__':
demo.launch()
|