Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,24 +1,19 @@
|
|
1 |
|
2 |
-
from transformers import
|
3 |
-
import
|
4 |
|
|
|
|
|
5 |
|
6 |
-
|
|
|
|
|
7 |
|
8 |
-
|
9 |
-
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
conversation = chatbot(conversation)
|
17 |
|
18 |
-
reply = conversation.generated_responses[-1]
|
19 |
-
response_list.append(reply)
|
20 |
-
return reply
|
21 |
-
|
22 |
-
demo_chatbot = gr.ChatInterface(Medical_Bot, title="Medical Bot", description="Enter text to start chatting.")
|
23 |
-
|
24 |
-
demo_chatbot.launch()
|
|
|
1 |
|
2 |
+
from transformers import AutoTokenizer, AutoModelForQuestionAnswering
|
3 |
+
import torch
|
4 |
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained("emilyalsentzer/Bio_ClinicalBERT")
|
6 |
+
model = AutoModelForQuestionAnswering.from_pretrained("emilyalsentzer/Bio_ClinicalBERT")
|
7 |
|
8 |
+
def answer_question(context, question):
|
9 |
+
inputs = tokenizer.encode_plus(question, context, return_tensors="pt")
|
10 |
+
answer_start_scores, answer_end_scores = model(**inputs).values()
|
11 |
|
12 |
+
start = torch.argmax(answer_start_scores)
|
13 |
+
end = torch.argmax(answer_end_scores) + 1
|
14 |
|
15 |
+
answer = tokenizer.convert_tokens_to_string(
|
16 |
+
tokenizer.convert_ids_to_tokens(inputs["input_ids"][0][start:end])
|
17 |
+
)
|
18 |
+
return answer
|
|
|
|
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|