references now took question from dataset
Browse files- web/HOW_TO_TUN.txt +2 -0
- web/__pycache__/app.cpython-310.pyc +0 -0
- web/app.py +39 -1
- web/templates/index.html +38 -10
web/HOW_TO_TUN.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
run python app OR python -m app
|
2 |
+
there might be error when you running that command but that probably will ask you to install flask or any other required dependencies
|
web/__pycache__/app.cpython-310.pyc
ADDED
Binary file (1.93 kB). View file
|
|
web/app.py
CHANGED
@@ -4,6 +4,7 @@
|
|
4 |
# 1) BEFORE ANNOTATION; 2) AFTER ANNOTATION;
|
5 |
# 3) NOTEBOOK THAT CONTAIN MODEL TRAINING CODE WHICH GENERATES PYTORCH_MODEL.BIN;
|
6 |
# 4) GUI CODE WHICH USE THAT MODEL, ON BELOW CODES
|
|
|
7 |
import requests
|
8 |
import json
|
9 |
|
@@ -25,9 +26,18 @@ raw_data = payload["data"][0]
|
|
25 |
paragraph_list = raw_data['paragraphs']
|
26 |
|
27 |
final_context = ""
|
|
|
28 |
for paragraph in paragraph_list:
|
29 |
context = paragraph['context']
|
|
|
|
|
30 |
final_context = final_context + context
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
@app.route('/')
|
33 |
def index():
|
@@ -40,7 +50,35 @@ def get_answer():
|
|
40 |
'context': final_context,
|
41 |
'question': question
|
42 |
})
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
if __name__ == '__main__':
|
46 |
app.run(debug=True)
|
|
|
4 |
# 1) BEFORE ANNOTATION; 2) AFTER ANNOTATION;
|
5 |
# 3) NOTEBOOK THAT CONTAIN MODEL TRAINING CODE WHICH GENERATES PYTORCH_MODEL.BIN;
|
6 |
# 4) GUI CODE WHICH USE THAT MODEL, ON BELOW CODES
|
7 |
+
# sample text here
|
8 |
import requests
|
9 |
import json
|
10 |
|
|
|
26 |
paragraph_list = raw_data['paragraphs']
|
27 |
|
28 |
final_context = ""
|
29 |
+
context_list = []
|
30 |
for paragraph in paragraph_list:
|
31 |
context = paragraph['context']
|
32 |
+
qas = paragraph['qas']
|
33 |
+
# context_list.append(context)
|
34 |
final_context = final_context + context
|
35 |
+
for qas_row in qas:
|
36 |
+
question_context = {
|
37 |
+
"question": qas_row['question'],
|
38 |
+
"context": context
|
39 |
+
}
|
40 |
+
context_list.append(question_context)
|
41 |
|
42 |
@app.route('/')
|
43 |
def index():
|
|
|
50 |
'context': final_context,
|
51 |
'question': question
|
52 |
})
|
53 |
+
|
54 |
+
# find context, for bert_score
|
55 |
+
answer_only = answer['answer']
|
56 |
+
chosen_context = ""
|
57 |
+
chosen_question = ""
|
58 |
+
|
59 |
+
for context_row in context_list:
|
60 |
+
if answer_only in context_row['context']:
|
61 |
+
chosen_context = context_row['context']
|
62 |
+
chosen_question = context_row['question']
|
63 |
+
break
|
64 |
+
|
65 |
+
from evaluate import load
|
66 |
+
bertscore = load("bertscore")
|
67 |
+
predictions = [question, answer_only]
|
68 |
+
references = [chosen_question, chosen_context]
|
69 |
+
bert_score_result = bertscore.compute(predictions=predictions, references=references, lang="id")
|
70 |
+
|
71 |
+
# ANSI escape codes for background colors
|
72 |
+
bg_red = "\033[41m"
|
73 |
+
bg_green = "\033[42m"
|
74 |
+
bg_yellow = "\033[43m"
|
75 |
+
bg_reset = "\033[0m"
|
76 |
+
|
77 |
+
print(f"{bg_yellow}Question: {bg_reset} {question}")
|
78 |
+
print(f"{bg_green}Answer:{bg_reset} {answer['answer']}")
|
79 |
+
print(f"{bg_red}Bert Score:{bg_reset} {bert_score_result}")
|
80 |
+
|
81 |
+
return render_template('index.html', answer=answer['answer'], question=question, bert_score_result=bert_score_result)
|
82 |
|
83 |
if __name__ == '__main__':
|
84 |
app.run(debug=True)
|
web/templates/index.html
CHANGED
@@ -1,17 +1,45 @@
|
|
1 |
<!DOCTYPE html>
|
2 |
-
<html>
|
3 |
<head>
|
|
|
|
|
4 |
<title>Question Answering</title>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
</head>
|
6 |
<body>
|
7 |
-
<
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
</body>
|
17 |
</html>
|
|
|
1 |
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
<title>Question Answering</title>
|
7 |
+
|
8 |
+
<!-- Link to Bootstrap CSS from CDN -->
|
9 |
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css">
|
10 |
+
|
11 |
+
<style>
|
12 |
+
/* Add a gray background color to the body */
|
13 |
+
body {
|
14 |
+
background-color: #e0e0e0; /* You can change the color code as needed */
|
15 |
+
}
|
16 |
+
</style>
|
17 |
</head>
|
18 |
<body>
|
19 |
+
<div class="container mt-5">
|
20 |
+
<h1 class="text-center">Question Answering</h1>
|
21 |
+
<form method="POST" action="/answer">
|
22 |
+
<div class="row">
|
23 |
+
<div class="col"><label for="question">Masukkan pertanyaan:</label></div>
|
24 |
+
</div>
|
25 |
+
<div class="row">
|
26 |
+
<div class="col">
|
27 |
+
<div class="form-group">
|
28 |
+
<input type="text" class="form-control" id="question" name="question" required/>
|
29 |
+
</div>
|
30 |
+
</div>
|
31 |
+
<div class="col">
|
32 |
+
<div class="form-group">
|
33 |
+
<button type="submit" class="btn btn-primary">Submit</button>
|
34 |
+
</div>
|
35 |
+
</div>
|
36 |
+
</div>
|
37 |
+
</form>
|
38 |
+
<div class="mt-3">
|
39 |
+
<p>Pertanyaan: <span id="question-display">{{ question }}</span></p>
|
40 |
+
<p>Jawaban: <span id="answer">{{ answer }}</span></p>
|
41 |
+
<p>Bert Score: <span id="bert_score_result">{{ bert_score_result }}</span></p>
|
42 |
+
</div>
|
43 |
+
</div>
|
44 |
</body>
|
45 |
</html>
|