Commit
·
f59b209
1
Parent(s):
ff61aff
added products
Browse files- app.py +34 -8
- recommendation.xlsx +0 -0
app.py
CHANGED
|
@@ -2,22 +2,48 @@ import gradio as gr
|
|
| 2 |
from fastai.vision.all import *
|
| 3 |
import skimage
|
| 4 |
import pathlib
|
|
|
|
| 5 |
|
| 6 |
plt = platform.system()
|
| 7 |
if plt == 'Linux': pathlib.WindowsPath = pathlib.PosixPath
|
| 8 |
|
| 9 |
-
learn = load_learner('export.pkl')
|
| 10 |
|
| 11 |
-
labels = learn.dls.vocab
|
| 12 |
-
def predict(img):
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
|
| 17 |
title = "Face condition Analyzer"
|
| 18 |
description = "A face condition detector trained on the custom dataset with fastai. Created using Gradio and HuggingFace Spaces."
|
| 19 |
examples = [['harmonal_acne.jpg'],['forehead_wrinkles.jpg'],['oily_skin.jpg']]
|
| 20 |
enable_queue=True
|
| 21 |
|
| 22 |
-
gr.Interface(fn=predict,inputs=gr.inputs.Image(shape=(512, 512)),outputs=gr.outputs.Label(num_top_classes=3),title=title,
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
from fastai.vision.all import *
|
| 3 |
import skimage
|
| 4 |
import pathlib
|
| 5 |
+
import pandas as pd
|
| 6 |
|
| 7 |
plt = platform.system()
|
| 8 |
if plt == 'Linux': pathlib.WindowsPath = pathlib.PosixPath
|
| 9 |
|
| 10 |
+
# learn = load_learner('export.pkl')
|
| 11 |
|
| 12 |
+
# labels = learn.dls.vocab
|
| 13 |
+
# def predict(img):
|
| 14 |
+
# img = PILImage.create(img)
|
| 15 |
+
# pred,pred_idx,probs = learn.predict(img)
|
| 16 |
+
# return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 17 |
|
| 18 |
title = "Face condition Analyzer"
|
| 19 |
description = "A face condition detector trained on the custom dataset with fastai. Created using Gradio and HuggingFace Spaces."
|
| 20 |
examples = [['harmonal_acne.jpg'],['forehead_wrinkles.jpg'],['oily_skin.jpg']]
|
| 21 |
enable_queue=True
|
| 22 |
|
| 23 |
+
# gr.Interface(fn=predict,inputs=gr.inputs.Image(shape=(512, 512)),outputs=gr.outputs.Label(num_top_classes=3),title=title,
|
| 24 |
+
# description=description,examples=examples,enable_queue=enable_queue).launch()
|
| 25 |
+
with gr.Blocks(title=title,description=description,examples=examples,enable_queue=enable_queue) as demo:
|
| 26 |
+
learn = load_learner('export.pkl')
|
| 27 |
+
labels = learn.dls.vocab
|
| 28 |
+
def predict(img):
|
| 29 |
+
img = PILImage.create(img)
|
| 30 |
+
pred,pred_idx,probs = learn.predict(img)
|
| 31 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 32 |
+
gr.Markdown("# Face Skin Analyzer")
|
| 33 |
+
gr.Markdown("A face condition detector trained on the custom dataset with fastai. Created using Gradio and HuggingFace Spaces. Kindly upload a photo of your face.")
|
| 34 |
+
with gr.Row():
|
| 35 |
+
inputs = gr.inputs.Image(shape=(512, 512))
|
| 36 |
+
outputs = gr.outputs.Label(num_top_classes=3)
|
| 37 |
+
btn = gr.Button("Predict")
|
| 38 |
+
btn.click(fn=predict, inputs=inputs, outputs=outputs)
|
| 39 |
+
|
| 40 |
+
df=pd.read_excel("recommendation.xlsx")
|
| 41 |
+
classes = df['class'].unique()
|
| 42 |
+
with gr.Accordion("Find your skin condition using above analyzer and see the Recommended solutions",open=False):
|
| 43 |
+
for c in classes:
|
| 44 |
+
with gr.Accordion(c,open=False):
|
| 45 |
+
df_temp = df[df['class']==c]
|
| 46 |
+
for i,current_row in df_temp.iterrows():
|
| 47 |
+
html_box = gr.HTML("<span><a href='{}'><img src ='{}'></a></span>".format(current_row['profit_link'],current_row['product_image']))
|
| 48 |
+
|
| 49 |
+
demo.launch()
|
recommendation.xlsx
ADDED
|
Binary file (10.1 kB). View file
|
|
|