Spaces:
Paused
Paused
import datetime | |
import json | |
import streamlit as st | |
import tokenizers | |
import torch | |
from transformers import Pipeline, pipeline | |
def get_answer(input, context, engine): | |
answer = engine({"question": input, "context": context}) | |
return answer["answer"] | |
def get_context(): | |
BIRTHYEAR = 1952 | |
OTHERBIRTHYEAR = 1984 | |
now = datetime.datetime.now() | |
with open("context.json") as f: | |
context = ( | |
json.load(f)["info"] | |
.replace("[YEAR]", str(now.year)) | |
.replace("[BIRTHYEAR]", str(BIRTHYEAR)) | |
.replace("[AGE]", str(now.year - BIRTHYEAR)) | |
.replace("[OTHERAGE]", str(now.year - OTHERBIRTHYEAR)) | |
) | |
return context | |
def load_engine() -> Pipeline: | |
nlp_qa = pipeline( | |
"question-answering", | |
model="mrm8488/bert-italian-finedtuned-squadv1-it-alfa", | |
tokenizer="mrm8488/bert-italian-finedtuned-squadv1-it-alfa", | |
) | |
return nlp_qa | |