Spaces:
Runtime error
Runtime error
import pandas as pd | |
import subprocess | |
import sys | |
def install(package): | |
subprocess.check_call([sys.executable, "-m", "pip", "install", package], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) | |
install("keybert") | |
install("keyphrase_vectorizers") | |
import warnings | |
from keybert import KeyBERT | |
from keyphrase_vectorizers import KeyphraseCountVectorizer | |
import gradio as gr | |
with warnings.catch_warnings(): | |
warnings.simplefilter("ignore", category=UserWarning) | |
embedding = 'all-mpnet-base-v2' | |
key_model = KeyBERT(model=embedding) | |
vectorizer_params = KeyphraseCountVectorizer(spacy_pipeline='en_core_web_sm', pos_pattern='<J.*>*<N.*>+', stop_words='english', lowercase=True) | |
def get_keywords(course_name, course_desc): | |
keywords_list = [] | |
course_name, course_desc = course_name.strip().lower(), course_desc.strip().lower() | |
data = course_name+". "+course_desc | |
keywords = key_model.extract_keywords(data, vectorizer=vectorizer_params, stop_words='english', top_n=7, use_mmr=True) | |
keywords_list = list(dict(keywords).keys()) | |
return ", ".join(keywords_list) | |
def get_keywords_file(file): | |
input_data = pd.read_csv(file) | |
keywords_data = [] | |
for i in range(len(input_data)): | |
curr_keywords = get_keywords(input_data["Course Name"][i], input_data["Course Desc"][i]) | |
keywords_data.append(curr_keywords) | |
input_data["Relevant Tags"] = keywords_data | |
output_file = "CourseTagGen_Result.csv" | |
input_data.to_csv(output_file) | |
return output_file | |
course_ex = [["Biotechnology", | |
""" | |
Biotechnology is one of the fastest moving fields in the biosciences. Genetic engineering techniques have allowed the manipulation of microorganisms, plants and animals to produce commercially important compounds, or to have improved characteristics. This module examines the techniques that are used in genetic manipulation and looks at examples of how the technology has been applied. The practical outcomes of genome sequencing projects and the way in which knowledge of the human genome can be applied to medicine and forensics are also considered. Practical classes and workshops allow students to perform some of the key techniques for themselves. | |
This course aims to provide an understanding, at a basic level, of the diverse ways in which the biological processes of plants, microbes and animals can be manipulated for benefit, and to demonstrate how biotechnology influences our everyday lives. | |
""" | |
], | |
["Intelligent System Control", | |
""" | |
This module introduces students to the design and application of intelligent control systems, with a focus on modern algorithmic, computer-aided design methods. Starting from the well-known proportional-integral algorithm, essential concepts such as digital and optimal control are introduced using straightforward algebra and block diagrams. The module addresses the needs of students across the engineering discipline who would like to advance their knowledge of automatic control and optimisation, with practical worked-examples from robotics, industrial process control and environmental systems, among other areas. This module also introduces students to statistical modelling concepts that are rather different to classical engineering model development based on physical equations. These methods have wide ranging application for control, signal processing, and forecasting, with applications beyond engineering into medicine, economics, environment sciences, and so on. | |
On successful completion of this module students will: | |
Understand various hierarchical architectures of intelligent control; | |
Be able to analyse and design discrete-time models and digital control systems; | |
Be able to design optimal model-based control systems; | |
Identify mathematical models from engineering data; | |
Design and evaluate system performance; | |
Be able to use statistical tools for the analysis of data; | |
Be able to use modern computational aids for the design of control systems; | |
Appreciate cutting-edge research developments in these areas; | |
Demonstrate an understanding of the control objectives and practical constraints, and be able to suggest design solutions for a range of case study examples. | |
"""], | |
["Migration, Citizenship and Belonging", | |
""" | |
'Belonging' to a nation is widely seen to be as 'natural' as 'belonging' to a family or a home. This course undermines assumptions about national belonging by introducing students to a range of theoretical approaches and debates. How are the nation and national belonging socially constructed? How is the nation defined? Who belongs, who doesn't? What are the impacts of migration on definitions of the nation? In turn, how is migration enabled or constricted by national borders and boundaries? | |
The module focuses on nation formation in relation to migration. It will explore what everyday practices, discourses, and policies reveal about the ways we think about, and inhabit, the nation and migration? Although we will focus on the example of Britain, the issues raised will be of interest to all students concerned with the effects of nationalisms and ideas of belonging and entitlement, which many countries of the contemporary world are presently debating in the context of the 'Age of migration' (Castles and Miller 1998). | |
Examples of topics covered include: ‘We the people’ – the forging of nations; the racial state; gender, sexuality and the nation; migration, citizenship, and integration; language as border control. | |
This course aims: | |
To introduce sociological issues surrounding the concepts of nation, migration and multiculturalism | |
To develop an understanding of discourse analysis | |
To introduce questions of power and politics surrounding the processes of identity formation | |
"""] | |
] | |
table_md = """ | |
| Course Name | Course Desc | | |
|----------------|-------------------| | |
| Course A | Desc Course A | | |
| Course B | Desc Course B | | |
| ... | ... | | |
""" | |
first_tab = gr.Interface(fn=get_keywords, | |
inputs=[gr.Textbox(label="Course Name"), | |
gr.Textbox(label="Course Description")], | |
outputs=gr.Textbox(label="Relevant Tags", max_lines=200), | |
description="Generating tags/keywords based on Keyphrase-BERT Extraction", | |
examples=course_ex) | |
second_tab = gr.Interface(fn=get_keywords_file, | |
inputs=gr.File(label="Upload a CSV file"), | |
outputs=gr.File(label="Upload a CSV file"), | |
description=f"Generating tags/keywords based on Keyphrase-BERT Extraction\n\nFollow this column name format!\n{table_md}") | |
iface = gr.TabbedInterface(interface_list=[first_tab, second_tab], | |
tab_names=["Generate From Text Input", "Generate From CSV/XLSX"], | |
title="College Course Tags Generator") | |
iface.launch() |