devendergarg14 commited on
Commit
b7585c6
·
1 Parent(s): 2cfe324

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -3
app.py CHANGED
@@ -1,15 +1,16 @@
1
  from transformers import pipeline
2
  import gradio as gr
 
3
  generator = pipeline('text-generation', model='EleutherAI/gpt-neo-1.3B')
4
  def query(input_sentence,num,start):
5
  string3=[]
6
  for i in range(0,num):
7
  intial="""These are the few examples of converting original sentences into paraphrased sentences.\n original: Symptoms of influenza include fever and nasal congestion.\n paraphrase: A stuffy nose and elevated temperature are signs you may have the flu.\n original: Maintaining a creative work environment is not only beneficial to employees, but also to company profits.\n paraphrase: Having a fertile work environment can increase productivity and profitability.\n """
8
  full_input=intial+"original:"+input_sentence + "\n paraphrase:"+start
9
- string1=generator(full_input, do_sample=True,max_length= len(full_input.split())+80,min_length=len(full_input.split())+80,temperature=0.65+i*0.05)[0]['generated_text']
10
  string2=string1.split('paraphrase:',3)[-1]
11
  string3.append(string2.split('.',1)[0]+".")
12
  return '\n\n'.join([i for i in string3[0:]])
13
  title = "Paraphrasing"
14
- description = "Gradio Demo for Paraphrasing"
15
- 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,enable_queue=True).launch()
 
1
  from transformers import pipeline
2
  import gradio as gr
3
+ import random
4
  generator = pipeline('text-generation', model='EleutherAI/gpt-neo-1.3B')
5
  def query(input_sentence,num,start):
6
  string3=[]
7
  for i in range(0,num):
8
  intial="""These are the few examples of converting original sentences into paraphrased sentences.\n original: Symptoms of influenza include fever and nasal congestion.\n paraphrase: A stuffy nose and elevated temperature are signs you may have the flu.\n original: Maintaining a creative work environment is not only beneficial to employees, but also to company profits.\n paraphrase: Having a fertile work environment can increase productivity and profitability.\n """
9
  full_input=intial+"original:"+input_sentence + "\n paraphrase:"+start
10
+ 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.01*random.uniform(1, 10))[0]['generated_text']
11
  string2=string1.split('paraphrase:',3)[-1]
12
  string3.append(string2.split('.',1)[0]+".")
13
  return '\n\n'.join([i for i in string3[0:]])
14
  title = "Paraphrasing"
15
+ 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."
16
+ 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,enable_queue=True).launch()