File size: 4,085 Bytes
624fb6c
 
f0c9186
624fb6c
 
bb3f29c
624fb6c
f0c9186
624fb6c
c5663df
9c278e9
624fb6c
 
9c278e9
624fb6c
bb3f29c
 
624fb6c
bb3f29c
 
 
624fb6c
 
bb3f29c
624fb6c
5c27c77
bb3f29c
915ff3e
bb3f29c
 
 
 
 
624fb6c
bb3f29c
 
 
 
624fb6c
 
bb3f29c
624fb6c
bb3f29c
 
624fb6c
fa0287d
bb3f29c
 
624fb6c
 
 
 
fa0287d
624fb6c
fa0287d
bb3f29c
 
 
fa0287d
 
624fb6c
 
fa0287d
bb3f29c
fa0287d
bb3f29c
 
fa0287d
bb3f29c
624fb6c
 
fa0287d
624fb6c
fa0287d
 
 
624fb6c
bb3f29c
624fb6c
 
fa0287d
624fb6c
 
bb3f29c
 
 
fa0287d
624fb6c
 
fa0287d
bb3f29c
fa0287d
bb3f29c
 
 
 
 
 
624fb6c
 
fa0287d
bb3f29c
fa0287d
bb3f29c
 
 
 
 
 
624fb6c
 
bb3f29c
fa0287d
bb3f29c
624fb6c
fa0287d
 
 
 
 
 
 
 
 
624fb6c
fa0287d
 
624fb6c
bb3f29c
624fb6c
 
bb3f29c
624fb6c
bb3f29c
 
624fb6c
fa0287d
624fb6c
 
fa0287d
bb3f29c
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
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 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
acne_labels = {0: 'Clear', 1: 'Comedo', 2: 'Acne'}
acne_treatment = {
    0: "✨ Keep up the good work! Maintain your skincare routine.",
    1: "- Benzoyl peroxide\n- Azelaic acid\n- Salicylic acid +/- sulfur\n- Retinoids (tretinoin, isotretinoin, adapalene)\n*Consult a dermatologist if needed*",
    2: "- Benzoyl peroxide, azelaic acid, or retinoids (tretinoin/adapalene)\n- Antibiotics (clindamycin)\n- Hormonal therapy (OCPs)\n- Light/laser therapy\n*Please consult your dermatologist*"
}

# Fungsi deteksi
def detect_acne(image, threshold=0.4):
    image_resized = cv2.resize(image, (299, 299))
    input_data = preprocess_input(np.expand_dims(image_resized, axis=0))
    predictions = model.predict(input_data)
    
    max_index = np.argmax(predictions[0])
    max_prob = predictions[0][max_index]
    
    detections, treatment_suggestion = [], ""
    if max_prob > threshold:
        detections.append(acne_labels[max_index])
        treatment_suggestion = acne_treatment[max_index]
    
    return f"Detected: {detections}", treatment_suggestion


# CSS elegan & rapih
custom_css = """
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap');

body {
    background: linear-gradient(135deg, #ff7e5f, #feb47b);
    font-family: 'Poppins', sans-serif;
    color: #333;
    margin: 0;
    padding: 0;
}

/* Container utama */
.gradio-container {
    max-width: 950px !important;
    margin: auto !important;
    padding: 30px !important;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 10px 25px rgba(0,0,0,0.15);
}

/* Judul */
h1 {
    font-size: 40px !important;
    font-weight: 700 !important;
    text-align: center;
    margin-bottom: 10px !important;
    color: #222 !important;
}

/* Subjudul */
h2 {
    font-size: 22px !important;
    font-weight: 500 !important;
    margin-top: 5px;
    text-align: center;
    color: #444;
}

/* Deskripsi */
p {
    font-size: 16px;
    font-weight: 400;
    color: #555;
    text-align: center;
    margin: 8px 0;
}

/* Kotak Output */
textarea {
    background: #ffffff !important;
    color: #222 !important;
    border-radius: 10px !important;
    padding: 15px !important;
    font-size: 16px !important;
    border: 1px solid #ddd !important;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
}

/* Tombol */
.gr-button-primary {
    background: linear-gradient(to right, #ff7e5f, #feb47b) !important;
    color: white !important;
    border-radius: 8px !important;
    font-weight: 600 !important;
    font-size: 16px !important;
    padding: 10px 20px !important;
    transition: 0.3s ease-in-out;
}

.gr-button-primary:hover {
    background: linear-gradient(to right, #ff6a00, #ee0979) !important;
    transform: scale(1.05);
}

/* Tombol Clear */
.gr-button-secondary {
    background: #444 !important;
    color: #fff !important;
    border-radius: 8px !important;
    font-weight: 500 !important;
    padding: 10px 20px !important;
}
"""
   


# Interface Gradio
interface = gr.Interface(
    fn=detect_acne,
    inputs=gr.Image(type="numpy", label="📷 Upload Your Face Image"),
    outputs=[
        gr.Textbox(label="🩺 Detection Result"),
        gr.Textbox(label="💡 Treatment Suggestion")
    ],
    title="AiCNE: Smart Acne Detection",
    description=(
        "<div style='text-align: center;'>"
        "<h2>Your AI-powered assistant for acne detection</h2>"
        "<p>Upload a clear face image and get instant analysis with treatment suggestions.</p>"
        "</div>"
    ),
    css=custom_css,
)

interface.launch()