Spaces:
Sleeping
Sleeping
| # -*- coding: utf-8 -*- | |
| import gradio as gr | |
| from transformers import pipeline | |
| # تحميل النموذج من Hugging Face | |
| classifier = pipeline( | |
| task="image-classification", | |
| model="dqnguyen/Diabetic_Foot_Ulcer_Image_Classification" | |
| ) | |
| # دالة التنبؤ | |
| def predict(image): | |
| predictions = classifier(image) | |
| results = {} | |
| # ترجمة النتائج | |
| for p in predictions: | |
| if p["label"] == "MoHat": | |
| results["أنسجة حبيبية (Granulation)"] = round(p["score"], 3) | |
| elif p["label"] == "MoGiaMacNhiemKhuan": | |
| results["أنسجة مصابة بعدوى (غشاء كاذب)"] = round(p["score"], 3) | |
| elif p["label"] == "MoHoaiTu": | |
| results["أنسجة ميتة (نخر)"] = round(p["score"], 3) | |
| # مقياس الخطورة | |
| if not results: | |
| risk_text = "لم يتم التعرف على النسيج" | |
| risk_level = "❔ غير محدد" | |
| color = "#888888" | |
| else: | |
| top_label = max(results, key=results.get) | |
| if "نخر" in top_label: | |
| risk_text = "⚠️ الحالة حرجة، يُنصح بمراجعة الطبيب فورًا" | |
| risk_level = "🔴 عالية الخطورة" | |
| color = "#FF6B6B" | |
| elif "عدوى" in top_label: | |
| risk_text = "⚠️ حالة متوسطة، تحتاج متابعة وعناية طبية" | |
| risk_level = "🟠 متوسطة الخطورة" | |
| color = "#FFD166" | |
| else: | |
| risk_text = "✅ القدم في حالة التئام جيدة" | |
| risk_level = "🟢 منخفضة الخطورة" | |
| color = "#8EF58E" | |
| return ( | |
| results, | |
| f""" | |
| <div class='dynamic-text' style='text-align:right; color:{color}; font-size:18px;'> | |
| <b>{risk_level}</b> | |
| </div> | |
| <p class='dynamic-text' style='text-align:right; font-size:16px;'>{risk_text}</p> | |
| """ | |
| ) | |
| custom_theme = gr.themes.Soft( | |
| primary_hue="green", | |
| secondary_hue="gray", | |
| neutral_hue="slate" | |
| ).set( | |
| button_primary_background_fill="#4CAF50", | |
| button_primary_background_fill_hover="#43A047", | |
| button_primary_text_color="#FFFFFF", | |
| ) | |
| # واجهة Gradio | |
| with gr.Blocks(theme=custom_theme, title="تصنيف تقرحات القدم السكرية") as demo: | |
| gr.HTML(""" | |
| <style> | |
| body { | |
| background-color: var(--background-fill-primary); | |
| } | |
| .dynamic-text { | |
| color: #333333; /* الوضع الفاتح */ | |
| } | |
| @media (prefers-color-scheme: dark) { | |
| .dynamic-text { | |
| color: #FFFFFF; /* الوضع الداكن */ | |
| } | |
| } | |
| </style> | |
| <div style='text-align:right;' class='dynamic-text'> | |
| <p style='font-size:16px;'> | |
| يقوم هذا النظام بتحليل صورة القدم لتحديد نوع الأنسجة ومستوى الخطورة المحتمل. | |
| <br> نسيج حبيبي (يدل على التئام جيد) | |
| <br> نسيج مصاب بعدوى (غشاء كاذب) | |
| <br> نسيج ميت (نخر) | |
| </p> | |
| </div> | |
| """) | |
| with gr.Row(): | |
| with gr.Column(scale=1): | |
| image_input = gr.Image(label="📷 ارفع صورة القدم", type="filepath") | |
| analyze_btn = gr.Button("🔍 تحليل الصورة", variant="primary") | |
| with gr.Column(scale=1): | |
| result_output = gr.Label(label="نتائج التحليل", num_top_classes=3) | |
| risk_output = gr.HTML(label="مقياس الخطورة") | |
| analyze_btn.click(fn=predict, inputs=image_input, outputs=[result_output, risk_output]) | |
| # زر الحجز للحالات الحرجة فقط | |
| gr.HTML(""" | |
| <div id='appointment' style='display:none; text-align:right; margin-top:20px;'> | |
| <a href='https://your-medical-app.com/book' target='_blank'> | |
| <button style='background-color:#4CAF50; color:white; padding:10px 20px; border:none; border-radius:10px; font-size:16px; cursor:pointer;'> | |
| حجز موعد مع الطبيب | |
| </button> | |
| </a> | |
| </div> | |
| <script> | |
| const observer = new MutationObserver(() => { | |
| const text = document.body.innerText || ""; | |
| if (text.includes("حرجة")) { | |
| document.getElementById("appointment").style.display = "block"; | |
| } else { | |
| document.getElementById("appointment").style.display = "none"; | |
| } | |
| }); | |
| observer.observe(document.body, { childList: true, subtree: true }); | |
| </script> | |
| """) | |
| if __name__ == "__main__": | |
| demo.launch() | |