DEV Community

Andres Ortiz
Andres Ortiz

Posted on • Edited on

Can an AI detect what your skin needs? Create a model in 30 minutes

Wow, seriously? I once stared at my bathroom mirror, wondering if my skin was dehydrated or just angry—right?—until I thought, “Why not let AI decide?”

I tried browsing beauty blogs and guessing products by trial and error [sic], and ended up with a cabinet full of half‑used creams. Then I realized: with a quick model, Python can analyze basic skin data and tell you exactly what your skin craves—no more guesswork.

Botox Avondale in Chicago Il


5 Key Concepts (Casual List)

  1. Data collection: simple surveys and selfies
  2. Preprocessing: clean and normalize inputs
  3. Model architecture: lightweight neural nets
  4. Inference: real‑time recommendations
  5. Deployment: wrap in a Flask app

How to Build Your Skin AI (Step by Step)

1. Install Dependencies

Grab your libraries.

pip install tensorflow pandas flask opencv-python
Enter fullscreen mode Exit fullscreen mode

2. Collect Sample Data

Create a CSV with columns: oiliness, dryness, sensitivity, pimples, skin_tone.

import pandas as pd

data = pd.DataFrame([
    {'oiliness':3, 'dryness':1, 'sensitivity':2, 'pimples':0, 'tone':'fair', 'label':'hydration'},
    # ... add more rows ...
])
data.to_csv('skin_data.csv', index=False)
Enter fullscreen mode Exit fullscreen mode

3. Preprocess Inputs

Normalize numeric features, encode tone.

from sklearn.preprocessing import StandardScaler, OneHotEncoder
import pandas as pd
import numpy as np

df = pd.read_csv('skin_data.csv')
scaler = StandardScaler()
X_num = scaler.fit_transform(df[['oiliness','dryness','sensitivity','pimples']])

encoder = OneHotEncoder(sparse=False)
X_tone = encoder.fit_transform(df[['tone']])

X = np.concatenate([X_num, X_tone], axis=1)
y = df['label']
Enter fullscreen mode Exit fullscreen mode

4. Define a Simple Neural Net

A tiny model for fast training.

import tensorflow as tf

model = tf.keras.Sequential([
    tf.keras.layers.Dense(16, activation='relu', input_shape=(X.shape[1],)),
    tf.keras.layers.Dense(8, activation='relu'),
    tf.keras.layers.Dense(len(y.unique()), activation='softmax')
])
Enter fullscreen mode Exit fullscreen mode

5. Compile & Train

Train in minutes—seriously under 30.

model.compile(optimizer='adam',
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])
model.fit(X, y, epochs=10, validation_split=0.2)
Enter fullscreen mode Exit fullscreen mode

6. Evaluate Your Model

Check performance quickly.

loss, acc = model.evaluate(X, y)
print(f"Accuracy: {acc*100:.1f}%")
Enter fullscreen mode Exit fullscreen mode

7. Save the Model

Reuse without retraining.

model.save('skin_needs_model.h5')
Enter fullscreen mode Exit fullscreen mode

8. Build a Flask API

Serve recommendations.

from flask import Flask, request, jsonify
import tensorflow as tf

app = Flask(__name__)
model = tf.keras.models.load_model('skin_needs_model.h5')

@app.route('/recommend', methods=['POST'])
def recommend():
    features = request.json['features']
    pred = model.predict([features])
    labels = ['hydration','oil_control','sensitive_care']
    return jsonify({'recommendation': labels[pred.argmax()]})
Enter fullscreen mode Exit fullscreen mode

9. Quick Front‑End Snippet

Test via JavaScript fetch().

fetch('/recommend', {
  method: 'POST',
  headers: {'Content-Type':'application/json'},
  body: JSON.stringify({features: [2,1,3,0,0]})
})
.then(r => r.json())
.then(data => alert(`Try: ${data.recommendation}`));
Enter fullscreen mode Exit fullscreen mode

10. Enhance with Selfie Input (Bonus)

Capture a basic image for future expansion.

import cv2
img = cv2.imread('selfie.jpg')
resized = cv2.resize(img, (128,128))
# feed to a CNN later
Enter fullscreen mode Exit fullscreen mode

Benefits (Casual Bullets)

  • No more guesswork: tailored suggestions, wow.
  • Fast MVP: build in half an hour, you know?
  • Scalable: add more features—UV index, humidity, right?
  • DIY‑friendly: you don’t need a data science team.
  • Shop smarter: skip unnecessary visits to Botox in Avondale opt for home remedies or pro treatments like Facials Avondale or advanced Microneedling in Avondale

Conclusion + Call to Action

Give it a try this week—you’ll see how AI can demystify skincare. Fork the repo, train on your own profiles, and share your results in the comments—can’t wait to see your editions!

Top comments (0)