sametblbnn commited on
Commit
f0abc82
·
verified ·
1 Parent(s): f62cf4b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -64
app.py CHANGED
@@ -1,64 +1,64 @@
1
- import gradio as gr
2
- import os
3
- import uuid
4
- from PIL import Image
5
- import sys
6
-
7
- sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'src')))
8
- from predict import predict_image
9
-
10
- UPLOAD_DIR = os.path.join(os.path.dirname(__file__), 'uploads')
11
- os.makedirs(UPLOAD_DIR, exist_ok=True)
12
-
13
- def classify(image):
14
- path = None
15
- try:
16
- filename = f"{uuid.uuid4()}.jpg"
17
- path = os.path.join(UPLOAD_DIR, filename)
18
- image.save(path)
19
-
20
- label, confidence = predict_image(path)
21
- return f"Tahmin: {label} - Güven: {confidence:.2f}"
22
- except Exception as e:
23
- print("❌ Hata:", str(e))
24
- return f"HATA: {str(e)}"
25
- finally:
26
- if path and os.path.exists(path):
27
- os.remove(path)
28
-
29
- with gr.Blocks(css="""
30
- #main-box {
31
- max-width: 600px;
32
- margin: auto;
33
- }
34
-
35
- #submit-btn {
36
- background-color: #c2410c !important; /* turuncu */
37
- color: white !important;
38
- border-radius: 6px;
39
- }
40
-
41
- #clear-btn {
42
- background-color: #4b5563 !important; /* koyu gri */
43
- color: white !important;
44
- border-radius: 6px;
45
- }
46
- """) as demo:
47
- with gr.Column(elem_id="main-box"):
48
- gr.Markdown("## 🧠 Beyin Tümörü Tespiti\nMRI görüntüsünü yükleyin, tahmin et butonuna basın.")
49
-
50
- image_input = gr.Image(type="pil", label="MRI Görüntüsü Yükle")
51
-
52
- with gr.Row():
53
- submit_btn = gr.Button("Submit", elem_id="submit-btn")
54
- clear_btn = gr.Button("Clear", elem_id="clear-btn")
55
-
56
- result_output = gr.Textbox(label="Tahmin Sonucu")
57
-
58
- submit_btn.click(fn=classify, inputs=image_input, outputs=result_output)
59
- clear_btn.click(fn=lambda: (None, ""), outputs=[image_input, result_output])
60
-
61
- demo.launch(share=True)
62
-
63
-
64
-
 
1
+ import gradio as gr
2
+ import os
3
+ import uuid
4
+ from PIL import Image
5
+ import sys
6
+
7
+ sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'src')))
8
+ from src.predict import predict_image
9
+
10
+ UPLOAD_DIR = os.path.join(os.path.dirname(__file__), 'uploads')
11
+ os.makedirs(UPLOAD_DIR, exist_ok=True)
12
+
13
+ def classify(image):
14
+ path = None
15
+ try:
16
+ filename = f"{uuid.uuid4()}.jpg"
17
+ path = os.path.join(UPLOAD_DIR, filename)
18
+ image.save(path)
19
+
20
+ label, confidence = predict_image(path)
21
+ return f"Tahmin: {label} - Güven: {confidence:.2f}"
22
+ except Exception as e:
23
+ print("❌ Hata:", str(e))
24
+ return f"HATA: {str(e)}"
25
+ finally:
26
+ if path and os.path.exists(path):
27
+ os.remove(path)
28
+
29
+ with gr.Blocks(css="""
30
+ #main-box {
31
+ max-width: 600px;
32
+ margin: auto;
33
+ }
34
+
35
+ #submit-btn {
36
+ background-color: #c2410c !important; /* turuncu */
37
+ color: white !important;
38
+ border-radius: 6px;
39
+ }
40
+
41
+ #clear-btn {
42
+ background-color: #4b5563 !important; /* koyu gri */
43
+ color: white !important;
44
+ border-radius: 6px;
45
+ }
46
+ """) as demo:
47
+ with gr.Column(elem_id="main-box"):
48
+ gr.Markdown("## 🧠 Beyin Tümörü Tespiti\nMRI görüntüsünü yükleyin, tahmin et butonuna basın.")
49
+
50
+ image_input = gr.Image(type="pil", label="MRI Görüntüsü Yükle")
51
+
52
+ with gr.Row():
53
+ submit_btn = gr.Button("Submit", elem_id="submit-btn")
54
+ clear_btn = gr.Button("Clear", elem_id="clear-btn")
55
+
56
+ result_output = gr.Textbox(label="Tahmin Sonucu")
57
+
58
+ submit_btn.click(fn=classify, inputs=image_input, outputs=result_output)
59
+ clear_btn.click(fn=lambda: (None, ""), outputs=[image_input, result_output])
60
+
61
+ demo.launch(share=True)
62
+
63
+
64
+