File size: 2,265 Bytes
0c6a012 d5fe222 0313309 378d972 b929154 378d972 494e732 56affb6 0313309 b929154 8ad5a75 7b8c2c6 0602420 0d66eb8 d655fed 0d66eb8 |
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 28 29 |
import gradio as gr
import requests
import json
import os
API_URL = "https://api-inference.huggingface.co/models/EleutherAI/gpt-neo-2.7B"
apikey=os.environ.get('api_key')
headers = {"Authorization": f"Bearer {apikey}"}
def query(input_sentence,num,start):
paraphrase_final=[]
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
data = json.dumps({"inputs":full_input,"options":{"wait_for_model":1},"parameters":{"max_length":len(full_input.split())+80,"min_length":len(full_input.split())+80},"temperature":0.65+0.05*i})
response = requests.request("POST", API_URL, headers=headers, data=data)
output=json.loads(response.content.decode("utf-8"))[0]['generated_text']
paraphrase_text=output.split('paraphrase:',3)[-1]
paraphrase_final.append( paraphrase_text.split('.',1)[0]+".")
return '\n\n'.join([i for i in paraphrase_final[0:]])
title = "Paraphrasing with GPT-NEO"
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. If outputs are not satisfactory try to increase number of outputs"
article = "<div style='text-align: center;'><a href='https://github.com/EleutherAI/gpt-neo'>GPT-NEO GitHub</a> | <center><img src='https://visitor-badge.glitch.me/badge?page_id=devendergarg14_Paraphrasing_with_GPT_Neo' alt='visitor badge'></center></div>"
gr.Interface(fn=query, inputs=[gr.inputs.Textbox(lines=4, label="Input Text (Single Sentence)"),
gr.inputs.Slider( minimum=1, maximum=10, step=1, default=4, 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() |