import joblib import numpy as np import cv2 import gradio as gr from sklearn import svm # تحميل النموذج وscaler project_classifier = joblib.load('model.pkl') scaler = joblib.load('scaler.pkl') def inference(img): labels = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"] img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) H, W = 28, 28 img = cv2.resize(img, (H, W)) ret, img = cv2.threshold(img, 127, 255, cv2.THRESH_BINARY) img = img.astype("float32").flatten().reshape(1, -1) img = scaler.transform(img) pred = project_classifier.predict_proba(img).flatten() dictionary = dict(zip(labels, map(float, pred))) return dictionary # إعداد واجهة Gradio nbr_top_classes = 3 iface = gr.Interface(fn=inference, inputs=gr.Image(), outputs=gr.Label(num_top_classes=nbr_top_classes), theme="darkdefault") iface.launch(share=True)