|
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 |
|
|
|
|
|
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 = { |
|
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)' |
|
} |
|
|
|
|
|
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 face: {detections}", treatment_suggestion |
|
|
|
|
|
|
|
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() |
|
|