linpearjun commited on
Commit
46da1a9
1 Parent(s): 38f4045

Upload Gradio app.py

Browse files
Files changed (1) hide show
  1. Gradio app.py +24 -0
Gradio app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, Text2TextGenerationPipeline
3
+
4
+ pipe = Text2TextGenerationPipeline(model = AutoModelForSeq2SeqLM.from_pretrained("jpwahle/t5-word-sense-disambiguation"),
5
+ tokenizer = AutoTokenizer.from_pretrained("jpwahle/t5-word-sense-disambiguation"))
6
+
7
+ def wsd_gen(word, context, d1, d2, d3):
8
+ question = 'question: question: which description describes the word' + ' " ' + word + ' " '
9
+ descriptions_context = 'best in the following context? \descriptions:[ " ' + d1 + '" , " ' + d2 + ' " , or " '+ d3 + ' " ] context: ' + context + "'"
10
+ raw_input = question + descriptions_context
11
+ output = pipe(raw_input)[0]['generated_text']
12
+ return output
13
+ word_mask = gr.inputs.Textbox(lines=1, placeholder= "Enter word to disambiguate", default="", label = "Based on the context, which description best matches this word: ")
14
+ input_context = gr.inputs.Textbox(lines=1, placeholder="Enter context", default="", label = "context: ")
15
+ input_desc1 = gr.inputs.Textbox(lines=1, placeholder="Enter description", default="", label = "description 1: ")
16
+ input_desc2 = gr.inputs.Textbox(lines=1, placeholder="Enter description", default="", label = "description 2: ")
17
+ input_desc3 = gr.inputs.Textbox(lines=1, placeholder="Enter description", default="", label = "description 3: ")
18
+ input_desc4 = gr.inputs.Textbox(lines=1, placeholder="Enter description", default="", label = "description 4: ")
19
+ gr.Interface(wsd_gen,
20
+ inputs = [word_mask , input_context, input_desc1, input_desc2, input_desc3],
21
+ outputs= "textbox",
22
+ title = "T5-Word Sense Disambiguation",
23
+ theme = "seafoam",
24
+ allow_flagging="never").launch(inbrowser=True,share=True)