Spaces:
Sleeping
Sleeping
File size: 1,888 Bytes
5a35a4d afd5fcc 5a35a4d afd5fcc 5a35a4d afd5fcc 5a35a4d afd5fcc 5a35a4d afd5fcc 1442a7c |
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 |
import platform
import pathlib
# معالجة مشكلة المسارات على الأنظمة المختلفة
plt = platform.system()
pathlib.WindowsPath = pathlib.PosixPath
import requests
from fastai.vision.all import *
import PIL.Image
PIL.Image.MAX_IMAGE_PIXELS = None
from PIL import Image
import gradio as gr
# تحميل النموذج المدرب
learn = load_learner('ChestXRayfine.pkl')
# قائمة التصنيفات
categories = ('COVID19', 'Normal', 'Pneumonia', 'Turberculosis')
# دالة التصنيف
def classify_image(img):
pred, indx, probs = learn.predict(img)
return dict(zip(categories, map(float, probs)))
# إعداد واجهة Gradio بالإصدار الأحدث
with gr.Blocks() as interface:
gr.Markdown("# Chest X-Ray Classification")
gr.Markdown("Upload a chest X-ray image to classify it into one of the following categories: **COVID-19**, **Normal**, **Pneumonia**, or **Tuberculosis**.")
# إدخال الصورة
with gr.Row():
image_input = gr.Image(type="pil", label="Upload Chest X-ray Image")
# إخراج النتائج
with gr.Row():
label_output = gr.Label(label="Classification Results")
# أمثلة جاهزة
example_images = gr.Examples(
examples=['1.jpeg', '10.png', '11.png', '12.jpeg', '13.jpeg', '14.jpeg', '15.jpeg', '16.jpeg', '17.jpeg',
'18.jpeg', '19.jpeg', '2.jpeg', '20.jpeg', '21.jpg', '22.jpg', '23.jpg', '3.jpeg', '4.jpeg', '5.jpeg',
'6.png', '7.png', '8.png', '9.png'],
inputs=image_input,
)
# زر التنفيذ
predict_button = gr.Button("Classify")
# الربط بين المدخلات والمخرجات
predict_button.click(classify_image, inputs=[image_input], outputs=[label_output])
# تشغيل التطبيق
if __name__ == "__main__":
interface.launch(share=True)
|