pr0mila commited on
Commit
ac54d64
1 Parent(s): f7c3475

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +78 -2
app.py CHANGED
@@ -43,6 +43,82 @@ def abstractive_text(text):
43
 
44
 
45
  import gradio as gr
46
- iface = gr.Interface(fn=abstractive_text, inputs= ["text"],outputs=["text"],title="Case summary generation")
47
- iface.launch(share=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
 
 
43
 
44
 
45
  import gradio as gr
46
+ sum_iface = gr.Interface(fn=abstractive_text, inputs= ["text"],outputs=["text"],title="Case summary generation")
47
+ sum_iface.launch(share=False)
48
+
49
+
50
+
51
+ import transformers
52
+ from transformers import BloomForCausalLM
53
+ from transformers import BloomTokenizerFast
54
+ import torch
55
+ from transformers import AutoTokenizer, AutoModelForCausalLM
56
+ import gradio as gr
57
+
58
+ tokenizer = AutoTokenizer.from_pretrained("bigscience/bloom-560m")
59
+
60
+ model = AutoModelForCausalLM.from_pretrained("bigscience/bloom-560m")
61
+
62
+ def get_result_with_bloom(text):
63
+ result_length = 200
64
+ inputs1 = tokenizer(text, return_tensors="pt")
65
+ output1 = tokenizer.decode(model.generate(inputs1["input_ids"],
66
+ max_length=result_length,
67
+ num_beams=2,
68
+ no_repeat_ngram_size=2,
69
+ early_stopping=True
70
+ )[0])
71
+ return output1
72
+
73
+
74
+
75
+
76
+ txtgen_iface = gr.Interface(fn=get_result_with_bloom,inputs = "text",outputs=["text"],title="Text generation with Bloom")
77
+ txtgen_iface.launch(share=True)
78
+
79
+
80
+ import spacy.cli
81
+ import en_core_med7_lg
82
+ import spacy
83
+ import gradio as gr
84
+
85
+ spacy.cli.download("en_core_web_lg")
86
+
87
+
88
+ med7 = en_core_med7_lg.load()
89
+
90
+ # create distinct colours for labels
91
+ col_dict = {}
92
+ seven_colours = ['#e6194B', '#3cb44b', '#ffe119', '#ffd8b1', '#f58231', '#f032e6', '#42d4f4']
93
+ for label, colour in zip(med7.pipe_labels['ner'], seven_colours):
94
+ col_dict[label] = colour
95
+
96
+ options = {'ents': med7.pipe_labels['ner'], 'colors':col_dict}
97
+
98
+ #text = 'A patient was prescribed Magnesium hydroxide 400mg/5ml suspension PO of total 30ml bid for the next 5 days.'
99
+ def ner_drugs(text):
100
+ doc = med7(text)
101
+
102
+ spacy.displacy.render(doc, style='ent', jupyter=True, options=options)
103
+
104
+ return [(ent.text, ent.label_) for ent in doc.ents]
105
+
106
+
107
+
108
+ med_iface = gr.Interface(fn=ner_drugs,inputs = "text",outputs=["text"],title="Drugs Named Entity Recognition")
109
+ med_iface.launch(share=True)
110
+
111
+
112
+
113
+ demo = gr.TabbedInterface(
114
+
115
+ [txtgen_iface, sum_iface, med_iface], ["Text Generation", "Summary Generation", "Named-entity recognition"],
116
+ title=title,
117
+
118
+ )
119
+
120
+ demo.queue()
121
+ demo.launch(share=False)
122
+
123
+
124