-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
71 lines (54 loc) · 2.27 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import logging
import os
import pandas as pd
import streamlit as st
from rc_modules import Doc2vec, Proofing, Tfidf, Word2vec
logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s',
level=logging.INFO)
ENABLE_PROOFING = os.getenv('ENABLE_PROOFING', 0)
NUM_RANK = int(os.getenv('NUM_RANK', 5))
def pre_process(question: str) -> str:
p = Proofing()
return p.check_words(question)
def main():
st.set_page_config(layout="wide")
st.title('Sistem Question Answering Konstitusi Indonesia')
tfidf = Tfidf(cache='.cache/tfidf')
word2vec = Word2vec(cache='.cache/word2vec')
doc2vec = Doc2vec(cache='.cache/doc2vec')
question = st.text_input(
label='Masukkan pertanyaan tentang konsititusi',
value='Apa tugas lembaga negara')
show_tfidf = st.checkbox('Tfidf', value=True)
show_word2vec = st.checkbox('Word2vec', value=True)
show_doc2vec = st.checkbox('Doc2vec', value=True)
if st.button('Tanyakan') or question != 'Apa tugas lembaga negara' and len(question) > 1:
try:
processed_question = pre_process(
question) if ENABLE_PROOFING else question
except ValueError as e:
st.write(f'Pertanyaan anda terdeteksi tidak valid: {question}')
st.write(e.args[0])
show_tfidf = False
show_word2vec = False
show_doc2vec = False
if show_tfidf:
answer: pd.DataFrame = tfidf.ask(
processed_question, num_rank=NUM_RANK)
answer['Rank'] = answer.reset_index().index + 1
st.subheader('Tfidf')
st.table(answer[['Rank', 'Response', 'Similarity']])
if show_word2vec:
answer: pd.DataFrame = word2vec.ask(
processed_question, num_rank=NUM_RANK)
answer['Rank'] = answer.reset_index().index + 1
st.subheader('Word2vec')
st.table(answer[['Rank', 'Response', 'Similarity']])
if show_doc2vec:
answer: pd.DataFrame = doc2vec.ask(
processed_question, num_rank=NUM_RANK)
answer['Rank'] = answer.reset_index().index + 1
st.subheader('Doc2vec')
st.table(answer[['Rank', 'Response', 'Similarity']])
if __name__ == '__main__':
main()