Spaces:
				
			
			
	
			
			
		Runtime error
		
	
	
	
			
			
	
	
	
	
		
		
		Runtime error
		
	File size: 3,081 Bytes
			
			| a1c3c86 4e92983 a1c3c86 1471ce5 f233d16 1471ce5 4e92983 a1c3c86 08b7f00 15d8981 1471ce5 a1c3c86 ed775f9 a1c3c86 4e92983 a1c3c86 1471ce5 a1c3c86 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | 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, shampoo):
    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)
    variants = ["Y2TTB9", "9KKGH7", "ML0JH9"]
    risks = ['Seborrheic eczema', 'Folliculitis', "Pityriasis amiantacea"]
    percents = ['30', "21", '9']
    geneticRisks = ""
    for variant, risk, percent in zip(variants, risks, percents):
        geneticRisks += f"Variant {variant} detected, risk of {risk} is {percent}% higher.\n"
    useful_products = ("Hydrating Shampoo : https://www.thisisthebestshampooforyou.fr/fr-fr/\n"
                       "Light Hat : https://www.amazon.com/light-therapy-hat/s?k=light+therapy+hat")
    return skio.imread("results.png"), 'Dermatitis\nDryness\nDandruff', geneticRisks, 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 ?"),
        gr.Textbox(label='How many times a week do you wash your hair ?'),
    ],
    outputs=[
        gr.Image(label='Scalp Metagenomics Analysis Results'),
        gr.Text(label='Current issues :'),
        gr.Text(label='Genetic Risks :'),
        gr.Image(label='Future Evolution'),
        gr.Text(label='Useful Care Products')
    ],
    allow_flagging='never',
    cache_examples=False,
    title=title,
    description=description
)
iface.launch()
 |