alibidaran commited on
Commit
1522ef4
1 Parent(s): 439a4ca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -7
app.py CHANGED
@@ -1,6 +1,8 @@
1
  import gradio as gr
2
- from transformers import pipeline
3
- pipe=pipeline('sentiment-analysis','alibidaran/Symptom2disease')
 
 
4
  label_2id={'Psoriasis': 0,
5
  'Varicose Veins': 1,
6
  'Typhoid': 2,
@@ -25,11 +27,16 @@ label_2id={'Psoriasis': 0,
25
  'drug reaction': 21,
26
  'peptic ulcer disease': 22,
27
  'diabetes': 23}
28
- id2_label={f'LABEL_{i}':v for v,i in label_2id.items()}
29
  def detect_symptom(symptoms):
30
- output=pipe(symptoms)[0]
31
- label=id2_label[output['label']]
32
- return f"You have {label} disease."
 
 
33
 
34
- demo=gr.Interface(fn=detect_symptom,inputs='text',outputs='label')
 
 
 
 
35
  demo.launch()
 
1
  import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
+ import torch
4
+ tokenizer = AutoTokenizer.from_pretrained("alibidaran/Symptom2disease")
5
+ model = AutoModelForSequenceClassification.from_pretrained("alibidaran/Symptom2disease")
6
  label_2id={'Psoriasis': 0,
7
  'Varicose Veins': 1,
8
  'Typhoid': 2,
 
27
  'drug reaction': 21,
28
  'peptic ulcer disease': 22,
29
  'diabetes': 23}
 
30
  def detect_symptom(symptoms):
31
+ inputs_id=tokenizer(symptoms,padding=True,truncation=True,return_tensors="pt")
32
+ output=model(inputs_id['input_ids'])
33
+ preds=torch.nn.functional.softmax(output.logits,-1).topk(5)
34
+ results={id2_label[preds.indices[0][i].item()]:preds.values[0][i].item() for i in range(5)}
35
+ return results
36
 
37
+ demo=gr.Interface(fn=detect_symptom,inputs='text',outputs=gr.Label(num_top_classes=5),
38
+ examples=["I can't stop sneezing and I feel really tired and crummy. My throat is really sore",
39
+ "I have been experiencing a severe headache that is accompanied by pain behind my eyes.",
40
+ "There are small red spots all over my body that I can't explain. It's worrying me.",
41
+ "I've been having a really hard time going to the bathroom lately. It's really painful"])
42
  demo.launch()