leghari221 commited on
Commit
2a358f8
1 Parent(s): 815e7c8

Upload categorical_classification.py

Browse files
Files changed (1) hide show
  1. categorical_classification.py +35 -0
categorical_classification.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """Categorical Classification.ipynb
3
+
4
+ Automatically generated by Colaboratory.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/1_5FDUSnfrkNJilGyx-hoov0pnOF1CHWn
8
+ """
9
+
10
+ !pip install gradio transformers
11
+
12
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
13
+
14
+ tokenizer = AutoTokenizer.from_pretrained("Softechlb/articles_classification")
15
+ model = AutoModelForSequenceClassification.from_pretrained("Softechlb/articles_classification")
16
+
17
+ from transformers import pipeline
18
+
19
+ classifier = pipeline("text-classification", model=model, tokenizer=tokenizer)
20
+ def classify_text(text):
21
+ result = classifier(text)[0]
22
+ label = result["label"]
23
+ return label
24
+
25
+ import gradio as gr
26
+
27
+ interface = gr.Interface(
28
+ fn=classify_text,
29
+ inputs="textbox",
30
+ outputs="text",
31
+ title="Categorical Classification",
32
+ description="Text classification model Softechlb/articles_classification from Hugging Face that can classify texts into categories.",
33
+ )
34
+
35
+ interface.launch(share=True)