spital commited on
Commit
2296822
1 Parent(s): 610ad77

Add application file

Browse files
Files changed (2) hide show
  1. app.py +32 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ import json
4
+ import os
5
+ API_URL = "https://api-inference.huggingface.co/models/EleutherAI/gpt-neo-1.3B"
6
+ apikey=os.environ.get('api_key')
7
+ headers = {"Authorization": f"Bearer {apikey}"}
8
+ def query(input_sentence,num,start):
9
+ paraphrase_final=[]
10
+ for i in range(0,num):
11
+ 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 """
12
+ full_input=intial+"original:"+input_sentence + "\n paraphrase:"+start
13
+ data = json.dumps({"inputs":full_input,"parameters":{"max_length":len(full_input.split())+70,"min_length":len(full_input.split())+70},"temperature":0.650+0.05*i})
14
+ response = requests.request("POST", API_URL, headers=headers, data=data)
15
+ output=json.loads(response.content.decode("utf-8"))[0]['generated_text']
16
+ paraphrase=output.split('paraphrase:',3)[-1]
17
+ paraphrase_text=paraphrase.split('original:',1)[0]
18
+ paraphrase_final.append( paraphrase_text.split('.',1)[0]+".")
19
+ return '\n\n'.join([i for i in paraphrase_final[0:]])
20
+ title = "Paraphrasing with GPT-NEO"
21
+ 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"
22
+ 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>"
23
+ examples=[['The sky, at sunset, looked like a carnivorous flower.',4,'The coloured reddish'],['Inside us there is something that has no name, that something is what we are.',4,'']]
24
+ gr.Interface(fn=query, inputs=[gr.inputs.Textbox(lines=4, label="Input Text (Single Sentence)"),
25
+ gr.inputs.Slider( minimum=1, maximum=10, step=1, default=4, label="Numbers of Outputs"),
26
+ gr.inputs.Textbox(lines=1, label="Starting Point (optional)")],
27
+ outputs=["text"],
28
+ title=title,description=description,
29
+ article= article,
30
+ examples=examples,
31
+ allow_flagging='never').launch(enable_queue=True,
32
+ cache_examples=True)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
1
+ gradio
2
+ requests