Run this model with HF Jobs
Run osam36b/Arabic_Text_Classification_Using_SANAD_Dataset on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/osam36b/Arabic_Text_Classification_Using_SANAD_Dataset. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/osam36b/Arabic_Text_Classification_Using_SANAD_Dataset on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use osam36b/Arabic_Text_Classification_Using_SANAD_Dataset with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use osam36b/Arabic_Text_Classification_Using_SANAD_Dataset with Keras:
# !pip install -U keras tensorflow huggingface_hub # Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here; # "jax" and "torch" also work for computation once TensorFlow is installed. import os os.environ["KERAS_BACKEND"] = "tensorflow" import keras model = keras.saving.load_model("hf://osam36b/Arabic_Text_Classification_Using_SANAD_Dataset") - Notebooks
- Google Colab
- Kaggle
File size: 2,549 Bytes
882da06 | 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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | import gradio as gr
import tensorflow as tf
from tensorflow.keras.preprocessing.sequence import pad_sequences
from tensorflow.keras.preprocessing.text import tokenizer_from_json
import pickle
import re
import os
# 1. تحميل الملفات والنموذج
def load_resources():
model = tf.keras.models.load_model('/content/exported_model/complaints_model.keras')
with open('/content/exported_model/tokenizer.json', 'r', encoding='utf-8') as f:
tokenizer_data = f.read()
tokenizer = tokenizer_from_json(tokenizer_data)
with open('/content/exported_model/label_encoder.pkl', 'rb') as f:
encoder = pickle.load(f)
return model, tokenizer, encoder
try:
model, tokenizer, encoder = load_resources()
except Exception as e:
print(f"Error loading resources: {e}")
# 2. تنظيف ومعالجة النص العربي
def normalize(text):
text = re.sub(r'[إأآا]', 'ا', text)
text = re.sub(r'ى', 'ي', text)
text = re.sub(r'ة', 'ه', text)
return text
def clean_arabic(text):
text = str(text)
text = re.sub(r'[^\u0621-\u064A\s]', '', text)
text = re.sub(r'(.)\1{2,}', r'\1', text)
text = normalize(text)
return re.sub(r'\s+', ' ', text).strip()
# 3. دالة التوقع والتحليل
def classify_arabic_text(text):
if not text.strip():
return "الرجاء إدخال نص صالح"
cleaned = clean_arabic(text)
sequence = tokenizer.texts_to_sequences([cleaned])
padded = pad_sequences(sequence, maxlen=30, padding='post', truncating='post')
predictions = model.predict(padded)[0]
# بناء قاموس بالاحتمالات لكل فئة
results = {}
for i, class_name in enumerate(encoder.classes_):
results[str(class_name)] = float(predictions[i])
return results
# 4. بناء واجهة Gradio
interface = gr.Interface(
fn=classify_arabic_text,
inputs=gr.Textbox(lines=5, placeholder="أدخل النص العربي هنا لتبدأ عملية التصنيف...", label="النص المدخل"),
outputs=gr.Label(num_top_classes=3, label="التصنيفات المحتملة"),
title="تصنيف النصوص العربية (Gradio)",
description="تطبيق ذكاء اصطناعي لتصنيف النصوص والشكاوى العربية إلى فئاتها المناسبة باستخدام نموذج شبكة عصبية متكررة (RNN).",
theme="soft"
)
if __name__ == "__main__":
interface.launch(share=True)
|