Julien Ajdenbaum
added default file
ed775f9
raw
history blame
2.79 kB
import gradio as gr
import math
import numpy as np
import os
import matplotlib.pyplot as plt
import random
from skimage import io as skio
def evolution_plot(current_age):
n = 10000
maxi = 100
x = np.linspace(0, maxi, 10000)
max_state = 7
final_state = 5
y = 1 / (1 + np.exp(-(x / 8) + 5))
y = (y - np.min(y)) / (np.max(y - np.min(y))) * (final_state - 1) + 1
plt.title("Hair Loss Evolution Prediction")
plt.xlabel("Age")
plt.ylabel("Nordwood State")
plt.ylim(1, max_state)
actual = np.where(x < int(current_age))[0][-1]
plt.plot(x[:actual], y[:actual])
plt.plot(x[actual:], y[actual:], '--')
im_save_path = f'tmp/{random.randint(0, 10000)}.png'
plt.savefig(im_save_path)
plt.clf()
plot = skio.imread(im_save_path)
return plot
def pad(arr):
arr = list(map(str, arr))
max_len = 0
for i in arr:
if len(i)>max_len:
max_len = len(i)
for i in range(len(arr)):
for j in range(max_len-len(arr[i])):
arr[i] = arr[i] + " "
return arr
def predict(file, age, parent, gp):
product = ['Computer', 'Monitor ', 'Laptop ', 'Printer ', 'Tablet ']
quantity = pad(np.array([320, 450, 300, 120, 280]) / 500)
min_normal = pad(np.array([250, 200, 210, 100, 250]) / 500)
max_normal = pad(np.array([400, 300, 450, 150, 300]) / 500)
txt = 'Bacteria\t\t\t\t\t\tMin\t\t\tMax\n\n'
for i in range(len(product)):
txt += product[i]
txt += "\t\t\t"
txt += quantity[i] + "\t\t" + min_normal[i] + "\t\t" + max_normal[i] + "\t"
txt += '\n'
txt = str(txt)
useful_products = ("Hydrating Shampoo : https://www.google.com\n"
"Light Hat : https://www.google.com")
return skio.imread("results.png"), 'Dermatitis\nDryness\nDandruff', evolution_plot(age), useful_products
# GUI
title = 'Hair loss prediction'
description = 'Metagenomics Scalp Analysis for Hair Loss Prediction'
# examples = [[f'examples/{name}', 3] for name in sorted(os.listdir('examples'))]
iface = gr.Interface(
fn=predict,
inputs=[
gr.File(value="tmp/metagenome.txt", type='file', label='Scalp sample'),
gr.Textbox(label='Age'),
gr.CheckboxGroup(choices=["Yes", "No", "Do not know"], label="Has the father experienced hair loss ?"),
gr.CheckboxGroup(choices=["0", "1", "2", "Do not know"], label="How many grand-parents have experienced hair loss ?")
],
outputs=[
gr.Image(label='Scalp Metagenomics Analysis Results'),
gr.Text(label='Current issues :'),
gr.Image(label='Future Evolution'),
gr.Text(label='Useful Care Products')
],
allow_flagging='never',
cache_examples=False,
title=title,
description=description
)
iface.launch()