ethanrom commited on
Commit
b44c45d
·
1 Parent(s): a33899d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -15,8 +15,11 @@ torch_device = 'cuda' if torch.cuda.is_available() else 'cpu'
15
  tokenizer3 = PegasusTokenizer.from_pretrained(model_name)
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,
@@ -35,7 +38,8 @@ def qa_paraphrase(text_input, question):
35
  batch = tokenizer3([sentence],truncation=True,padding='longest',max_length=60, return_tensors="pt").to(torch_device)
36
  translated = model3.generate(**batch,max_length=60,num_beams=10, num_return_sequences=1, temperature=1.5)
37
  paraphrase = tokenizer3.batch_decode(translated, skip_special_tokens=True)[0]
38
- return f"Answer: {answer}\nParaphrased Sentence: {paraphrase}"
 
39
 
40
 
41
  iface = gr.Interface(
@@ -49,4 +53,4 @@ iface = gr.Interface(
49
  description="Answer a given question from a given text and paraphrase the sentence containing the answer."
50
  )
51
 
52
- iface.launch()
 
15
  tokenizer3 = PegasusTokenizer.from_pretrained(model_name)
16
  model3 = PegasusForConditionalGeneration.from_pretrained(model_name).to(torch_device)
17
 
18
+ prev_context = "" # to store the previous context
19
 
20
  def qa_paraphrase(text_input, question):
21
+ global prev_context
22
+ text_input = prev_context + " " + text_input # combine with previous context
23
  prediction = classifier(
24
  context=text_input,
25
  question=question,
 
38
  batch = tokenizer3([sentence],truncation=True,padding='longest',max_length=60, return_tensors="pt").to(torch_device)
39
  translated = model3.generate(**batch,max_length=60,num_beams=10, num_return_sequences=1, temperature=1.5)
40
  paraphrase = tokenizer3.batch_decode(translated, skip_special_tokens=True)[0]
41
+ prev_context = text_input # update previous context
42
+ return f"Q: {question}\nA: {answer}\nParaphrased Sentence: {paraphrase}"
43
 
44
 
45
  iface = gr.Interface(
 
53
  description="Answer a given question from a given text and paraphrase the sentence containing the answer."
54
  )
55
 
56
+ iface.launch()