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=( "
" "

Welcome to AiCNE, your AI-powered assistant for acne detection!

" "

Upload a clear image of your face to analyze and classify acne types.

" "

Get instant results and take a step closer to understanding your skin!

" "
" "
" "

What is AiCNE?

" "

AiCNE is an AI-Powered Acne Detection tool, a smart solution to understand your skin condition with AI Technology.

" "
" "

Why use AiCNE?

" "

AiCNE detects acne within seconds with high accuracy, offering a user-friendly interface for your convenience.

" "
" "
" "
" ), css=custom_css, ) interface.launch()