Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,30 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import pandas as pd
|
| 3 |
import cv2
|
| 4 |
import numpy as np
|
|
|
|
| 5 |
from sklearn.ensemble import RandomForestClassifier
|
| 6 |
from sklearn.preprocessing import LabelEncoder
|
| 7 |
|
| 8 |
-
# Load dataset
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
# Gradio interface
|
| 14 |
iface = gr.Interface(
|
| 15 |
-
fn=
|
| 16 |
-
inputs=gr.
|
| 17 |
-
outputs=
|
| 18 |
-
title="Skin Tone
|
| 19 |
)
|
| 20 |
|
| 21 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import cv2
|
| 3 |
import numpy as np
|
| 4 |
+
import pandas as pd
|
| 5 |
from sklearn.ensemble import RandomForestClassifier
|
| 6 |
from sklearn.preprocessing import LabelEncoder
|
| 7 |
|
| 8 |
+
# Load dataset and train model
|
| 9 |
+
df = pd.read_excel("your_dataset.xlsx")
|
| 10 |
+
le = LabelEncoder()
|
| 11 |
+
df["skin_tone"] = le.fit_transform(df["skin_tone"])
|
| 12 |
+
|
| 13 |
+
X_train, X_test, y_train, y_test = train_test_split(df["image"], df["skin_tone"], test_size=0.2, random_state=42)
|
| 14 |
+
model = RandomForestClassifier(n_estimators=100)
|
| 15 |
+
model.fit(X_train, y_train)
|
| 16 |
+
|
| 17 |
+
# Define Gradio function
|
| 18 |
+
def predict_skin_tone(image):
|
| 19 |
+
img_resized = cv2.resize(image, (100, 100)).flatten().reshape(1, -1)
|
| 20 |
+
prediction = model.predict(img_resized)
|
| 21 |
+
return le.inverse_transform(prediction)[0]
|
| 22 |
|
|
|
|
| 23 |
iface = gr.Interface(
|
| 24 |
+
fn=predict_skin_tone,
|
| 25 |
+
inputs=gr.Image(type="numpy", label="Upload Image"),
|
| 26 |
+
outputs="text",
|
| 27 |
+
title="Skin Tone Prediction"
|
| 28 |
)
|
| 29 |
|
| 30 |
iface.launch()
|