t5-playground / app.py
merve's picture
merve HF staff
Update app.py
e268c03
from transformers import pipeline
import gradio as gr
from gradio import inputs
text2text_generator = pipeline("text2text-generation", model = "t5-base")
tasks_dict = {"Translation": "Translate English to German:", "Summarization": "Summarize:", "Linguistic Acceptibility": "cola sentence:",
"Other":""}
def infer(Input, task):
if task == "Other":
output = text2text_generator(f"{Input}")
elif task == "Question Answering":
input_list = Input.split("?")
output = text2text_generator(f"question: {input_list[0]}, context: {input_list[1]}")
else:
output = text2text_generator(f"{tasks_dict[task]} {Input}")
return output[0]["generated_text"]
description = "Explore the capabilities of text generation. If you can't find the task you're looking for, pick Other and write your prompt."
title = "T5 Playground"
interface = gr.Interface(infer,
title = title,
inputs = [
gr.inputs.Textbox(lines=15, label="Input"),
gr.inputs.Dropdown(["Translation", "Summarization", "Linguistic Acceptibility", "Question Answering", "Other"]),
],
outputs = gr.outputs.Textbox(type = "auto", label="Output"),
description=description,
examples=[["TensorFlow is a free and open-source software library for machine learning and artificial intelligence. It can be used across a range of tasks but has a particular focus on training and inference of deep neural networks. TensorFlow was developed by the Google Brain team for internal Google use in research and production. The initial version was released under the Apache License 2.0 in 2015. Google released the updated version of TensorFlow, named TensorFlow 2.0, in September 2019. TensorFlow can be used in a wide variety of programming languages, most notably Python, as well as Javascript, C++, and Java. This flexibility lends itself to a range of applications in many different sectors.", "Summarization"],
["I love machine learning!", "Translation"],
["I went to market and.", "Linguistic Acceptibility"],
["what is the meaning to life?The answer to the ultimate question of life, the universe and everything is 42.", "Question Answering"]],
theme = "grass"
)
interface.launch()