File size: 2,965 Bytes
95e98bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
03bdd77
 
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
import gradio as gr
from PIL import Image
from io import BytesIO
import PIL 
import numpy as np
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

def sentence_builder(age, sex, skin_type, allergies, diet, file):
    import index

    print(age, sex, skin_type, allergies, diet)

    response = index.predict(file)
    predictions = response['prediction']
    prediction = np.array(predictions)

    data = response
    data["prediction"] = prediction

    labels = ["Low", "Moderate", "Severe"]
    show_prediction = np.zeros((4, 3))


    for in_, pred in enumerate(prediction):
        show_prediction[in_] = pred

    output1 = {labels[i]: float(show_prediction[0][i]) for i in range(3)}
    output2 = {labels[i]: float(show_prediction[1][i]) for i in range(3)}
    output3 = {labels[i]: float(show_prediction[2][i]) for i in range(3)}
    output4 = {labels[i]: float(show_prediction[3][i]) for i in range(3)}

    data['age'] = age
    data['gender'] = sex
    data['skin_type'] = skin_type
    data['allergies'] = allergies
    data['diet'] = diet


    try:
        response = index.recommendation(data)
        data = response.json()
        content = data['choices'][0]['message']['content']
        return content, output1, output2, output3, output4
    except: 
        return "No recommendation found", output1, output2, output3, output4

with gr.Blocks() as demo:
    gr.Markdown("Flip text or image files using this demo.")
    with gr.Row():
        with gr.Column():
            age = gr.Number(value=20, label="Age")
            sex = gr.Radio(["Male", "Female", "Other"], label="Gender", info="Your Gender")
            skin_type = gr.CheckboxGroup(["Oily", "Dry", "Normal"], label="Skin", info="Skin Type")
            allergy = gr.Dropdown(
                ["benzoyl peroxide", "salicylic acid", "Sun-exposure", "Itching", "Swelling", "Redness"],
                multiselect=True, label="Allergies", 
                info="Tell us your allergies and symptoms"
            )
            diet = gr.CheckboxGroup(["Veg", "Non-Veg",], label="Diet", info="Select your diet preference")
            img = gr.Image(source="upload", type="pil", label="Face Image (with open eye)")
            submit = gr.Button("Submit")
            
        with gr.Tab("Model:Severity Prediction"):
            chin = gr.Label(num_top_classes=3, label="Chin|Acne Level")
            fh = gr.Label(num_top_classes=3, label="Fore Head|Acne Level")
            lc = gr.Label(num_top_classes=3, label="Left Cheek|Acne Level")
            rc = gr.Label(num_top_classes=3, label="Right Cheek|Acne Level")
        with gr.Tab("Recommendation:Treatment Plan"):
            html_output = gr.HTML('Recommendation will be shown here')

    submit.click(sentence_builder, inputs=[age, sex, skin_type, allergy, diet, img], outputs=[html_output, rc, lc, chin, fh])

if __name__ == "__main__":
    demo.launch(server_name="0.0.0.0", server_port=7860)