marksverdhei commited on
Commit
edfc428
·
1 Parent(s): 6ea2993
Files changed (1) hide show
  1. app.py +29 -0
app.py CHANGED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ model = pipeline(model="marksverdhei/t5-base-define")
5
+ model.model.config.max_length = 300
6
+
7
+ description = """
8
+ Enter a word and a sentence that uses the word. We then generate a definition
9
+ """
10
+
11
+
12
+ def predict(word, example):
13
+ input_text = f"define \"{word}\": {example}"
14
+ output = model(input_text, truncation=True)
15
+ output_text = output[0]["generated_text"]
16
+ return output_text
17
+
18
+
19
+ gr.Interface(
20
+ fn=predict_from_inputs,
21
+ inputs=["text", "text", "text"],
22
+ outputs=[
23
+ gr.Textbox(label="word"),
24
+ gr.Textbox(label="example sentence using word")
25
+ ],
26
+
27
+ title="Word definition",
28
+ description=description,
29
+ ).launch()