File size: 1,158 Bytes
7fdacf0 d2347dd 7fdacf0 872437c 7fdacf0 872437c 7fdacf0 872437c 7fdacf0 872437c 7fdacf0 872437c |
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 36 37 38 39 40 41 42 |
import gradio as gr
import joblib
import os
model = joblib.load('arabic_text_classifier.pkl')
vectorizer = joblib.load('tfidf_vectorizer.pkl')
label_encoder = joblib.load('label_encoder.pkl')
def predict_category(text):
text_vector = vectorizer.transform([text])
probabilities = model.predict_proba(text_vector)[0]
max_prob = max(probabilities)
predicted_category = model.predict(text_vector)[0]
if max_prob < 0.5:
return "Other"
predicted_label = label_encoder.inverse_transform([predicted_category])[0]
return predicted_label
HF_TOKEN = os.getenv("classification")
hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN, "crowdsourced-text-classification-data")
iface = gr.Interface(
fn=predict_category,
inputs=gr.Textbox(
lines=5,
placeholder="Enter text in Arabic here...",
label="Text"
),
outputs=gr.Label(label="Predicted Category"),
title="Arabic Text Classification",
description="Enter an Arabic text to get its classification based on the trained model.",
allow_flagging="auto",
flagging_callback=hf_writer,
)
iface.launch(share=True)
|