File size: 5,542 Bytes
624fb6c
 
f0c9186
624fb6c
 
915ff3e
624fb6c
f0c9186
624fb6c
c5663df
9c278e9
624fb6c
 
9c278e9
624fb6c
 
 
7155a5f
 
 
624fb6c
 
 
7155a5f
 
 
624fb6c
 
 
 
 
5c27c77
624fb6c
 
 
 
 
915ff3e
624fb6c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import tensorflow as tf
from tensorflow.keras.models import load_model
import gradio as gr
import cv2
import numpy as np
from tensorflow.keras.applications.inception_v3 import InceptionV3, preprocess_input
import gdown

# Download model dari Google Drive
file_id = '10LuyD0erYpFO2D4dN_BYoBQU9sblpLNL'
gdown.download(f"https://drive.google.com/uc?export=download&id={file_id}", "Dalam_Nama_TuhanYesus.keras", quiet=False)

# Load model
model = load_model("Dalam_Nama_TuhanYesus.keras")

# Labels dan saran pengobatan untuk deteksi acne
acne_labels = {
    0: 'Clear',
    1: 'Comedo',
    2: 'Acne'
}

acne_treatment = {
    2: '- Topical anti-acne agents, such as benzoyl peroxide, azelaic acid, and tretinoin or adapalene gel and some antibiotics (clindamycin)\n- New bioactive proteins may also prove successful\n- Newer topical agents such as clascoterone\n- Low-dose combined oral contraceptive\n- Antiseptic or keratolytic washes containing salicylic acid\n- Light/laser therapy',
    0: 'Keep up the good work! ',
    1: '- Benzoyl peroxide\n- Azelaic acid\n- Salicylic acid +/- sulfur and resorcinol\n- Glycolic acid\n- Retinoids such as tretinoin, isotretinoin, adapalene (these require a doctors prescription)'
}

# Fungsi untuk mendeteksi acne
def detect_acne(image, threshold=0.4):
    # Resize gambar menjadi 224x224 piksel agar sesuai dengan ukuran input model
    image_resized = cv2.resize(image, (299, 299))
    
    # Proses gambar dengan preprocess_input untuk menyesuaikan format input model
    input_data = preprocess_input(np.expand_dims(image_resized, axis=0))  # Menambah dimensi untuk batch

    # Mendapatkan prediksi dari model
    predictions = model.predict(input_data)

    # Menemukan indeks kelas dengan probabilitas tertinggi
    max_index = np.argmax(predictions[0])  # Indeks dengan probabilitas tertinggi
    max_prob = predictions[0][max_index]  # Nilai probabilitas tertinggi

    # Inisialisasi variabel untuk hasil deteksi dan saran pengobatan
    detections = []  # Daftar untuk menyimpan label deteksi (misalnya 'Acne', 'Clear', 'Comedo')
    treatment_suggestion = ""  # Saran pengobatan yang sesuai

    # Jika probabilitas tertinggi lebih besar dari threshold, deteksi berhasil
    if max_prob > threshold:
        detections.append(acne_labels[max_index])  # Menambahkan label deteksi ke dalam daftar
        treatment_suggestion = acne_treatment[max_index]  # Mendapatkan saran pengobatan berdasarkan deteksi

    # Mengembalikan hasil: gambar yang sudah dianotasi, hasil deteksi, dan saran pengobatan
    return f"Detected face: {detections}", treatment_suggestion


# CSS untuk mempercantik tampilan antarmuka
custom_css = """
@import url('https://fonts.googleapis.com/css2?family=Itim&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Instrument+Sans:wght@400;700&display=swap');
body {
    background: linear-gradient(to bottom, #FFA500, #1E90FF); 
    color: #ffffff !important; 
    margin: 0;
    padding: 0;
    overflow: hidden; 
}

.gradio-container {
    max-height: 90vh; 
    overflow-y: auto; 
    background: transparent !important;
    color: #ffffff !important;
    border-radius: 12px;
    text-align: center;
    box-sizing: border-box;
    padding: 10px;
}

.gradio-container .wrap h1 {
    font-size: 100px !important; 
    font-family: 'Itim', cursive !important; 
    font-weight: bold !important;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5); 
    color: #000000 !important; 
}

h2 {
    font-size: 40px;
    font-family: 'Instrument Sans', sans-serif;
    font-weight: bold;
    color: #000000;
    text-align: center;
}

p {
    font-size: 30px;
    font-family: 'Instrument Sans', sans-serif;
    font-weight: bold;
    color: #000000;
    text-align: center;
}

.gradio-container .wrap {
    font-size: 40px !important; 
    line-height: 1.6;
    padding: 20px
}

.output-textbox textarea {
    background-color: #1e1e1e !important;
    color: #ffffff !important;
    border: 2px solid #000000; 
    font-weight: bold;
    font-size: 16px;
    padding: 10px;
    border-radius: 8px;
}

.gradio-container::-webkit-scrollbar {
    width: 12px;
}

.gradio-container::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 6px; 
}

.gradio-container::-webkit-scrollbar-thumb {
    background: #D3D3D3;
    border-radius: 6px;
    border: #555555; 
}

.gradio-container::-webkit-scrollbar-thumb:active {
    background: #555555; 
    border: #555555; 
}
"""

interface = gr.Interface(
    fn=detect_acne,
    inputs=gr.Image(type="numpy", label="Upload an image"),
    outputs=[
        gr.Textbox(label="Detection Result"),
        gr.Textbox(label="Treatment Suggestion")
    ],
    title="🌟 AiCNE 🌟",
    description=(
        "<div style='text-align: center;'>"
        "<h2>Welcome to <b>AiCNE</b>, your AI-powered assistant for acne detection!</h2>"
        "<h2>Upload a clear image of your face to analyze and classify acne types.</h2>"
        "<h2><b>Get instant results</b> and take a step closer to understanding your skin!</h2>"
        "<br>"
        "<br>"
        "<h2>What is AiCNE?</h2>"
        "<p>AiCNE is an AI-Powered Acne Detection tool, a smart solution to understand your skin condition with AI Technology.</p>"
        "<br>"
        "<h2>Why use AiCNE?</h2>"
        "<p>AiCNE detects acne within seconds with high accuracy, offering a user-friendly interface for your convenience.</p>"
        "<br>"
        "<br>"
        "</div>"
    ),
    css=custom_css,
)

interface.launch()