skolvankar commited on
Commit
2b9215e
·
1 Parent(s): 8508bc5

Add application file

Browse files
Files changed (2) hide show
  1. 2app.py +106 -0
  2. app.py +25 -28
2app.py ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """[DRAFT]SWAYAM_CHATBOT SYSTEM_Course Recommendation System.ipynb
3
+
4
+ Automatically generated by Colaboratory.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/1s4_kZDgJcvRr7kfnw12oFNus45E2oOr9
8
+ """
9
+
10
+ # Commented out IPython magic to ensure Python compatibility.
11
+ # %pip install openai
12
+
13
+ import openai
14
+ import pandas as pd
15
+ from sklearn.feature_extraction.text import TfidfVectorizer
16
+ from sklearn.metrics.pairwise import linear_kernel
17
+
18
+ # Set your OpenAI API key
19
+ openai.api_key = "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" # Replace with your actual API key
20
+
21
+ # Sample course data
22
+ data = {
23
+ 'CourseID': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],
24
+ 'Title': ['Python Programming',
25
+ 'Data Science with Python',
26
+ 'Machine Learning',
27
+ 'Web Development',
28
+ 'Environmental Studies',
29
+ 'Business Communication (Language-English/ Hindi/ MIL)',
30
+ 'Management Principles and Applications',
31
+ 'Analytical Geometry',
32
+ 'Cost Accounting',
33
+ 'Principles of Micro Economics',
34
+ 'Human Resource Management',
35
+ 'Fundamentals of Financial Management',
36
+ 'Classical Political Philosophy',
37
+ 'Differential Calculus',
38
+ 'Sociology of Health and Medicine',
39
+ 'Economic History of India (1857-1947)'],
40
+ 'Description': [
41
+ 'Start your journey in programming by learning Python from scratch.',
42
+ 'Start your journey in Data Science and become data scientist by learning python and other data science libraries.',
43
+ 'Master your programming skills and dive into the world of machine learning with python and other machine learning libraries',
44
+ 'Start your journey in web development using python programming and Django library.',
45
+ 'Explore the intricate relationship between humanity and the environment, and learn how to make informed decisions to preserve and protect our planet.',
46
+ 'Enhance your communication skills in English, Hindi, or your mother tongue (MIL) to excel in the business world. Learn the art of effective written and verbal communication.',
47
+ 'Gain a comprehensive understanding of the fundamental principles of management and their real-world applications to thrive in today\'s dynamic business environment.',
48
+ 'Delve into the world of analytical geometry and master the mathematical techniques and concepts that underlie this fascinating branch of mathematics.',
49
+ 'Learn the essentials of cost accounting and financial analysis to make sound business decisions and optimize financial performance.',
50
+ 'Explore the principles of microeconomics, the study of individual economic behavior, and understand how economic decisions impact businesses and society.',
51
+ 'Gain insight into the management of human resources, from recruitment to employee development, and learn how effective HR practices drive organizational success.',
52
+ 'Understand the core principles of financial management, including budgeting, investment, and risk analysis, to make strategic financial decisions.',
53
+ 'Dive into the world of classical political philosophy and explore the influential works of thinkers like Plato, Aristotle, and more, to understand the foundations of political thought.',
54
+ 'Master the fundamental concepts of differential calculus, a branch of mathematics that deals with rates of change, and its applications in various fields.',
55
+ 'Explore the sociological aspects of health, illness, and healthcare systems. Understand how society shapes healthcare practices and policies.',
56
+ 'Take a journey through the economic history of India during a critical period of change and transformation, from 1857 to 1947, and understand the economic forces that shaped the nation.'
57
+ ]
58
+ }
59
+
60
+ # Create a DataFrame from the course data
61
+ courses_df = pd.DataFrame(data)
62
+
63
+ # Function to recommend courses based on user skills
64
+ def recommend_courses(user_skills):
65
+ # Combine the user's skills into a single string
66
+ user_skills = ', '.join(user_skills.split())
67
+
68
+ # Create a TF-IDF vectorizer to convert course descriptions into vectors
69
+ tfidf_vectorizer = TfidfVectorizer(stop_words='english')
70
+ tfidf_matrix = tfidf_vectorizer.fit_transform(courses_df['Description'])
71
+
72
+ # Calculate cosine similarity between user skills and course descriptions
73
+ user_vector = tfidf_vectorizer.transform([user_skills])
74
+ cosine_similarities = linear_kernel(user_vector, tfidf_matrix)
75
+
76
+ # Get course recommendations based on similarity scores
77
+ recommendations = courses_df.copy()
78
+ recommendations['Similarity'] = cosine_similarities[0]
79
+
80
+ # Sort courses by similarity and recommend the top matches
81
+ recommendations = recommendations.sort_values(by='Similarity', ascending=False)
82
+ recommended_courses = recommendations[['CourseID', 'Title', 'Similarity']]
83
+
84
+ return recommended_courses
85
+
86
+ # Function to interact with GPT-3 and provide recommendations
87
+ def gpt_recommend_courses(user_input):
88
+ response = openai.Completion.create(
89
+ engine="text-davinci-002",
90
+ prompt=f"I have skills in {user_input}. What courses do you recommend?",
91
+ max_tokens=100,
92
+ n=1,
93
+ stop=None,
94
+ temperature=0.7,
95
+ )
96
+ recommendation_prompt = response.choices[0].text.strip()
97
+
98
+ return recommend_courses(recommendation_prompt)
99
+
100
+ # User input for skills
101
+ user_input = input("Enter your skills: ")
102
+
103
+ # Get course recommendations using GPT-3
104
+ recommended_courses = gpt_recommend_courses(user_input)
105
+ print("\nRecommended Courses:")
106
+ print(recommended_courses)
app.py CHANGED
@@ -1,15 +1,17 @@
1
  # -*- coding: utf-8 -*-
