import os import cv2 import numpy as np import gradio as gr from ultralytics import YOLO # Hugging Face Spaces'te yazma hatalarını önlemek için geçici dizin ayarı os.environ['YOLO_CONFIG_DIR'] = '/tmp' # Modeli yükle try: # Boşluklara dikkat: try bloğunun altındaki satırlar içeride olmalı model = YOLO("best.pt") except Exception as e: print(f"Model yüklenirken bir hata oluştu: {e}") def predict_caries(image, conf_threshold): if image is None: return None # Tahmin (Inference) yap results = model.predict( source=image, conf=conf_threshold, iou=0.45, imgsz=640, device='cpu' ) # Sonuçları çizdir # conf=False: Karelerin üzerindeki güven skorunu (sayıları) gizler res_plotted = results[0].plot(labels=True, conf=False) # BGR'den RGB'ye dönüştür return cv2.cvtColor(res_plotted, cv2.COLOR_BGR2RGB) # Arayüz with gr.Blocks(theme=gr.themes.Default()) as demo: gr.Markdown("# 🦷 Dental Caries Detection System For Akansh Mani") gr.Markdown("Upload the X-ray image and wait for the AI ​​to analyze it.") gr.Markdown(""" ### ℹ️ Instructions: 1. **Upload** an X-ray image. 2. Click **Run AI Analysis**. 3. **Adjust Confidence Threshold:** * **Lower values (e.g. 0.15):** Higher sensitivity to catch early suspicious areas. * **Higher values (e.g. 0.45):** Only shows the most certain caries. * *Recommended value is **0.25** for a balanced result.* """) with gr.Row(): with gr.Column(): input_img = gr.Image(type="numpy", label="Upload X-Ray") conf_slider = gr.Slider( minimum=0.01, maximum=1.0, value=0.25, step=0.01, label="Confidence Threshold" ) btn = gr.Button("🔍 Run AI Analysis", variant="primary") with gr.Column(): output_img = gr.Image(type="numpy", label="Detection Result") # Buton tetikleyicisi btn.click( fn=predict_caries, inputs=[input_img, conf_slider], outputs=output_img ) # Başlatma if __name__ == "__main__": demo.launch(server_name="0.0.0.0", server_port=7860)