Create app.py
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="Ahmed107/EOS_bert")
|
| 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=["اهلا", "والسلام عليكم ورحمة الله"]
|
| 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()
|