merve HF staff commited on
Commit
3175aa8
1 Parent(s): 1c58dee

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import gradio as gr
3
+ from gradio import inputs
4
+
5
+ text2text_generator = pipeline("text2text-generation", model = "t5-base")
6
+
7
+ tasks_dict = {"Translation": "Translate English to German:", "Summarization": "Summarize:", "Linguistic Acceptibility": "cola sentence:",
8
+ "Other":""}
9
+
10
+ def infer(Input, task):
11
+ if task == "Other":
12
+ output = text2text_generator(f"{Input}")
13
+ elif task == "Question Answering":
14
+ input_list = Input.split("?")
15
+ output = text2text_generator(f"question: {input_list[0]}, context: {input_list[1]}")
16
+ else:
17
+ output = text2text_generator(f"{tasks_dict[task]} {Input}")
18
+ return output[0]["generated_text"]
19
+
20
+
21
+ description = "Explore the capabilities of text generation."
22
+ title = "T5 Playground"
23
+ interface = gr.Interface(infer,
24
+ title = title,
25
+ inputs = [
26
+ gr.inputs.Textbox(lines=20, label="Input"),
27
+ gr.inputs.Dropdown(["Translation", "Summarization", "Linguistic Acceptibility", "Question Answering", "Other"]),
28
+ ],
29
+ outputs = gr.outputs.Textbox(type = "auto", label="Output"),
30
+ description=description,
31
+ 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"],
32
+ ["I love machine learning!", "Translation"],
33
+ ["I went to market and.", "Linguistic Acceptibility"],
34
+ ["what is the meaning to life?The answer to the ultimate question of life, the universe and everything is 42.", "Question Answering"]],
35
+ )
36
+ interface.launch()