File size: 2,347 Bytes
0484001
 
 
af33715
 
0484001
 
 
 
 
 
 
 
 
 
 
 
 
 
 
af33715
 
0484001
 
 
af33715
0484001
af33715
0484001
af33715
0484001
 
 
 
af33715
0484001
 
 
af33715
0484001
af33715
 
 
 
 
 
 
 
0484001
 
af33715
0484001
af33715
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import gradio as gr
from PIL import Image
import torch
import base64
import io

from transformers import (
    pipeline,
    AutoModelForImageClassification,
    AutoImageProcessor
)

MODEL_ID = "cagrigungor/fire-prediction"

model = AutoModelForImageClassification.from_pretrained(MODEL_ID)
processor = AutoImageProcessor.from_pretrained(MODEL_ID)

pipe = pipeline(
    task="image-classification",
    model=model,
    image_processor=processor,
    device=-1
)

# -------------------------
# Inference
# -------------------------
def predict_from_image(image):
    if image is None:
        return None

    image = image.convert("RGB")
    results = pipe(image)

    return {r["label"]: float(r["score"]) for r in results}


# -------------------------
# Base64 (haritadan gelen)
# -------------------------
def predict_from_base64(base64_str):
    if base64_str is None:
        return None

    image_bytes = base64.b64decode(base64_str.split(",")[1])
    image = Image.open(io.BytesIO(image_bytes)).convert("RGB")
    return predict_from_image(image)


# -------------------------
# UI
# -------------------------
with gr.Blocks(title="🔥 Wildfire Detection with Map") as app:
    gr.Markdown("## 🔥 Wildfire Detection (OSM + Image Upload)")

    with gr.Tabs():
        # -------------------------
        # TAB 1: Manual Upload
        # -------------------------
        with gr.Tab("📤 Resim Yükle"):
            img_input = gr.Image(type="pil", label="Görüntü Yükle")
            btn1 = gr.Button("Tahmin Et")
            out1 = gr.Label(num_top_classes=2)

            btn1.click(
                fn=predict_from_image,
                inputs=img_input,
                outputs=out1
            )

        # -------------------------
        # TAB 2: Map
        # -------------------------
        with gr.Tab("🗺️ Harita (OSM)"):
            gr.HTML("""
            <iframe
              src="/map.html"
              style="width:100%; height:600px; border:none;">
            </iframe>
            """)

            base64_input = gr.Textbox(visible=False)
            btn2 = gr.Button("Haritadan Tahmin Et")
            out2 = gr.Label(num_top_classes=2)

            btn2.click(
                fn=predict_from_base64,
                inputs=base64_input,
                outputs=out2
            )

app.launch()