Diff of /src/model_interface.py [000000] .. [a72e01]

Switch to unified view

a b/src/model_interface.py
1
"""
2
Gradio related stuff
3
"""
4
from enum import Enum
5
from typing import Optional
6
7
import gradio as gr
8
from src import utils
9
10
11
class InjuryType(str, Enum):
12
    NO_INJURY = "NO_INJURY"
13
    LIVER = "LIVER"
14
    KIDNEY = "KIDNEY"
15
    SPLEEN = "SPLEEN"
16
    EXTRAVASATION = "EXTRAVASATION"
17
    BOWEL = "BOWEL"
18
19
20
INJURY_PROMPTS = {
21
    InjuryType.LIVER: "[INST] What are some first aid for liver internal injury [/INST]",
22
    InjuryType.KIDNEY: "[INST] What are some first aid for kidney internal injury [/INST]",
23
    InjuryType.SPLEEN: "[INST] What are some first aid for spleen internal injury [/INST]",
24
    InjuryType.EXTRAVASATION: "[INST] What are some first aid for extravasation internal injury [/INST]",
25
    InjuryType.BOWEL: "[INST] What are some first aid for bowel internal injury [/INST]",
26
    InjuryType.NO_INJURY: "[INST] What are some general medical fitness tips [/INST]",
27
}
28
29
30
# Define function to be executed when "Run" button is clicked
31
def interface_handler(choice: Optional[InjuryType]) -> str:
32
    if choice is None:
33
        return ""
34
    input_prompt = INJURY_PROMPTS[choice]
35
    return utils.query(inputs=input_prompt)
36
37
38
interface_description = """
39
<center>
40
<img src="/static/images/image-robot.jpg" alt="image of a robot" width="350px"/>
41
</center>
42
43
<strong>This application is based on the [RSNA 2023 Kaggle Competition](),
44
and attempts to provide first aid information to patients with abdominal injuries.</strong>
45
46
It does this by prompting the <em>[mistralai/Mistral-7B-Instruct-v0.1](https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.1)</em>
47
text generation model via the [HuggingFace Inference API](https://huggingface.co/inference-api).
48
This model is not medically accurate, and this entire application has been created for illustrative purposes.
49
Do enjoy!
50
51
"""
52
53
54
# Gradio interface configuration
55
iface = gr.Interface(
56
    fn=interface_handler,
57
    allow_flagging="never",
58
    title="Ask eMLily",
59
    description=interface_description,
60
    inputs=[
61
        gr.Radio(
62
            label="Get some first aid advice!",
63
            info="What is the patient's diagnosis?",
64
            choices=[
65
                ("Liver", InjuryType.LIVER),
66
                ("Bowel", InjuryType.BOWEL),
67
                ("Extravasation", InjuryType.EXTRAVASATION),
68
                ("Kidney", InjuryType.KIDNEY),
69
                ("Spleen", InjuryType.SPLEEN),
70
                (
71
                    "No Internal Injury. I'd just like general medical advice",
72
                    InjuryType.NO_INJURY,
73
                ),
74
            ],
75
        ),
76
    ],
77
    outputs=gr.Textbox("Model output ..."),
78
    live=True,
79
    theme="light",
80
)