Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
import gradio as gr
|
| 3 |
+
#This is a pipeline for text classification using the Arabic MARBERT model for news article classification from Hugging Face.
|
| 4 |
+
Clasification = pipeline('text-classification', model='Ammar-alhaj-ali/arabic-MARBERT-news-article-classification')
|
| 5 |
+
|
| 6 |
+
#This function will take and input then return the label and the score of that sentence.
|
| 7 |
+
def classification_fun(news_article):
|
| 8 |
+
results = Clasification(news_article)
|
| 9 |
+
return results[0]['label'], results[0]['score']
|
| 10 |
+
|
| 11 |
+
#CSS styling for the Gradio interface
|
| 12 |
+
custom_css = """
|
| 13 |
+
textarea, .gradio-output {
|
| 14 |
+
direction: rtl;
|
| 15 |
+
background-color: black;
|
| 16 |
+
color: white;
|
| 17 |
+
border: 2px solid #800020;
|
| 18 |
+
border-radius: 5px;
|
| 19 |
+
padding: 10px;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
label {
|
| 23 |
+
font-size: 18px;
|
| 24 |
+
font-weight: bold;
|
| 25 |
+
text-align: center;
|
| 26 |
+
background-color: #800020;
|
| 27 |
+
color: white;
|
| 28 |
+
box-shadow: 2px 2px 5px rgba(0,0,0,0.2);
|
| 29 |
+
padding: 5px;
|
| 30 |
+
display: block;
|
| 31 |
+
margin: 10px 0;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
.gradio-container {
|
| 35 |
+
background-color: black;
|
| 36 |
+
padding: 20px;
|
| 37 |
+
box-sizing: border-box;
|
| 38 |
+
}
|
| 39 |
+
"""
|
| 40 |
+
|
| 41 |
+
my_model = gr.Interface(
|
| 42 |
+
fn=classification_fun,
|
| 43 |
+
inputs=gr.Textbox(label="News Articles", lines=10, placeholder="Enter your Article"),
|
| 44 |
+
outputs=[gr.Textbox(label="Label of the Article"), gr.Number(label="Confidence Score")],
|
| 45 |
+
css=custom_css
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
my_model.launch()
|