Spaces:
Sleeping
Sleeping
abdulmatinomotoso
commited on
Commit
·
efb3d97
1
Parent(s):
9ff6263
Update app.py
Browse files
app.py
CHANGED
@@ -7,10 +7,10 @@ from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
|
7 |
import torch
|
8 |
|
9 |
#Defining the labels of the models
|
10 |
-
labels = [
|
11 |
|
12 |
#Defining the models and tokenuzer
|
13 |
-
model_name =
|
14 |
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
15 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
16 |
|
@@ -35,8 +35,8 @@ def clean_text(url):
|
|
35 |
" +", " ", text
|
36 |
).strip() # get rid of multiple spaces and replace with a single
|
37 |
|
38 |
-
text = re.sub(r
|
39 |
-
text = re.sub(r
|
40 |
|
41 |
return text
|
42 |
|
@@ -44,7 +44,7 @@ def clean_text(url):
|
|
44 |
def get_category(file):
|
45 |
text = clean_text(file)
|
46 |
|
47 |
-
input_tensor = tokenizer.encode(text, return_tensors=
|
48 |
logits = model(input_tensor).logits
|
49 |
|
50 |
softmax = torch.nn.Softmax(dim=1)
|
@@ -56,10 +56,10 @@ def get_category(file):
|
|
56 |
return emotion
|
57 |
|
58 |
#Creating the interface for the radio app
|
59 |
-
demo = gr.Interface(get_category, inputs=gr.inputs.Textbox(label=
|
60 |
-
outputs =
|
61 |
-
title=
|
62 |
|
63 |
#Launching the gradio app
|
64 |
-
if __name__ ==
|
65 |
demo.launch(debug=True)
|
|
|
7 |
import torch
|
8 |
|
9 |
#Defining the labels of the models
|
10 |
+
labels = ["business", "science","health", "world", "sport", "politics", "entertainment", "tech"]
|
11 |
|
12 |
#Defining the models and tokenuzer
|
13 |
+
model_name = "valurank/finetuned-distilbert-news-article-categorization"
|
14 |
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
15 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
16 |
|
|
|
35 |
" +", " ", text
|
36 |
).strip() # get rid of multiple spaces and replace with a single
|
37 |
|
38 |
+
text = re.sub(r"Date\s\d{1,2}\/\d{1,2}\/\d{4}", "", text) #remove date
|
39 |
+
text = re.sub(r"\d{1,2}:\d{2}\s[A-Z]+\s[A-Z]+", "", text) #remove time
|
40 |
|
41 |
return text
|
42 |
|
|
|
44 |
def get_category(file):
|
45 |
text = clean_text(file)
|
46 |
|
47 |
+
input_tensor = tokenizer.encode(text, return_tensors="pt", truncation=True)
|
48 |
logits = model(input_tensor).logits
|
49 |
|
50 |
softmax = torch.nn.Softmax(dim=1)
|
|
|
56 |
return emotion
|
57 |
|
58 |
#Creating the interface for the radio app
|
59 |
+
demo = gr.Interface(get_category, inputs=gr.inputs.Textbox(label="Drop your articles here"),
|
60 |
+
outputs = "text",
|
61 |
+
title="News Article Categorization")
|
62 |
|
63 |
#Launching the gradio app
|
64 |
+
if __name__ == "__main__":
|
65 |
demo.launch(debug=True)
|