Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -62,4 +62,31 @@ def predict(request: QueryRequest):
|
|
| 62 |
return {
|
| 63 |
"question": request.question,
|
| 64 |
"answer": answer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
}
|
|
|
|
| 62 |
return {
|
| 63 |
"question": request.question,
|
| 64 |
"answer": answer
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
@app.get("/answers")
|
| 71 |
+
def predict(question: str = Query(..., description="The question to ask"), max_new_tokens: int = Query(50, description="Max new tokens to generate")):
|
| 72 |
+
# Tokenize the input question
|
| 73 |
+
inputs = tokenizer(question, return_tensors="pt")
|
| 74 |
+
|
| 75 |
+
# Generate output from model
|
| 76 |
+
outputs = model.generate(
|
| 77 |
+
**inputs,
|
| 78 |
+
max_new_tokens=max_new_tokens,
|
| 79 |
+
do_sample=True,
|
| 80 |
+
temperature=0.7,
|
| 81 |
+
top_p=0.9,
|
| 82 |
+
pad_token_id=tokenizer.eos_token_id,
|
| 83 |
+
return_dict_in_generate=True
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
# Decode output
|
| 87 |
+
answer = tokenizer.decode(outputs.sequences[0], skip_special_tokens=True)
|
| 88 |
+
|
| 89 |
+
return {
|
| 90 |
+
"question": question,
|
| 91 |
+
"answer": answer
|
| 92 |
}
|