word_definition / app.py
marksverdhei's picture
Update app.py
84bb4b2
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()