File size: 649 Bytes
edfc428
 
 
 
 
 
 
 
 
 
 
84bb4b2
edfc428
 
 
 
 
 
 
84bb4b2
 
edfc428
84bb4b2
edfc428
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import gradio as gr
from transformers import pipeline

model = pipeline(model="marksverdhei/t5-base-define")
model.model.config.max_length = 300

description = """
Enter a word and a sentence that uses the word. We then generate a definition
"""


def predict(word, example) -> str:
    input_text = f"define \"{word}\": {example}"
    output = model(input_text, truncation=True)
    output_text = output[0]["generated_text"]
    return output_text


gr.Interface(
    fn=predict,
    inputs=["text", "text"],
    outputs=[
        gr.Textbox(label="Generated definition")
    ],
    title="Word definition", 
    description=description,
).launch()