kkPriyanka
commited on
Commit
•
4da10ec
1
Parent(s):
4836638
Classification using DistillBert
Browse files
app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
classifier = pipeline("sentiment-analysis", model="kkPriyanka/cls_distilbert_model")
|
5 |
+
|
6 |
+
def text_classification(text):
|
7 |
+
result= classifier(text)
|
8 |
+
sentiment_label = result[0]['label']
|
9 |
+
sentiment_score = result[0]['score']
|
10 |
+
formatted_output = f"This sentiment is {sentiment_label} with the probability {sentiment_score*100:.2f}%"
|
11 |
+
return formatted_output
|
12 |
+
|
13 |
+
examples=["This is wonderful movie!", "The movie was really bad; I didn't like it."]
|
14 |
+
|
15 |
+
io = gr.Interface(fn=text_classification,
|
16 |
+
inputs= gr.Textbox(lines=2, label="Text", placeholder="Enter title here..."),
|
17 |
+
outputs=gr.Textbox(lines=2, label="Text Classification Result"),
|
18 |
+
title="Text Classification",
|
19 |
+
description="Enter a text and see the text classification result!",
|
20 |
+
examples=examples)
|
21 |
+
|
22 |
+
io.launch(inline=False, share=True)
|