Spaces:
Running on Zero
Running on Zero
Remove phi3 medium.
Browse filesFiles changed (2)
- app.py-10
- phi3_instruct_graph.py+1-1
10 unmodified lines111213141516171855 unmodified lines747576777879807 unmodified lines88899091929394959646 unmodified lines1431441451461471481491501516 unmodified lines1581591601611621631648 unmodified lines17317417517617717817910 unmodified linesfrom spacy.tokens import Spanimport randomjson_example = {'nodes': [{'id': 'Aerosmith', 'type': 'organization', 'detailed_type': 'rock band'}, {'id': 'Steven Tyler', 'type': 'person', 'detailed_type': 'lead singer'}, {'id': 'vocal cord injury', 'type': 'medical condition', 'detailed_type': 'fractured larynx'}, {'id': 'retirement', 'type': 'event', 'detailed_type': 'announcement'}, {'id': 'touring', 'type': 'activity', 'detailed_type': 'musical performance'}, {'id': 'September 2023', 'type': 'date', 'detailed_type': 'specific time'}], 'edges': [{'from': 'Aerosmith', 'to': 'Steven Tyler', 'label': 'led by'}, {'from': 'Steven Tyler', 'to': 'vocal cord injury', 'label': 'suffered'}, {'from': 'vocal cord injury', 'to': 'retirement', 'label': 'caused'}, {'from': 'retirement', 'to': 'touring', 'label': 'ended'}, {'from': 'vocal cord injury', 'to': 'September 2023', 'label': 'occurred in'}]}@spaces.GPUdef extract(text, model):model = Phi3InstructGraph(model=model)55 unmodified linesspans = []colors = {}for node in data["nodes"]:# entity_spans = [m.span() for m in re.finditer(re.escape(node["id"]), full_text)]entity_spans = find_token_indices(doc, node["id"], full_text)for dataentity in entity_spans:start = dataentity["start"]7 unmodified linesif node["type"] not in colors:colors[node["type"]] = get_random_light_color()# for span in spans:# print(f"Span: {span.text}, Label: {span.label_}")doc.set_ents(spans, default="unmodified")doc.spans["sc"] = spans46 unmodified lines# edge['smooth'] = {'type': 'curvedCW', 'roundness': 0.2}html = nt.generate_html()# need to remove ' from HTMLhtml = html.replace("'", '"')# return htmlreturn f"""<iframe style="width: 140%; height: 620px; margin: 0 auto;" name="result"allow="midi; geolocation; microphone; camera; display-capture; encrypted-media;"6 unmodified linesif not text or not model:raise gr.Error("Text and model must be provided.")json_data = extract(text, model)# json_data = json_exampleentities_viz = create_custom_entity_viz(json_data, text)graph_html = create_graph(json_data)8 unmodified lineswith gr.Column(scale=1):input_model = gr.Dropdown(MODEL_LIST, label="Model",# value=MODEL_LIST[0])input_text = gr.TextArea(label="Text", info="The text to be extracted")10 unmodified lines11121314151655 unmodified lines7273747576777 unmodified lines85868788899046 unmodified lines1371381391401411421436 unmodified lines1501511521531541558 unmodified lines16416516616716816910 unmodified linesfrom spacy.tokens import Spanimport random@spaces.GPUdef extract(text, model):model = Phi3InstructGraph(model=model)55 unmodified linesspans = []colors = {}for node in data["nodes"]:entity_spans = find_token_indices(doc, node["id"], full_text)for dataentity in entity_spans:start = dataentity["start"]7 unmodified linesif node["type"] not in colors:colors[node["type"]] = get_random_light_color()doc.set_ents(spans, default="unmodified")doc.spans["sc"] = spans46 unmodified lines# edge['smooth'] = {'type': 'curvedCW', 'roundness': 0.2}html = nt.generate_html()html = html.replace("'", '"')return f"""<iframe style="width: 140%; height: 620px; margin: 0 auto;" name="result"allow="midi; geolocation; microphone; camera; display-capture; encrypted-media;"6 unmodified linesif not text or not model:raise gr.Error("Text and model must be provided.")json_data = extract(text, model)entities_viz = create_custom_entity_viz(json_data, text)graph_html = create_graph(json_data)8 unmodified lineswith gr.Column(scale=1):input_model = gr.Dropdown(MODEL_LIST, label="Model",)input_text = gr.TextArea(label="Text", info="The text to be extracted")
12 unmodified lines1314151617181912 unmodified linesMODEL_LIST = ["EmergentMethods/Phi-3-mini-4k-instruct-graph","EmergentMethods/Phi-3-mini-128k-instruct-graph","EmergentMethods/Phi-3-medium-128k-instruct-graph"]torch.random.manual_seed(0)12 unmodified lines1314151617181912 unmodified linesMODEL_LIST = ["EmergentMethods/Phi-3-mini-4k-instruct-graph","EmergentMethods/Phi-3-mini-128k-instruct-graph",# "EmergentMethods/Phi-3-medium-128k-instruct-graph"]torch.random.manual_seed(0)
app.py-10
phi3_instruct_graph.py+1-1