File size: 945 Bytes
53b2317
ffb4efb
 
53b2317
3a4d95a
ffb4efb
53b2317
 
 
ffb4efb
 
3a4d95a
ffb4efb
3a4d95a
ffb4efb
3a4d95a
 
ffb4efb
 
 
 
 
53b2317
ffb4efb
3a4d95a
229af1a
3a4d95a
 
 
 
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
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)