File size: 2,304 Bytes
d065cca
 
 
f6ad217
 
d065cca
4ca94cc
f6ad217
d065cca
4ca94cc
f6ad217
9bdf62d
 
f6ad217
9bdf62d
d065cca
 
9bdf62d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4ca94cc
9bdf62d
 
529bf7e
 
 
 
 
 
 
 
9bdf62d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d065cca
9bdf62d
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
70
71
72
73
74
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)