REALME5-pro commited on
Commit
cc60d4f
·
verified ·
1 Parent(s): 5ca112c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -58
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
- # Load the medical model
7
- medical_learn = load_learner('model.pkl')
8
-
9
- # Medical model configuration
10
- medical_description = "Medical Diagnosis"
11
- medical_categories = ['Allergy', 'Anemia', 'Bronchitis', 'Diabetes', 'Diarrhea', 'Fatigue', 'Flu', 'Malaria', 'Stress']
12
-
13
- def classify_medical_text(txt):
14
- pred, idx, probs = medical_learn.predict(txt)
15
- return dict(zip(medical_categories, map(float, probs)))
16
-
17
- # Load the psychiatric model from Hugging Face
18
- psychiatric_model_name = "mental/mental-bert-base-uncased" # Replace with the appropriate model
19
- psychiatric_tokenizer = AutoTokenizer.from_pretrained(psychiatric_model_name)
20
- psychiatric_model = AutoModelForSequenceClassification.from_pretrained(psychiatric_model_name)
21
-
22
- # Psychiatric model configuration
23
- psychiatric_description = "Psychiatric Analysis"
24
- psychiatric_labels = ['Depression', 'Anxiety', 'Bipolar Disorder', 'PTSD', 'OCD', 'Stress', 'Schizophrenia'] # Adjust based on the model
25
-
26
- def classify_psychiatric_text(txt):
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)