Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoImageProcessor, AutoModelForImageClassification
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
# تحميل المعالج والنموذج من Hugging Face Hub
|
6 |
+
model = AutoModelForImageClassification.from_pretrained("Alhdrawi/x_alhdrawi")
|
7 |
+
processor = AutoImageProcessor.from_pretrained("Alhdrawi/x_alhdrawi")
|
8 |
+
|
9 |
+
# دالة التنبؤ
|
10 |
+
def predict(image):
|
11 |
+
inputs = processor(images=image, return_tensors="pt")
|
12 |
+
outputs = model(**inputs)
|
13 |
+
logits = outputs.logits
|
14 |
+
predicted_class_idx = logits.argmax(-1).item()
|
15 |
+
label = model.config.id2label[predicted_class_idx]
|
16 |
+
return f"🔍 Prediction: {label}"
|
17 |
+
|
18 |
+
# واجهة Gradio
|
19 |
+
iface = gr.Interface(
|
20 |
+
fn=predict,
|
21 |
+
inputs=gr.Image(type="pil", label="ارفع صورة شعاعية"),
|
22 |
+
outputs=gr.Textbox(label="النتيجة"),
|
23 |
+
title="🩻 نموذج التشخيص الشعاعي - Alhdrawi",
|
24 |
+
description="نموذج ذكاء اصطناعي لتشخيص الصور الشعاعية مثل X-ray باستخدام Transformers من Hugging Face."
|
25 |
+
)
|
26 |
+
|
27 |
+
iface.launch()
|