Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,13 +3,18 @@ import numpy as np
|
|
3 |
import torch
|
4 |
from transformers import DistilBertTokenizer, DistilBertForQuestionAnswering
|
5 |
|
6 |
-
|
|
|
|
|
7 |
def load_model():
|
8 |
model = DistilBertForQuestionAnswering.from_pretrained("distilbert-base-uncased-distilled-squad")
|
9 |
tokenizer = DistilBertTokenizer.from_pretrained("distilbert-base-uncased-distilled-squad")
|
10 |
return model, tokenizer
|
11 |
|
12 |
def get_answer(question, text, tokenizer, model):
|
|
|
|
|
|
|
13 |
inputs = tokenizer(question, text, return_tensors="pt", truncation=True, padding=True)
|
14 |
with torch.no_grad():
|
15 |
outputs = model(**inputs)
|
@@ -20,8 +25,6 @@ def get_answer(question, text, tokenizer, model):
|
|
20 |
return answer
|
21 |
|
22 |
def main():
|
23 |
-
st.set_page_config(page_title="Question Answering Tool", page_icon=":mag_right:")
|
24 |
-
|
25 |
st.write("# Question Answering Tool \n"
|
26 |
"This tool will help you find answers to your questions about the text you provide. \n"
|
27 |
"Please enter your question and the text you want to search in the boxes below.")
|
|
|
3 |
import torch
|
4 |
from transformers import DistilBertTokenizer, DistilBertForQuestionAnswering
|
5 |
|
6 |
+
st.set_page_config(page_title="Question Answering Tool", page_icon=":mag_right:")
|
7 |
+
|
8 |
+
@st.cache_resource
|
9 |
def load_model():
|
10 |
model = DistilBertForQuestionAnswering.from_pretrained("distilbert-base-uncased-distilled-squad")
|
11 |
tokenizer = DistilBertTokenizer.from_pretrained("distilbert-base-uncased-distilled-squad")
|
12 |
return model, tokenizer
|
13 |
|
14 |
def get_answer(question, text, tokenizer, model):
|
15 |
+
if "your name" in question.lower():
|
16 |
+
return "My name is Numini, full form NativUttarMini, created by Sanju Debnath at University of Calcutta."
|
17 |
+
|
18 |
inputs = tokenizer(question, text, return_tensors="pt", truncation=True, padding=True)
|
19 |
with torch.no_grad():
|
20 |
outputs = model(**inputs)
|
|
|
25 |
return answer
|
26 |
|
27 |
def main():
|
|
|
|
|
28 |
st.write("# Question Answering Tool \n"
|
29 |
"This tool will help you find answers to your questions about the text you provide. \n"
|
30 |
"Please enter your question and the text you want to search in the boxes below.")
|