File size: 1,022 Bytes
2a358f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# -*- coding: utf-8 -*-
"""Categorical Classification.ipynb

Automatically generated by Colaboratory.

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

!pip install gradio transformers

from transformers import AutoTokenizer, AutoModelForSequenceClassification

tokenizer = AutoTokenizer.from_pretrained("Softechlb/articles_classification")
model = AutoModelForSequenceClassification.from_pretrained("Softechlb/articles_classification")

from transformers import pipeline

classifier = pipeline("text-classification", model=model, tokenizer=tokenizer)
def classify_text(text):
  result = classifier(text)[0]
  label = result["label"]
  return label

import gradio as gr

interface = gr.Interface(
  fn=classify_text,
  inputs="textbox",
  outputs="text",
  title="Categorical Classification",
  description="Text classification model Softechlb/articles_classification from Hugging Face that can classify texts into categories.",
)

interface.launch(share=True)