2
- """[DRAFT]SWAYAM_CHATBOT SYSTEM_Course Recommendation System.ipynb
3
 
4
  Automatically generated by Colaboratory.
5
 
6
  Original file is located at
7
- https://colab.research.google.com/drive/1s4_kZDgJcvRr7kfnw12oFNus45E2oOr9
8
  """
9
 
10
  # Commented out IPython magic to ensure Python compatibility.
11
  # %pip install openai
 
12
 
 
13
  import openai
14
  import pandas as pd
15
  from sklearn.feature_extraction.text import TfidfVectorizer
@@ -39,9 +41,9 @@ data = {
39
  'Economic History of India (1857-1947)'],
40
  'Description': [
41
  'Start your journey in programming by learning Python from scratch.',
42
- 'Start your journey in Data Science and become data scientist by learning python and other data science libraries.',
43
- 'Master your programming skills and dive into the world of machine learning with python and other machine learning libraries',
44
- 'Start your journey in web development using python programming and Django library.',
45
  'Explore the intricate relationship between humanity and the environment, and learn how to make informed decisions to preserve and protect our planet.',
46
  'Enhance your communication skills in English, Hindi, or your mother tongue (MIL) to excel in the business world. Learn the art of effective written and verbal communication.',
47
  'Gain a comprehensive understanding of the fundamental principles of management and their real-world applications to thrive in today\'s dynamic business environment.',
@@ -77,30 +79,25 @@ def recommend_courses(user_skills):
77
  recommendations = courses_df.copy()
78
  recommendations['Similarity'] = cosine_similarities[0]
79
 
80
- # Sort courses by similarity and recommend the top matches
81
- recommendations = recommendations.sort_values(by='Similarity', ascending=False)
82
- recommended_courses = recommendations[['CourseID', 'Title', 'Similarity']]
83
-
84
- return recommended_courses
85
-
86
- # Function to interact with GPT-3 and provide recommendations
87
- def gpt_recommend_courses(user_input):
88
- response = openai.Completion.create(
89
- engine="text-davinci-002",
90
- prompt=f"I have skills in {user_input}. What courses do you recommend?",
91
- max_tokens=100,
92
- n=1,
93
- stop=None,
94
- temperature=0.7,
95
  )
96
- recommendation_prompt = response.choices[0].text.strip()
97
 
98
- return recommend_courses(recommendation_prompt)
 
99
 
100
- # User input for skills
101
- user_input = input("Enter your skills: ")
102
 
103
- # Get course recommendations using GPT-3
104
- recommended_courses = gpt_recommend_courses(user_input)
105
- print("\nRecommended Courses:")
106
- print(recommended_courses)
 
 
 
 
 
 
 
 
1
  # -*- coding: utf-8 -*-
2
+ """[DRAFT]SWAYAM_CHATBOT SYSTEM_Course Recommendation System[Demo v0.3].ipynb
3
 
4
  Automatically generated by Colaboratory.
5
 
6
  Original file is located at
7
+ https://colab.research.google.com/drive/1SEEfmJflBUSuKGVBoGqaR_YwfBGCjH86
8
  """
9
 
10
  # Commented out IPython magic to ensure Python compatibility.
11
  # %pip install openai
12
+ # %pip install gradio
13
 
14
+ import gradio as gr
15
  import openai
16
  import pandas as pd
17
  from sklearn.feature_extraction.text import TfidfVectorizer
 
41
  'Economic History of India (1857-1947)'],
42
  'Description': [
43
  'Start your journey in programming by learning Python from scratch.',
44
+ 'Start your journey in Data Science and become a data scientist by learning Python and other data science libraries.',
45
+ 'Master your programming skills and dive into the world of machine learning with Python and other machine learning libraries',
46
+ 'Start your journey in web development using Python programming and Django library.',
47
  'Explore the intricate relationship between humanity and the environment, and learn how to make informed decisions to preserve and protect our planet.',
48
  'Enhance your communication skills in English, Hindi, or your mother tongue (MIL) to excel in the business world. Learn the art of effective written and verbal communication.',
49
  'Gain a comprehensive understanding of the fundamental principles of management and their real-world applications to thrive in today\'s dynamic business environment.',
 
79
  recommendations = courses_df.copy()
80
  recommendations['Similarity'] = cosine_similarities[0]
81
 
82
+ # Determine recommendation levels
83
+ recommendations['Recommendation Level'] = recommendations['Similarity'].apply(
84
+ lambda x: 'Highly Recommended' if x > 0.5 else ('Partially Recommended' if x > 0.2 else 'LOW')
 
 
 
 
 
 
 
 
 
 
 
 
85
  )
 
86
 
87
+ # Filter and display courses with HIGH or MEDIUM recommendation levels
88
+ high_medium_courses = recommendations[(recommendations['Recommendation Level'] == 'Highly Recommended') | (recommendations['Recommendation Level'] == 'Partially Recommended')]
89
 
90
+ # Generate an HTML table for the filtered courses
91
+ table = high_medium_courses[['Title', 'Recommendation Level']].to_html(classes='table table-bordered', index=False, escape=False)
92
 
93
+ return table
94
+
95
+ # Gradio interface
96
+ iface = gr.Interface(
97
+ fn=recommend_courses,
98
+ inputs="text",
99
+ outputs="html",
100
+ title = "COURSE Recommendation Chatbot: SWAYAM",
101
+ live=True,
102
+ )
103
+ iface.launch()