Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,61 +1,24 @@
|
|
1 |
from fastai.text.all import *
|
2 |
-
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
3 |
-
import torch
|
4 |
import gradio as gr
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
inputs = psychiatric_tokenizer(txt, return_tensors="pt", truncation=True, padding=True)
|
28 |
-
with torch.no_grad():
|
29 |
-
outputs = psychiatric_model(**inputs)
|
30 |
-
logits = outputs.logits
|
31 |
-
probabilities = torch.softmax(logits, dim=1).squeeze().tolist()
|
32 |
-
return dict(zip(psychiatric_labels, probabilities))
|
33 |
-
|
34 |
-
# Gradio Interfaces
|
35 |
-
medical_text = gr.Textbox(lines=2, label='Describe your symptoms in detail')
|
36 |
-
medical_label = gr.Label()
|
37 |
-
medical_examples = ['I feel short of breath and have a high fever.', 'My throat hurts and I keep sneezing.', 'I am always thirsty.']
|
38 |
-
|
39 |
-
psychiatric_text = gr.Textbox(lines=2, label='Describe your mental health concerns in detail')
|
40 |
-
psychiatric_label = gr.Label()
|
41 |
-
psychiatric_examples = ['I feel hopeless and have no energy.', 'I am unable to concentrate and feel anxious all the time.', 'I have recurring intrusive thoughts.']
|
42 |
-
|
43 |
-
medical_interface = gr.Interface(
|
44 |
-
fn=classify_medical_text,
|
45 |
-
inputs=medical_text,
|
46 |
-
outputs=medical_label,
|
47 |
-
examples=medical_examples,
|
48 |
-
description=medical_description,
|
49 |
-
)
|
50 |
-
|
51 |
-
psychiatric_interface = gr.Interface(
|
52 |
-
fn=classify_psychiatric_text,
|
53 |
-
inputs=psychiatric_text,
|
54 |
-
outputs=psychiatric_label,
|
55 |
-
examples=psychiatric_examples,
|
56 |
-
description=psychiatric_description,
|
57 |
-
)
|
58 |
-
|
59 |
-
# Combine interfaces using Tabs
|
60 |
-
app = gr.TabbedInterface([medical_interface, psychiatric_interface], ["Medical Diagnosis", "Psychiatric Analysis"])
|
61 |
-
app.launch(inline=False)
|
|
|
1 |
from fastai.text.all import *
|
|
|
|
|
2 |
import gradio as gr
|
3 |
|
4 |
+
|
5 |
+
learn = load_learner('model.pkl')
|
6 |
+
|
7 |
+
|
8 |
+
description = "Medical Diagnosis"
|
9 |
+
categories = (['Allergy', 'Anemia', 'Bronchitis', 'Diabetes', 'Diarrhea', 'Fatigue', 'Flu', 'Malaria', 'Stress'])
|
10 |
+
|
11 |
+
|
12 |
+
|
13 |
+
def classify_text(txt):
|
14 |
+
pred,idx,probs = learn.predict(txt)
|
15 |
+
return dict(zip(categories, map(float,probs)))
|
16 |
+
|
17 |
+
|
18 |
+
|
19 |
+
text = gr.Textbox(lines=2, label='Describe how you feel in great detail')
|
20 |
+
label = gr.Label()
|
21 |
+
examples = ['I have no intrest in physical activity. i am always thirsty', 'I am freezing', 'My eyes are pale']
|
22 |
+
|
23 |
+
intf = gr.Interface(fn=classify_text, inputs=text, outputs=label, examples=examples, description=description)
|
24 |
+
intf.launch(inline=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|