Spaces:
Runtime error
Runtime error
requirements.txt
Browse filesgradio
roboflow
Pillow
requests
app.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from google.colab import files
|
| 2 |
+
from zipfile import ZipFile
|
| 3 |
+
|
| 4 |
+
# إنشاء الملفات المطلوبة
|
| 5 |
+
app_code = """import gradio as gr
|
| 6 |
+
from roboflow import Roboflow
|
| 7 |
+
import io
|
| 8 |
+
|
| 9 |
+
print("Loading model from Roboflow...")
|
| 10 |
+
rf = Roboflow(api_key="tN8RCHc8406wlBLQoCBx")
|
| 11 |
+
project = rf.workspace("yomnasoror").project("medical-waste")
|
| 12 |
+
model = project.version(1).model
|
| 13 |
+
print("✅ Model loaded successfully!")
|
| 14 |
+
|
| 15 |
+
def predict_image(images):
|
| 16 |
+
results = []
|
| 17 |
+
for image in images:
|
| 18 |
+
img_byte_arr = io.BytesIO()
|
| 19 |
+
image.save(img_byte_arr, format='PNG')
|
| 20 |
+
img_byte_arr.seek(0)
|
| 21 |
+
result = model.predict(img_byte_arr).json()
|
| 22 |
+
pred = result["predictions"][0]
|
| 23 |
+
label = pred["class"]
|
| 24 |
+
conf = pred["confidence"]
|
| 25 |
+
results.append(f"🧠 النوع: {label} | 📊 الدقة: {conf:.2f}")
|
| 26 |
+
return results
|
| 27 |
+
|
| 28 |
+
iface = gr.Interface(
|
| 29 |
+
fn=predict_image,
|
| 30 |
+
inputs=gr.Image(type="pil", multiple=True, label="📸 ارفع صورة/صور المخلفات الطبية"),
|
| 31 |
+
outputs=gr.Textbox(label="🔍 النتائج"),
|
| 32 |
+
title="🧠 BioTrack AI - Medical Waste Classifier",
|
| 33 |
+
description="ارفع صورة أو أكثر، وسيقوم الذكاء الاصطناعي بتصنيف المخلفات الطبية 🔬"
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
iface.launch()
|
| 37 |
+
"""
|
| 38 |
+
|
| 39 |
+
requirements = """gradio
|
| 40 |
+
roboflow
|
| 41 |
+
Pillow
|
| 42 |
+
requests
|
| 43 |
+
"""
|
| 44 |
+
|
| 45 |
+
readme = """# BioTrack AI - Medical Waste Classifier
|
| 46 |
+
|
| 47 |
+
مشروع يستخدم Roboflow و Gradio لتصنيف المخلفات الطبية إلى أنواع مختلفة.
|
| 48 |
+
|
| 49 |
+
ارفع صورة أو أكثر، وسيقوم الذكاء الاصطناعي بتحديد النوع والدقة.
|
| 50 |
+
"""
|
| 51 |
+
|
| 52 |
+
# حفظ الملفات
|
| 53 |
+
with open("app.py", "w") as f:
|
| 54 |
+
f.write(app_code)
|
| 55 |
+
with open("requirements.txt", "w") as f:
|
| 56 |
+
f.write(requirements)
|
| 57 |
+
with open("README.md", "w") as f:
|
| 58 |
+
f.write(readme)
|
| 59 |
+
|
| 60 |
+
# ضغط الملفات في zip
|
| 61 |
+
zip_filename = "BioTrack_AI_Space.zip"
|
| 62 |
+
with ZipFile(zip_filename, "w") as zipf:
|
| 63 |
+
zipf.write("app.py")
|
| 64 |
+
zipf.write("requirements.txt")
|
| 65 |
+
zipf.write("README.md")
|
| 66 |
+
|
| 67 |
+
# تحميل الملف
|
| 68 |
+
files.download(zip_filename)
|