Spaces:
Running
Running
SalmanAboAraj
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,43 +1,55 @@
|
|
1 |
import platform
|
2 |
import pathlib
|
|
|
|
|
3 |
plt = platform.system()
|
4 |
pathlib.WindowsPath = pathlib.PosixPath
|
5 |
|
6 |
-
|
7 |
import requests
|
8 |
-
|
9 |
-
|
10 |
-
# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
|
11 |
-
|
12 |
-
# %% auto 0
|
13 |
-
__all__ = ['learn', 'categories', 'image', 'label', 'examples', 'interface', 'classify_image']
|
14 |
-
|
15 |
-
# %% app.ipynb 1
|
16 |
from fastai.vision.all import *
|
17 |
import PIL.Image
|
18 |
PIL.Image.MAX_IMAGE_PIXELS = None
|
19 |
from PIL import Image
|
20 |
-
|
21 |
import gradio as gr
|
22 |
|
23 |
-
#
|
24 |
learn = load_learner('ChestXRayfine.pkl')
|
25 |
|
26 |
-
#
|
27 |
-
categories=('COVID19','Normal','Pneumonia','Turberculosis')
|
28 |
|
|
|
29 |
def classify_image(img):
|
30 |
-
pred,indx,probs=learn.predict(img)
|
31 |
-
return dict(zip(categories,map(float,probs)))
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import platform
|
2 |
import pathlib
|
3 |
+
|
4 |
+
# معالجة مشكلة المسارات على الأنظمة المختلفة
|
5 |
plt = platform.system()
|
6 |
pathlib.WindowsPath = pathlib.PosixPath
|
7 |
|
|
|
8 |
import requests
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
from fastai.vision.all import *
|
10 |
import PIL.Image
|
11 |
PIL.Image.MAX_IMAGE_PIXELS = None
|
12 |
from PIL import Image
|
|
|
13 |
import gradio as gr
|
14 |
|
15 |
+
# تحميل النموذج المدرب
|
16 |
learn = load_learner('ChestXRayfine.pkl')
|
17 |
|
18 |
+
# قائمة التصنيفات
|
19 |
+
categories = ('COVID19', 'Normal', 'Pneumonia', 'Turberculosis')
|
20 |
|
21 |
+
# دالة التصنيف
|
22 |
def classify_image(img):
|
23 |
+
pred, indx, probs = learn.predict(img)
|
24 |
+
return dict(zip(categories, map(float, probs)))
|
25 |
+
|
26 |
+
# إعداد واجهة Gradio بالإصدار الأحدث
|
27 |
+
with gr.Blocks() as interface:
|
28 |
+
gr.Markdown("# Chest X-Ray Classification")
|
29 |
+
gr.Markdown("Upload a chest X-ray image to classify it into one of the following categories: **COVID-19**, **Normal**, **Pneumonia**, or **Tuberculosis**.")
|
30 |
+
|
31 |
+
# إدخال الصورة
|
32 |
+
with gr.Row():
|
33 |
+
image_input = gr.Image(type="pil", label="Upload Chest X-ray Image")
|
34 |
+
|
35 |
+
# إخراج النتائج
|
36 |
+
with gr.Row():
|
37 |
+
label_output = gr.Label(label="Classification Results")
|
38 |
+
|
39 |
+
# أمثلة جاهزة
|
40 |
+
example_images = gr.Examples(
|
41 |
+
examples=['1.jpeg', '10.png', '11.png', '12.jpeg', '13.jpeg', '14.jpeg', '15.jpeg', '16.jpeg', '17.jpeg',
|
42 |
+
'18.jpeg', '19.jpeg', '2.jpeg', '20.jpeg', '21.jpg', '22.jpg', '23.jpg', '3.jpeg', '4.jpeg', '5.jpeg',
|
43 |
+
'6.png', '7.png', '8.png', '9.png'],
|
44 |
+
inputs=image_input,
|
45 |
+
)
|
46 |
+
|
47 |
+
# زر التنفيذ
|
48 |
+
predict_button = gr.Button("Classify")
|
49 |
+
|
50 |
+
# الربط بين المدخلات والمخرجات
|
51 |
+
predict_button.click(classify_image, inputs=[image_input], outputs=[label_output])
|
52 |
+
|
53 |
+
# تشغيل التطبيق
|
54 |
+
if __name__ == "__main__":
|
55 |
+
interface.launch()
|