Spaces:
Runtime error
Runtime error
| 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) | |