File size: 1,721 Bytes
4e07a7c
0c6a012
31dbe0a
378d972
 
 
494e732
56affb6
5bae3bb
56affb6
 
0e11069
378d972
b7585c6
0d66eb8
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from transformers import pipeline
import gradio as gr
generator = pipeline('text-generation', model='EleutherAI/gpt-neo-1.3B')
def query(input_sentence,num,start):
    string3=[]
    for i in range(0,num):
       intial="""These are the few examples of converting original sentences into paraphrased sentences.\n original: The gray clouds were a warning of an approaching storm.\n paraphrase: The coming storm was foretold by the dark clouds.\n original: Giraffes like Acacia leaves and hay, and they can consume 75 pounds of food a day.\n paraphrase: A giraffe can eat up to 75 pounds of Acacia leaves and hay daily.\n """
       full_input=intial+"original:"+input_sentence + "\n paraphrase:"+start
       string1=generator(full_input, do_sample=True,max_length= len(full_input.split())+70,min_length=len(full_input.split())+70,temperature=0.65+i*0.05)[0]['generated_text']
       string2=string1.split('paraphrase:',3)[-1]
       string3.append(string2.split('.',1)[0]+".")
    return '\n\n'.join([i for i in string3[0:]])
title = "Paraphrasing"
description = "Gradio Demo for Paraphrasing with GPT-NEO. Simply add one line sentence in the Input. It is possible to control the start of output paraphrased sentences using optional Starting Point Input."
article = "<p style='text-align: center'><a href='https://github.com/EleutherAI/gpt-neo'>GPT-NEO GitHub</a></p>"
gr.Interface(fn=query, inputs=[gr.inputs.Textbox(lines=4, label="Input Text (Single Sentence)"),
gr.inputs.Slider( minimum=1, maximum=5, step=1, default=2, label="Numbers of Outputs"),
gr.inputs.Textbox(lines=1, label="Starting Point (optional)")],
outputs=["text"],
title=title,description=description,
article= article,
enable_queue=True).launch()