GulAk8902 commited on
Commit
a3ab012
·
verified ·
1 Parent(s): 41db0a9

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +157 -0
app.py ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ from PIL import Image
4
+ import torch
5
+ import torch.nn.functional as F
6
+
7
+ # Temporary placeholder function - replace with your actual model later
8
+ def predict_skin_lesion(image):
9
+ """
10
+ Placeholder prediction function
11
+ Replace this with your actual ResNet50 model inference
12
+ """
13
+
14
+ # Skin lesion classes
15
+ classes = [
16
+ "Actinic Keratoses",
17
+ "Basal Cell Carcinoma",
18
+ "Benign Keratosis-like Lesions",
19
+ "Dermatofibroma",
20
+ "Melanocytic Nevi (Normal)",
21
+ "Melanoma",
22
+ "Vascular Lesions"
23
+ ]
24
+
25
+ # Placeholder prediction (random for now)
26
+ # TODO: Replace with actual model.predict(image)
27
+ confidence_scores = np.random.dirichlet(np.ones(len(classes)), size=1)[0]
28
+
29
+ # Get top prediction
30
+ top_prediction_idx = np.argmax(confidence_scores)
31
+ top_class = classes[top_prediction_idx]
32
+ top_confidence = float(confidence_scores[top_prediction_idx])
33
+
34
+ # Create confidence dictionary for gradio
35
+ predictions = {classes[i]: float(confidence_scores[i]) for i in range(len(classes))}
36
+
37
+ # Risk assessment based on prediction
38
+ if top_class in ["Melanoma", "Basal Cell Carcinoma"] and top_confidence > 0.6:
39
+ risk_level = "⚠️ YÜKSEK RİSK - Dermatolog konsültasyonu önerilir"
40
+ risk_color = "#FF6B6B"
41
+ elif top_confidence > 0.4:
42
+ risk_level = "⚡ ORTA RİSK - Takip önerilir"
43
+ risk_color = "#FFE66D"
44
+ else:
45
+ risk_level = "✅ DÜŞÜK RİSK - Rutin kontrol"
46
+ risk_color = "#4ECDC4"
47
+
48
+ return predictions, f"<div style='padding: 10px; background-color: {risk_color}; border-radius: 5px; color: white; font-weight: bold;'>{risk_level}</div>"
49
+
50
+ # Custom CSS for better UI
51
+ css = """
52
+ .gradio-container {
53
+ max-width: 900px;
54
+ margin: 0 auto;
55
+ }
56
+
57
+ .title {
58
+ text-align: center;
59
+ color: #2E86AB;
60
+ margin-bottom: 20px;
61
+ }
62
+
63
+ .description {
64
+ text-align: center;
65
+ color: #666;
66
+ margin-bottom: 30px;
67
+ }
68
+
69
+ .risk-box {
70
+ margin-top: 15px;
71
+ text-align: center;
72
+ }
73
+ """
74
+
75
+ # Create Gradio interface
76
+ with gr.Blocks(css=css, title="Cilt Lezyonu AI Analizi") as demo:
77
+
78
+ # Header
79
+ gr.Markdown(
80
+ """
81
+ # 🔬 Cilt Lezyonu AI Analizi
82
+ ### Yapay zeka destekli cilt kanseri erken teşhis sistemi
83
+
84
+ **Nasıl kullanılır:**
85
+ 1. Cilt lezyonu fotoğrafını yükleyin
86
+ 2. AI analizi bekleyin (30 saniye)
87
+ 3. Sonuçları değerlendirin
88
+ 4. Gerekirse uzman hekime başvurun
89
+
90
+ ⚠️ **Uyarı:** Bu sistem sadece ön değerlendirme amaçlıdır. Kesin tanı için mutlaka doktora başvurun.
91
+ """,
92
+ elem_classes=["description"]
93
+ )
94
+
95
+ with gr.Row():
96
+ with gr.Column(scale=1):
97
+ # Input
98
+ input_image = gr.Image(
99
+ label="📸 Cilt Lezyonu Fotoğrafı",
100
+ type="pil",
101
+ elem_id="input-image"
102
+ )
103
+
104
+ # Analyze button
105
+ analyze_btn = gr.Button(
106
+ "🔍 Analiz Et",
107
+ variant="primary",
108
+ size="lg"
109
+ )
110
+
111
+ with gr.Column(scale=1):
112
+ # Outputs
113
+ prediction_output = gr.Label(
114
+ label="📊 AI Tahmin Sonuçları",
115
+ num_top_classes=7
116
+ )
117
+
118
+ risk_output = gr.HTML(
119
+ label="⚠️ Risk Değerlendirmesi"
120
+ )
121
+
122
+ # Examples section
123
+ gr.Markdown("### 📋 Örnek Görüntüler (Test için)")
124
+ gr.Examples(
125
+ examples=[
126
+ # Add example image paths here later
127
+ # ["example_melanoma.jpg"],
128
+ # ["example_nevus.jpg"],
129
+ ],
130
+ inputs=input_image,
131
+ label="Örnek görüntülere tıklayın"
132
+ )
133
+
134
+ # Footer
135
+ gr.Markdown(
136
+ """
137
+ ---
138
+ **Geliştiren:** AI Healthcare Team | **Teknoloji:** ResNet50 + Transfer Learning | **Dataset:** HAM10000
139
+
140
+ 📞 **Acil Durum:** 112 | 🏥 **Dermatoloji Kliniği:** [Randevu Al](https://www.turkiye.gov.tr)
141
+ """
142
+ )
143
+
144
+ # Set up the interface interaction
145
+ analyze_btn.click(
146
+ fn=predict_skin_lesion,
147
+ inputs=input_image,
148
+ outputs=[prediction_output, risk_output]
149
+ )
150
+
151
+ # Launch the app
152
+ if __name__ == "__main__":
153
+ demo.launch(
154
+ share=True,
155
+ server_name="0.0.0.0",
156
+ server_port=7860
157
+ )