Spaces:
Running
Running
File size: 7,336 Bytes
515bd6c |
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 188 189 190 191 192 193 194 195 196 197 198 199 200 |
import gradio as gr
import pandas as pd
import torch
from transformers import BertTokenizer, BertModel
import numpy as np
from sklearn.preprocessing import StandardScaler
import logging
# Setup logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
class EasyLearningPlatform:
def __init__(self):
self.device = 'cuda' if torch.cuda.is_available() else 'cpu'
logger.info(f"Using device: {self.device}")
self.initialize_models()
def initialize_models(self):
"""Initialize BERT model for processing"""
try:
self.tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
self.model = BertModel.from_pretrained('bert-base-uncased').to(self.device)
except Exception as e:
logger.error(f"Error initializing models: {str(e)}")
raise
def process_learning_request(
self,
name: str,
age: int,
education_level: str,
interests: str,
learning_goal: str,
preferred_learning_style: str,
available_hours_per_week: int
):
"""Process user input and generate learning recommendations"""
try:
# Create user profile
profile = {
'name': name,
'age': age,
'education': education_level,
'interests': interests,
'goal': learning_goal,
'learning_style': preferred_learning_style,
'hours_available': available_hours_per_week
}
# Generate recommendations based on profile
recommendations = self.generate_recommendations(profile)
# Create response
return {
"status": "Success",
"personal_learning_path": recommendations['learning_path'],
"estimated_completion_time": recommendations['completion_time'],
"recommended_resources": recommendations['resources'],
"next_steps": recommendations['next_steps']
}
except Exception as e:
logger.error(f"Error processing request: {str(e)}")
return {
"status": "Error",
"message": "There was an error processing your request. Please try again."
}
def generate_recommendations(self, profile):
"""Generate personalized learning recommendations"""
# Simplified recommendation logic
learning_styles = {
'visual': ['video tutorials', 'infographics', 'diagrams'],
'auditory': ['podcasts', 'audio books', 'lectures'],
'reading/writing': ['textbooks', 'articles', 'written guides'],
'kinesthetic': ['practical exercises', 'hands-on projects', 'interactive tutorials']
}
# Get recommended resources based on learning style
preferred_resources = learning_styles.get(
profile['learning_style'].lower(),
learning_styles['visual'] # default to visual if style not found
)
# Calculate estimated completion time (simplified)
weekly_hours = min(max(profile['hours_available'], 1), 168) # Limit between 1 and 168 hours
estimated_weeks = 12 # Default to 12-week program
return {
'learning_path': [
f"Week 1-2: Introduction to {profile['goal']}",
f"Week 3-4: Fundamental Concepts",
f"Week 5-8: Core Skills Development",
f"Week 9-12: Advanced Topics and Projects"
],
'completion_time': f"{estimated_weeks} weeks at {weekly_hours} hours per week",
'resources': preferred_resources,
'next_steps': [
"1. Review your personalized learning path",
"2. Schedule your study time",
"3. Start with the recommended resources",
"4. Track your progress weekly"
]
}
def create_interface(self):
"""Create the Gradio interface"""
# Define the interface
iface = gr.Interface(
fn=self.process_learning_request,
inputs=[
gr.Textbox(label="Name"),
gr.Number(label="Age", minimum=1, maximum=120),
gr.Dropdown(
choices=[
"High School",
"Bachelor's Degree",
"Master's Degree",
"PhD",
"Other"
],
label="Education Level"
),
gr.Textbox(
label="Interests",
placeholder="e.g., programming, data science, web development"
),
gr.Textbox(
label="Learning Goal",
placeholder="What do you want to learn?"
),
gr.Dropdown(
choices=[
"Visual",
"Auditory",
"Reading/Writing",
"Kinesthetic"
],
label="Preferred Learning Style",
info="How do you learn best?"
),
gr.Slider(
minimum=1,
maximum=40,
value=10,
label="Available Hours per Week",
info="How many hours can you dedicate to learning each week?"
)
],
outputs=gr.JSON(label="Your Personalized Learning Plan"),
title="AI Learning Path Generator",
description="""
Welcome to your personalized learning journey!
Fill in your information below to get a customized learning path:
1. Enter your basic information
2. Specify your learning goals
3. Choose your preferred learning style
4. Set your weekly time commitment
Contact-: AJoshi 91-8847374914 email [email protected]
Click submit to generate your personalized learning plan!
""",
examples=[
[
"John Doe",
25,
"Bachelor's Degree",
"Machine Learning, Python",
"Learn Data Science",
"Visual",
10
],
[
"Jane Smith",
30,
"Master's Degree",
"Web Development, JavaScript",
"Full Stack Development",
"Kinesthetic",
15
]
]
)
return iface
def main():
# Create and launch the platform
platform = EasyLearningPlatform()
interface = platform.create_interface()
interface.launch(share=True)
if __name__ == "__main__":
"""
# Run these commands in Google Colab first:
!pip install gradio transformers torch numpy pandas scikit-learn
"""
main() |