Anupam251272 commited on
Commit
515bd6c
·
verified ·
1 Parent(s): 1fa61c9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +200 -0
app.py ADDED
@@ -0,0 +1,200 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import torch
4
+ from transformers import BertTokenizer, BertModel
5
+ import numpy as np
6
+ from sklearn.preprocessing import StandardScaler
7
+ import logging
8
+
9
+ # Setup logging
10
+ logging.basicConfig(level=logging.INFO)
11
+ logger = logging.getLogger(__name__)
12
+
13
+ class EasyLearningPlatform:
14
+ def __init__(self):
15
+ self.device = 'cuda' if torch.cuda.is_available() else 'cpu'
16
+ logger.info(f"Using device: {self.device}")
17
+ self.initialize_models()
18
+
19
+ def initialize_models(self):
20
+ """Initialize BERT model for processing"""
21
+ try:
22
+ self.tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
23
+ self.model = BertModel.from_pretrained('bert-base-uncased').to(self.device)
24
+ except Exception as e:
25
+ logger.error(f"Error initializing models: {str(e)}")
26
+ raise
27
+
28
+ def process_learning_request(
29
+ self,
30
+ name: str,
31
+ age: int,
32
+ education_level: str,
33
+ interests: str,
34
+ learning_goal: str,
35
+ preferred_learning_style: str,
36
+ available_hours_per_week: int
37
+ ):
38
+ """Process user input and generate learning recommendations"""
39
+ try:
40
+ # Create user profile
41
+ profile = {
42
+ 'name': name,
43
+ 'age': age,
44
+ 'education': education_level,
45
+ 'interests': interests,
46
+ 'goal': learning_goal,
47
+ 'learning_style': preferred_learning_style,
48
+ 'hours_available': available_hours_per_week
49
+ }
50
+
51
+ # Generate recommendations based on profile
52
+ recommendations = self.generate_recommendations(profile)
53
+
54
+ # Create response
55
+ return {
56
+ "status": "Success",
57
+ "personal_learning_path": recommendations['learning_path'],
58
+ "estimated_completion_time": recommendations['completion_time'],
59
+ "recommended_resources": recommendations['resources'],
60
+ "next_steps": recommendations['next_steps']
61
+ }
62
+
63
+ except Exception as e:
64
+ logger.error(f"Error processing request: {str(e)}")
65
+ return {
66
+ "status": "Error",
67
+ "message": "There was an error processing your request. Please try again."
68
+ }
69
+
70
+ def generate_recommendations(self, profile):
71
+ """Generate personalized learning recommendations"""
72
+ # Simplified recommendation logic
73
+ learning_styles = {
74
+ 'visual': ['video tutorials', 'infographics', 'diagrams'],
75
+ 'auditory': ['podcasts', 'audio books', 'lectures'],
76
+ 'reading/writing': ['textbooks', 'articles', 'written guides'],
77
+ 'kinesthetic': ['practical exercises', 'hands-on projects', 'interactive tutorials']
78
+ }
79
+
80
+ # Get recommended resources based on learning style
81
+ preferred_resources = learning_styles.get(
82
+ profile['learning_style'].lower(),
83
+ learning_styles['visual'] # default to visual if style not found
84
+ )
85
+
86
+ # Calculate estimated completion time (simplified)
87
+ weekly_hours = min(max(profile['hours_available'], 1), 168) # Limit between 1 and 168 hours
88
+ estimated_weeks = 12 # Default to 12-week program
89
+
90
+ return {
91
+ 'learning_path': [
92
+ f"Week 1-2: Introduction to {profile['goal']}",
93
+ f"Week 3-4: Fundamental Concepts",
94
+ f"Week 5-8: Core Skills Development",
95
+ f"Week 9-12: Advanced Topics and Projects"
96
+ ],
97
+ 'completion_time': f"{estimated_weeks} weeks at {weekly_hours} hours per week",
98
+ 'resources': preferred_resources,
99
+ 'next_steps': [
100
+ "1. Review your personalized learning path",
101
+ "2. Schedule your study time",
102
+ "3. Start with the recommended resources",
103
+ "4. Track your progress weekly"
104
+ ]
105
+ }
106
+
107
+ def create_interface(self):
108
+ """Create the Gradio interface"""
109
+
110
+ # Define the interface
111
+ iface = gr.Interface(
112
+ fn=self.process_learning_request,
113
+ inputs=[
114
+ gr.Textbox(label="Name"),
115
+ gr.Number(label="Age", minimum=1, maximum=120),
116
+ gr.Dropdown(
117
+ choices=[
118
+ "High School",
119
+ "Bachelor's Degree",
120
+ "Master's Degree",
121
+ "PhD",
122
+ "Other"
123
+ ],
124
+ label="Education Level"
125
+ ),
126
+ gr.Textbox(
127
+ label="Interests",
128
+ placeholder="e.g., programming, data science, web development"
129
+ ),
130
+ gr.Textbox(
131
+ label="Learning Goal",
132
+ placeholder="What do you want to learn?"
133
+ ),
134
+ gr.Dropdown(
135
+ choices=[
136
+ "Visual",
137
+ "Auditory",
138
+ "Reading/Writing",
139
+ "Kinesthetic"
140
+ ],
141
+ label="Preferred Learning Style",
142
+ info="How do you learn best?"
143
+ ),
144
+ gr.Slider(
145
+ minimum=1,
146
+ maximum=40,
147
+ value=10,
148
+ label="Available Hours per Week",
149
+ info="How many hours can you dedicate to learning each week?"
150
+ )
151
+ ],
152
+ outputs=gr.JSON(label="Your Personalized Learning Plan"),
153
+ title="AI Learning Path Generator",
154
+ description="""
155
+ Welcome to your personalized learning journey!
156
+
157
+ Fill in your information below to get a customized learning path:
158
+ 1. Enter your basic information
159
+ 2. Specify your learning goals
160
+ 3. Choose your preferred learning style
161
+ 4. Set your weekly time commitment
162
+ Contact-: AJoshi 91-8847374914 email -joshianupam32@gmail.com
163
+
164
+ Click submit to generate your personalized learning plan!
165
+ """,
166
+ examples=[
167
+ [
168
+ "John Doe",
169
+ 25,
170
+ "Bachelor's Degree",
171
+ "Machine Learning, Python",
172
+ "Learn Data Science",
173
+ "Visual",
174
+ 10
175
+ ],
176
+ [
177
+ "Jane Smith",
178
+ 30,
179
+ "Master's Degree",
180
+ "Web Development, JavaScript",
181
+ "Full Stack Development",
182
+ "Kinesthetic",
183
+ 15
184
+ ]
185
+ ]
186
+ )
187
+ return iface
188
+
189
+ def main():
190
+ # Create and launch the platform
191
+ platform = EasyLearningPlatform()
192
+ interface = platform.create_interface()
193
+ interface.launch(share=True)
194
+
195
+ if __name__ == "__main__":
196
+ """
197
+ # Run these commands in Google Colab first:
198
+ !pip install gradio transformers torch numpy pandas scikit-learn
199
+ """
200
+ main()