ethanrom commited on
Commit
306995b
·
1 Parent(s): 35d1b2d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -26
app.py CHANGED
@@ -16,31 +16,7 @@ tokenizer3 = PegasusTokenizer.from_pretrained(model_name)
16
  model3 = PegasusForConditionalGeneration.from_pretrained(model_name).to(torch_device)
17
 
18
 
19
- def paraphrase(text_input):
20
- question = "What is the Sri Lanka's rank on human development Index?"
21
- prediction = classifier(
22
- context=text_input,
23
- question=question,
24
- truncation=True,
25
- max_length=512,
26
- padding=True,
27
- )
28
- answer = prediction['answer']
29
- answer_start = prediction['start']
30
- answer_end = prediction['end']
31
- context = text_input.split(".")
32
- for i in range(len(context)):
33
- if answer in context[i]:
34
- sentence = context[i].strip() + "."
35
- break
36
- batch = tokenizer3([sentence],truncation=True,padding='longest',max_length=60, return_tensors="pt").to(torch_device)
37
- translated = model3.generate(**batch,max_length=60,num_beams=10, num_return_sequences=1, temperature=1.5)
38
- paraphrase = tokenizer3.batch_decode(translated, skip_special_tokens=True)[0]
39
- return paraphrase
40
-
41
-
42
- def qa_paraphrase(text_input):
43
- question = "What is the Sri Lanka's rank on human development Index?"
44
  prediction = classifier(
45
  context=text_input,
46
  question=question,
@@ -64,7 +40,10 @@ def qa_paraphrase(text_input):
64
 
65
  iface = gr.Interface(
66
  fn=qa_paraphrase,
67
- inputs=gr.inputs.Textbox(label="Text Input"),
 
 
 
68
  outputs=[
69
  gr.outputs.Textbox(label="Answer"),
70
  gr.outputs.Textbox(label="Paraphrased Sentence")
 
16
  model3 = PegasusForConditionalGeneration.from_pretrained(model_name).to(torch_device)
17
 
18
 
19
+ def qa_paraphrase(text_input, question):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  prediction = classifier(
21
  context=text_input,
22
  question=question,
 
40
 
41
  iface = gr.Interface(
42
  fn=qa_paraphrase,
43
+ inputs=[
44
+ gr.inputs.Textbox(label="Text Input"),
45
+ gr.inputs.Textbox(label="Question")
46
+ ],
47
  outputs=[
48
  gr.outputs.Textbox(label="Answer"),
49
  gr.outputs.Textbox(label="Paraphrased Sentence")