anjali2024 commited on
Commit
83b0dd0
·
verified ·
1 Parent(s): 58c94db

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py CHANGED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoTokenizer, AutoModelForQuestionAnswering
2
+ import torch
3
+
4
+ # Load model and tokenizer
5
+ tokenizer = AutoTokenizer.from_pretrained("ntphuc149/ViBidLEQA_large")
6
+ model = AutoModelForQuestionAnswering.from_pretrained("ntphuc149/ViBidLEQA_large")
7
+
8
+ # Example usage
9
+ #question = "Thế nào là đấu thầu hạn chế?"
10
+ #context = "Đấu thầu hạn chế là phương thức lựa chọn nhà thầu trong đó chỉ một số nhà thầu đáp ứng yêu cầu về năng lực và kinh nghiệm được bên mời thầu mời tham gia."
11
+
12
+ # Tokenize input
13
+ inputs = tokenizer(
14
+ question,
15
+ context,
16
+ return_tensors="pt",
17
+ max_length=512,
18
+ truncation=True,
19
+ padding=True
20
+ )
21
+
22
+ # Get model predictions
23
+ with torch.no_grad():
24
+ outputs = model(**inputs)
25
+
26
+ # Get answer span
27
+ answer_start = torch.argmax(outputs.start_logits)
28
+ answer_end = torch.argmax(outputs.end_logits) + 1
29
+
30
+ answer = tokenizer.decode(inputs.input_ids[0][answer_start:answer_end])
31
+ print(f"Question: {question}")
32
+ print(f"Answer: {answer}")