krrishsinha commited on
Commit
1941458
·
verified ·
1 Parent(s): b00ffb5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -31,6 +31,10 @@ def pdfopen(filepath : str) -> str:
31
 
32
  return text.strip()
33
 
 
 
 
 
34
 
35
  def summarizer():
36
 
@@ -46,7 +50,7 @@ def anq():
46
 
47
  tokenizer = AutoTokenizer.from_pretrained(qnap, use_fast=False)
48
  model = AutoModelForQuestionAnswering.from_pretrained(qnap)
49
- k = pipeline("question-answering", model=model, tokenizer=tokenizer)
50
 
51
  return k
52
 
@@ -164,10 +168,14 @@ def quesans(py : qna):
164
  raise HTTPException(status_code=400, detail="No PDF text found. Upload PDF first.")
165
 
166
  g = anq()
 
 
 
 
 
 
167
 
168
- result = g (question= py.question, context= txt2)
169
-
170
- return {"answer" : result["answer"]}
171
 
172
 
173
  @app.post("/clausedetection")
 
31
 
32
  return text.strip()
33
 
34
+ def clean_short(ans):
35
+ words = ans.split()
36
+ return " ".join(words[:3])
37
+
38
 
39
  def summarizer():
40
 
 
50
 
51
  tokenizer = AutoTokenizer.from_pretrained(qnap, use_fast=False)
52
  model = AutoModelForQuestionAnswering.from_pretrained(qnap)
53
+ k = pipeline("question-answering", model=model, tokenizer=tokenizer,max_answer_len=5)
54
 
55
  return k
56
 
 
168
  raise HTTPException(status_code=400, detail="No PDF text found. Upload PDF first.")
169
 
170
  g = anq()
171
+
172
+ forced_question = py.question + " (Give answer in 1 to 3 words only.)"
173
+
174
+ result = g (question= forced_question, context= txt2)
175
+
176
+ cleaned = clean_short(ans = result["answer"])
177
 
178
+ return {"answer" : cleaned}
 
 
179
 
180
 
181
  @app.post("/clausedetection")