File size: 5,716 Bytes
5a359a3
8508bc5
5a359a3
 
 
 
8508bc5
5a359a3
 
8508bc5
 
 
5a359a3
 
 
 
 
8508bc5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5a359a3
 
8508bc5
5a359a3
 
 
8508bc5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# -*- coding: utf-8 -*-
"""[DRAFT]SWAYAM_CHATBOT SYSTEM_Course Recommendation System.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1s4_kZDgJcvRr7kfnw12oFNus45E2oOr9
"""

# Commented out IPython magic to ensure Python compatibility.
# %pip install openai

import openai
import pandas as pd
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import linear_kernel

# Set your OpenAI API key
openai.api_key = "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"  # Replace with your actual API key

# Sample course data
data = {
    'CourseID': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],
    'Title': ['Python Programming',
              'Data Science with Python',
              'Machine Learning',
              'Web Development',
              'Environmental Studies',
              'Business Communication (Language-English/ Hindi/ MIL)',
              'Management Principles and Applications',
              'Analytical Geometry',
              'Cost Accounting',
              'Principles of Micro Economics',
              'Human Resource Management',
              'Fundamentals of Financial Management',
              'Classical Political Philosophy',
              'Differential Calculus',
              'Sociology of Health and Medicine',
              'Economic History of India (1857-1947)'],
    'Description': [
        'Start your journey in programming by learning Python from scratch.',
        'Start your journey in Data Science and become data scientist by learning python and other data science libraries.',
        'Master your programming skills and dive into the world of machine learning with python and other machine learning libraries',
        'Start your journey in web development using python programming and Django library.',
        'Explore the intricate relationship between humanity and the environment, and learn how to make informed decisions to preserve and protect our planet.',
        '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.',
        'Gain a comprehensive understanding of the fundamental principles of management and their real-world applications to thrive in today\'s dynamic business environment.',
        'Delve into the world of analytical geometry and master the mathematical techniques and concepts that underlie this fascinating branch of mathematics.',
        'Learn the essentials of cost accounting and financial analysis to make sound business decisions and optimize financial performance.',
        'Explore the principles of microeconomics, the study of individual economic behavior, and understand how economic decisions impact businesses and society.',
        'Gain insight into the management of human resources, from recruitment to employee development, and learn how effective HR practices drive organizational success.',
        'Understand the core principles of financial management, including budgeting, investment, and risk analysis, to make strategic financial decisions.',
        '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.',
        'Master the fundamental concepts of differential calculus, a branch of mathematics that deals with rates of change, and its applications in various fields.',
        'Explore the sociological aspects of health, illness, and healthcare systems. Understand how society shapes healthcare practices and policies.',
        '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.'
    ]
}

# Create a DataFrame from the course data
courses_df = pd.DataFrame(data)

# Function to recommend courses based on user skills
def recommend_courses(user_skills):
    # Combine the user's skills into a single string
    user_skills = ', '.join(user_skills.split())

    # Create a TF-IDF vectorizer to convert course descriptions into vectors
    tfidf_vectorizer = TfidfVectorizer(stop_words='english')
    tfidf_matrix = tfidf_vectorizer.fit_transform(courses_df['Description'])

    # Calculate cosine similarity between user skills and course descriptions
    user_vector = tfidf_vectorizer.transform([user_skills])
    cosine_similarities = linear_kernel(user_vector, tfidf_matrix)

    # Get course recommendations based on similarity scores
    recommendations = courses_df.copy()
    recommendations['Similarity'] = cosine_similarities[0]

    # Sort courses by similarity and recommend the top matches
    recommendations = recommendations.sort_values(by='Similarity', ascending=False)
    recommended_courses = recommendations[['CourseID', 'Title', 'Similarity']]

    return recommended_courses

# Function to interact with GPT-3 and provide recommendations
def gpt_recommend_courses(user_input):
    response = openai.Completion.create(
        engine="text-davinci-002",
        prompt=f"I have skills in {user_input}. What courses do you recommend?",
        max_tokens=100,
        n=1,
        stop=None,
        temperature=0.7,
    )
    recommendation_prompt = response.choices[0].text.strip()

    return recommend_courses(recommendation_prompt)

# User input for skills
user_input = input("Enter your skills: ")

# Get course recommendations using GPT-3
recommended_courses = gpt_recommend_courses(user_input)
print("\nRecommended Courses:")
print(recommended_courses)