SalmanAboAraj commited on
Commit
53b2317
·
verified ·
1 Parent(s): 571eb0b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -18
app.py CHANGED
@@ -1,22 +1,12 @@
1
- from sklearn.datasets import fetch_openml
2
- from sklearn.preprocessing import StandardScaler
3
- from sklearn.model_selection import train_test_split
4
- import gradio as gr
5
  import numpy as np
6
  import cv2
 
7
  from sklearn import svm
8
 
9
- # Load and preprocess data
10
- X, y = fetch_openml("mnist_784", version=1, return_X_y=True, as_frame=False)
11
- scaler = StandardScaler()
12
- X = scaler.fit_transform(X)
13
-
14
- X_train_img, X_test_img, y_train_img, y_test_img = train_test_split(
15
- X, y, test_size=0.2, shuffle=True)
16
-
17
- # Create a classifier
18
- project_classifier = svm.SVC(kernel='linear', probability=True)
19
- project_classifier.fit(X_train_img, y_train_img)
20
 
21
  def inference(img):
22
  labels = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
@@ -30,12 +20,11 @@ def inference(img):
30
  dictionary = dict(zip(labels, map(float, pred)))
31
  return dictionary
32
 
33
- # Set up Gradio interface
34
  nbr_top_classes = 3
35
  iface = gr.Interface(fn=inference,
36
- inputs=gr.Image(source="upload"), # source= "upload" "webcam" "canvas"
37
  outputs=gr.Label(num_top_classes=nbr_top_classes),
38
  theme="darkdefault")
39
 
40
- # Launch the interface
41
  iface.launch(share=True)
 
1
+ import joblib
 
 
 
2
  import numpy as np
3
  import cv2
4
+ import gradio as gr
5
  from sklearn import svm
6
 
7
+ # تحميل النموذج وscaler
8
+ project_classifier = joblib.load('model.pkl')
9
+ scaler = joblib.load('scaler.pkl')
 
 
 
 
 
 
 
 
10
 
11
  def inference(img):
12
  labels = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
 
20
  dictionary = dict(zip(labels, map(float, pred)))
21
  return dictionary
22
 
23
+ # إعداد واجهة Gradio
24
  nbr_top_classes = 3
25
  iface = gr.Interface(fn=inference,
26
+ inputs=gr.Image(source="upload"),
27
  outputs=gr.Label(num_top_classes=nbr_top_classes),
28
  theme="darkdefault")
29
 
 
30
  iface.launch(share=True)