Spaces:
Runtime error
Runtime error
File size: 2,084 Bytes
843f5be | 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 57 58 59 60 61 62 63 64 65 66 67 68 69 | from google.colab import files
from zipfile import ZipFile
# إنشاء الملفات المطلوبة
app_code = """import gradio as gr
from roboflow import Roboflow
import io
print("Loading model from Roboflow...")
rf = Roboflow(api_key="tN8RCHc8406wlBLQoCBx")
project = rf.workspace("yomnasoror").project("medical-waste")
model = project.version(1).model
print("✅ Model loaded successfully!")
def predict_image(images):
results = []
for image in images:
img_byte_arr = io.BytesIO()
image.save(img_byte_arr, format='PNG')
img_byte_arr.seek(0)
result = model.predict(img_byte_arr).json()
pred = result["predictions"][0]
label = pred["class"]
conf = pred["confidence"]
results.append(f"🧠 النوع: {label} | 📊 الدقة: {conf:.2f}")
return results
iface = gr.Interface(
fn=predict_image,
inputs=gr.Image(type="pil", multiple=True, label="📸 ارفع صورة/صور المخلفات الطبية"),
outputs=gr.Textbox(label="🔍 النتائج"),
title="🧠 BioTrack AI - Medical Waste Classifier",
description="ارفع صورة أو أكثر، وسيقوم الذكاء الاصطناعي بتصنيف المخلفات الطبية 🔬"
)
iface.launch()
"""
requirements = """gradio
roboflow
Pillow
requests
"""
readme = """# BioTrack AI - Medical Waste Classifier
مشروع يستخدم Roboflow و Gradio لتصنيف المخلفات الطبية إلى أنواع مختلفة.
ارفع صورة أو أكثر، وسيقوم الذكاء الاصطناعي بتحديد النوع والدقة.
"""
# حفظ الملفات
with open("app.py", "w") as f:
f.write(app_code)
with open("requirements.txt", "w") as f:
f.write(requirements)
with open("README.md", "w") as f:
f.write(readme)
# ضغط الملفات في zip
zip_filename = "BioTrack_AI_Space.zip"
with ZipFile(zip_filename, "w") as zipf:
zipf.write("app.py")
zipf.write("requirements.txt")
zipf.write("README.md")
# تحميل الملف
files.download(zip_filename)
|