|
|
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 |
|
|
|
|
|
|
|
|
file_id = '10LuyD0erYpFO2D4dN_BYoBQU9sblpLNL' |
|
|
gdown.download(f"https://drive.google.com/uc?export=download&id={file_id}", "Dalam_Nama_TuhanYesus.keras", quiet=False) |
|
|
|
|
|
|
|
|
model = load_model("Dalam_Nama_TuhanYesus.keras") |
|
|
|
|
|
|
|
|
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*" |
|
|
} |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
|
|
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 = 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() |
|
|
|