File size: 1,302 Bytes
b790f42
 
 
 
 
 
 
 
 
 
 
 
18b565b
 
b790f42
 
 
 
 
 
 
 
 
a7d7769
b790f42
 
a7d7769
b790f42
 
 
18b565b
b790f42
 
 
cec4a0c
b790f42
fa713b6
b790f42
 
 
 
 
 
 
a7d7769
b790f42
 
 
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
import spacy
from keybert import KeyBERT
import numpy as np
import pandas as pd
import os
import re
import json
import seaborn as sns
import gradio as gr



# def separate_punc(text):
#     return [token.text.lower() for token in text if token.text not in '\n\n \n\n\n!"-#$%&()--.*+,-/:;<=>?@[\\]^_`{|}~\t\n ']

    
kw_model = KeyBERT(model='all-mpnet-base-v2')

from sklearn.pipeline import Pipeline
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.svm import LinearSVC
from sklearn.linear_model import LogisticRegression



# Feed the training data through the pipeline



def run(text):
    # separate_punc(text)
    
    keywords = kw_model.extract_keywords(text, keyphrase_ngram_range=(1, 3), stop_words='english', highlight=False,)
    keywords_list= list(dict(keywords).keys())
    s='We suggest the following as potential topic name for the given article: \n '
    for i in range (len(keywords_list)):
        s = s+keywords_list[i] + '\n '
        # if i<=len(keywords_list):
        #     print('Would you like another suggestion?')
        #     f=input()
        #     if f=='No':
        #         break
        # else:
        #     print('Sorry That is all we can suggest')
    return s

iface = gr.Interface(fn=run, inputs="text", outputs="text")
iface.launch()