Spaces:
Running
Running
Commit ·
a19fbdf
1
Parent(s): 340b3eb
Remove print statments
Browse files15 unmodified lines161718192021222324252627282930313233343536373839404142433 unmodified lines4748495051525354101 unmodified lines15615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019136 unmodified lines22822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328415 unmodified linesfrom NER_Distiller import distill_entitiesapp = FastAPI()print("Version 2...")# Download files from model repo# tag_vocab_path = hf_hub_download(# repo_id="SinaLab/Nested",# filename="tag_vocab.pkl"# )pretrained_path = "aubmindlab/bert-base-arabertv2" # must match trainingtokenizer = AutoTokenizer.from_pretrained(pretrained_path)encoder = AutoModel.from_pretrained(pretrained_path).eval()# checkpoint_path = hf_hub_download(# repo_id="SinaLab/Nested",# filename="checkpoints/checkpoint_2.pt"# )checkpoint_path = snapshot_download(repo_id="SinaLab/Nested", allow_patterns="checkpoints/")print("checkpoint_path : ", checkpoint_path)args_path = hf_hub_download(repo_id="SinaLab/Nested",3 unmodified lineswith open(args_path, 'r') as f:args_data = json.load(f)print("data : ", args_data)# Load modelwith open("Nested/utils/tag_vocab.pkl", "rb") as f:label_vocab = pickle.load(f)101 unmodified linesdef NER(sentence, mode):print("within NER, and mode is: ", mode)output_list = []xml = ""if mode.strip() == "1":output_list = jsons_to_list_of_lists(extract(sentence))return output_listelif mode.strip() == "2":print("outputlist : ", output_list)if output_list != []:xml = IBO_to_XML(output_list)print("xml is: ", xml)return xmlelse:output_list = jsons_to_list_of_lists(extract(sentence))print("output_list .....: ", output_list)xml = IBO_to_XML(output_list)print("else xml is: ", xml)return xmlelif mode.strip() == "3":print("mode is 3")if xml != "":#print("in if")html = NER_XML_to_HTML(xml)return htmlelse:print("in else : ")print("extract : ", extract(sentence))output_list = jsons_to_list_of_lists(extract(sentence))#print("output list : ", output_list)xml = IBO_to_XML(output_list)html = NER_XML_to_HTML(xml)return html36 unmodified lines"statusCode": 0,}print("content: ", content)return JSONResponse(content=content,media_type="application/json",status_code=200,)# sentence = "ذهب احمد إلى جامعة"# Load tagger# tagger, tag_vocab, train_config = load_checkpoint(checkpoint_path)# Convert text to a tagger dataset and index the tokens in args.text# dataset, token_vocab = text2segments(sentence)# vocabs = namedtuple("Vocab", ["tags", "tokens"])# vocab = vocabs(tokens=token_vocab, tags=tag_vocab)# From the datasets generate the dataloaders# dataloader = get_dataloaders(# (dataset,),# vocab,# args_data,# batch_size=32,# shuffle=(False,),# )[0]# Perform inference on the text and get back the tagged segments# segments = tagger.infer(dataloader)# segments_lists = []## Print results## for segment in segments:## s = [## f"{token.text} ({'|'.join([t['tag'] for t in token.pred_tag])})"## for token in segment## ]## print(" ".join(s))# for segment in segments:# for token in segment:# segments_list = {}# segments_list["token"] = token.text# list_of_tags = [t['tag'] for t in token.pred_tag]# list_of_tags = [i for i in list_of_tags if i not in('O',' ','')]# if list_of_tags == []:# segments_list["tags"] = ' '.join(['O'])# else:# segments_list["tags"] = ' '.join(list_of_tags)# segments_lists.append(segments_list)# print(segments_lists)15 unmodified lines161718192021222324252627283 unmodified lines323334353637101 unmodified lines13914014114214314414514614714814915015115215315415515615715815916016116216316436 unmodified lines20120220320420520620720815 unmodified linesfrom NER_Distiller import distill_entitiesapp = FastAPI()pretrained_path = "aubmindlab/bert-base-arabertv2" # must match trainingtokenizer = AutoTokenizer.from_pretrained(pretrained_path)encoder = AutoModel.from_pretrained(pretrained_path).eval()checkpoint_path = snapshot_download(repo_id="SinaLab/Nested", allow_patterns="checkpoints/")args_path = hf_hub_download(repo_id="SinaLab/Nested",3 unmodified lineswith open(args_path, 'r') as f:args_data = json.load(f)# Load modelwith open("Nested/utils/tag_vocab.pkl", "rb") as f:label_vocab = pickle.load(f)101 unmodified linesdef NER(sentence, mode):output_list = []xml = ""if mode.strip() == "1":output_list = jsons_to_list_of_lists(extract(sentence))return output_listelif mode.strip() == "2":if output_list != []:xml = IBO_to_XML(output_list)return xmlelse:output_list = jsons_to_list_of_lists(extract(sentence))xml = IBO_to_XML(output_list)return xmlelif mode.strip() == "3":if xml != "":html = NER_XML_to_HTML(xml)return htmlelse:output_list = jsons_to_list_of_lists(extract(sentence))xml = IBO_to_XML(output_list)html = NER_XML_to_HTML(xml)return html36 unmodified lines"statusCode": 0,}return JSONResponse(content=content,media_type="application/json",status_code=200,)
app.py-76