|
import streamlit as st |
|
from spacy import displacy |
|
from Model.NER.VLSP2021.Predict_Ner import ViTagger |
|
import re |
|
from thunghiemxuly import save_uploaded_image,convert_text_to_txt,add_string_to_txt |
|
|
|
import os |
|
from transformers import AutoTokenizer, BertConfig |
|
from Model.MultimodelNER.VLSP2016.train_umt_2016 import format_predictions,process_predictions,combine_entities,remove_B_prefix,load_model,predict |
|
from Model.MultimodelNER.predict import get_test_examples_predict |
|
from Model.MultimodelNER import resnet as resnet |
|
from Model.MultimodelNER.resnet_utils import myResnet |
|
import torch |
|
import numpy as np |
|
from Model.MultimodelNER.VLSP2016.dataset_roberta import MNERProcessor_2016 |
|
from Model.MultimodelNER.VLSP2016.MNER_2016 import show_mner_2016 |
|
from Model.MultimodelNER.VLSP2021.MNER_2021 import show_mner_2021 |
|
|
|
CONFIG_NAME = 'bert_config.json' |
|
WEIGHTS_NAME = 'pytorch_model.bin' |
|
device = torch.device("cuda" if torch.cuda.is_available() else "cpu") |
|
|
|
|
|
net = getattr(resnet, 'resnet152')() |
|
net.load_state_dict(torch.load(os.path.join('Model/Resnet/', 'resnet152.pth'))) |
|
encoder = myResnet(net, True, device) |
|
def process_text(text): |
|
|
|
processed_text = re.sub(r'\s+', ' ', text.strip()) |
|
return processed_text |
|
|
|
|
|
|
|
def show_mner(): |
|
st.sidebar.title('Datasets') |
|
dataset = st.sidebar.selectbox("Datasets", ("VLSP2016", "VLSP2021")) |
|
st.header("Multimodal NER") |
|
if dataset == 'VLSP2016': |
|
show_mner_2016() |
|
else: |
|
show_mner_2021() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|