Update Model/MultimodelNER/app_MNER.py
Browse files- Model/MultimodelNER/app_MNER.py +49 -49
Model/MultimodelNER/app_MNER.py
CHANGED
|
@@ -1,50 +1,50 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
from spacy import displacy
|
| 3 |
-
from Model.NER.VLSP2021.Predict_Ner import ViTagger
|
| 4 |
-
import re
|
| 5 |
-
from thunghiemxuly import save_uploaded_image,convert_text_to_txt,add_string_to_txt
|
| 6 |
-
|
| 7 |
-
import os
|
| 8 |
-
from transformers import AutoTokenizer, BertConfig
|
| 9 |
-
from Model.MultimodelNER.VLSP2016.train_umt_2016 import format_predictions,process_predictions,combine_entities,remove_B_prefix,load_model,predict
|
| 10 |
-
from Model.MultimodelNER.predict import get_test_examples_predict
|
| 11 |
-
from Model.MultimodelNER import resnet as resnet
|
| 12 |
-
from Model.MultimodelNER.resnet_utils import myResnet
|
| 13 |
-
import torch
|
| 14 |
-
import numpy as np
|
| 15 |
-
from Model.MultimodelNER.VLSP2016.dataset_roberta import MNERProcessor_2016
|
| 16 |
-
from Model.MultimodelNER.VLSP2016.MNER_2016 import show_mner_2016
|
| 17 |
-
from Model.MultimodelNER.VLSP2021.MNER_2021 import show_mner_2021
|
| 18 |
-
|
| 19 |
-
CONFIG_NAME = 'bert_config.json'
|
| 20 |
-
WEIGHTS_NAME = 'pytorch_model.bin'
|
| 21 |
-
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
net = getattr(resnet, 'resnet152')()
|
| 25 |
-
net.load_state_dict(torch.load(os.path.join('
|
| 26 |
-
encoder = myResnet(net, True, device)
|
| 27 |
-
def process_text(text):
|
| 28 |
-
# Loại bỏ dấu cách thừa và dấu cách ở đầu và cuối văn bản
|
| 29 |
-
processed_text = re.sub(r'\s+', ' ', text.strip())
|
| 30 |
-
return processed_text
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
def show_mner():
|
| 35 |
-
st.sidebar.title('Datasets')
|
| 36 |
-
dataset = st.sidebar.selectbox("Datasets", ("VLSP2016", "VLSP2021"))
|
| 37 |
-
st.header("Multimodal NER")
|
| 38 |
-
if dataset == 'VLSP2016':
|
| 39 |
-
show_mner_2016()
|
| 40 |
-
else:
|
| 41 |
-
show_mner_2021()
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
# Sử dụng widget st.html để hiển thị HTML
|
| 45 |
-
|
| 46 |
-
# Hiển thị văn bản đã nhập
|
| 47 |
-
# st.write("Văn bản đã nhập:", text)
|
| 48 |
-
|
| 49 |
-
|
| 50 |
###Ví dụ 1 : Một trận hỗn chiến đã xảy ra tại trận đấu khúc côn cầu giữa Penguins và Islanders ở Mỹ (image:penguin)
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from spacy import displacy
|
| 3 |
+
from Model.NER.VLSP2021.Predict_Ner import ViTagger
|
| 4 |
+
import re
|
| 5 |
+
from thunghiemxuly import save_uploaded_image,convert_text_to_txt,add_string_to_txt
|
| 6 |
+
|
| 7 |
+
import os
|
| 8 |
+
from transformers import AutoTokenizer, BertConfig
|
| 9 |
+
from Model.MultimodelNER.VLSP2016.train_umt_2016 import format_predictions,process_predictions,combine_entities,remove_B_prefix,load_model,predict
|
| 10 |
+
from Model.MultimodelNER.predict import get_test_examples_predict
|
| 11 |
+
from Model.MultimodelNER import resnet as resnet
|
| 12 |
+
from Model.MultimodelNER.resnet_utils import myResnet
|
| 13 |
+
import torch
|
| 14 |
+
import numpy as np
|
| 15 |
+
from Model.MultimodelNER.VLSP2016.dataset_roberta import MNERProcessor_2016
|
| 16 |
+
from Model.MultimodelNER.VLSP2016.MNER_2016 import show_mner_2016
|
| 17 |
+
from Model.MultimodelNER.VLSP2021.MNER_2021 import show_mner_2021
|
| 18 |
+
|
| 19 |
+
CONFIG_NAME = 'bert_config.json'
|
| 20 |
+
WEIGHTS_NAME = 'pytorch_model.bin'
|
| 21 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
net = getattr(resnet, 'resnet152')()
|
| 25 |
+
net.load_state_dict(torch.load(os.path.join('/Model/Resnet/', 'resnet152.pth')))
|
| 26 |
+
encoder = myResnet(net, True, device)
|
| 27 |
+
def process_text(text):
|
| 28 |
+
# Loại bỏ dấu cách thừa và dấu cách ở đầu và cuối văn bản
|
| 29 |
+
processed_text = re.sub(r'\s+', ' ', text.strip())
|
| 30 |
+
return processed_text
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def show_mner():
|
| 35 |
+
st.sidebar.title('Datasets')
|
| 36 |
+
dataset = st.sidebar.selectbox("Datasets", ("VLSP2016", "VLSP2021"))
|
| 37 |
+
st.header("Multimodal NER")
|
| 38 |
+
if dataset == 'VLSP2016':
|
| 39 |
+
show_mner_2016()
|
| 40 |
+
else:
|
| 41 |
+
show_mner_2021()
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
# Sử dụng widget st.html để hiển thị HTML
|
| 45 |
+
|
| 46 |
+
# Hiển thị văn bản đã nhập
|
| 47 |
+
# st.write("Văn bản đã nhập:", text)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
###Ví dụ 1 : Một trận hỗn chiến đã xảy ra tại trận đấu khúc côn cầu giữa Penguins và Islanders ở Mỹ (image:penguin)
|