Belligerent commited on
Commit
1c6d5fd
·
1 Parent(s): 108ae2d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -6
app.py CHANGED
@@ -1,15 +1,26 @@
1
  import gradio as gr
2
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, Text2TextGenerationPipeline
3
 
4
- pipe = Text2TextGenerationPipeline(model = AutoModelForSeq2SeqLM.from_pretrained("jpelhaw/t5-word-sense-disambiguation"),tokenizer = AutoTokenizer.from_pretrained("jpelhaw/t5-word-sense-disambiguation"), )
 
5
 
 
 
 
 
 
 
6
 
7
- examples = ["""'question: which description describes the word " java " best in the following context? descriptions: [ " A drink consisting of an infusion of ground coffee beans " , " a platform-independent programming lanugage " , or " an island in Indonesia to the south of Borneo " ] context: I like to drink "java" in the morning ."""]
8
- print(pipe(examples[0]))
9
 
10
- gr.Interface.from_pipeline(pipe,
11
- inputs = "textbox",
12
- outputs="textbox",
 
 
 
 
 
 
13
  examples = examples,
14
  title = "word sense disambiguation",
15
  allow_flagging="never").launch(inbrowser=True)
 
1
  import gradio as gr
2
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, Text2TextGenerationPipeline
3
 
4
+ pipe = Text2TextGenerationPipeline(model = AutoModelForSeq2SeqLM.from_pretrained("jpelhaw/t5-word-sense-disambiguation"),
5
+ tokenizer = AutoTokenizer.from_pretrained("jpelhaw/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
 
 
 
14
 
15
+
16
+ examples = [["java", 'I like to drink "java" in the morning.', " A drink consisting of an infusion of ground coffee beans. " , " a platform-independent programming language.", " an island in Indonesia to the south of Borneo. "]]
17
+ gr.Interface(wsd_gen,
18
+ inputs = [gr.inputs.Textbox(lines=1, placeholder= "Enter Word to Mask", default="", label = "Based on the context, which description best matches this word: "),
19
+ gr.inputs.Textbox(lines=1, placeholder="Enter context", default="", label = "context: "),
20
+ gr.inputs.Textbox(lines=1, placeholder="Enter description", default="", label = "description 1: "),
21
+ gr.inputs.Textbox(lines=1, placeholder="Enter description", default="", label = "description 2: "),
22
+ gr.inputs.Textbox(lines=1, placeholder="Enter description", default="", label = "description 3: ")],
23
+ outputs= "textbox",
24
  examples = examples,
25
  title = "word sense disambiguation",
26
  allow_flagging="never").launch(inbrowser=True)