Spaces:
Runtime error
Runtime error
| # -*- coding: utf-8 -*- | |
| """[DRAFT]SWAYAM_CHATBOT SYSTEM_Course Recommendation System[Demo v0.3].ipynb | |
| Automatically generated by Colaboratory. | |
| Original file is located at | |
| https://colab.research.google.com/drive/1SEEfmJflBUSuKGVBoGqaR_YwfBGCjH86 | |
| """ | |
| # Commented out IPython magic to ensure Python compatibility. | |
| # %pip install openai | |
| # %pip install gradio | |
| import gradio as gr | |
| 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 a 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] | |
| # Determine recommendation levels | |
| recommendations['Recommendation Level'] = recommendations['Similarity'].apply( | |
| lambda x: 'Highly Recommended' if x > 0.5 else ('Partially Recommended' if x > 0.2 else 'LOW') | |
| ) | |
| # Filter and display courses with HIGH or MEDIUM recommendation levels | |
| high_medium_courses = recommendations[(recommendations['Recommendation Level'] == 'Highly Recommended') | (recommendations['Recommendation Level'] == 'Partially Recommended')] | |
| # Generate an HTML table for the filtered courses | |
| table = high_medium_courses[['Title', 'Recommendation Level']].to_html(classes='table table-bordered', index=False, escape=False) | |
| return table | |
| # with gr.Blocks() as iface: | |
| # gr.Markdown( | |
| # """ | |
| # Welcome to the skill transformation journey on SWAYAM!!! | |
| # """) | |
| # name = gr.Textbox(label="Enter any skill") | |
| # output = gr.HTML(label = "Here is your skill transformation journey") | |
| # greet_btn = gr.Button("Submit") | |
| # greet_btn.click(fn=recommend_courses, inputs=name, outputs=output, api_name="recommend_courses") | |
| # demo.launch() | |
| # Gradio interface | |
| iface = gr.Interface( | |
| fn=recommend_courses, | |
| inputs="text", | |
| outputs="html", | |
| title = "COURSE Recommendation Chatbot: SWAYAM", | |
| live=True, | |
| ) | |
| iface.launch(share=True) |