Spaces:
Runtime error
Runtime error
paul hilders commited on
Commit ·
929c841
1
Parent(s): 5d101e4
Add NER highlighting
Browse files47 unmodified lines4849505152534 unmodified lines5859606162636465666768697071727310 unmodified lines848586878847 unmodified linesfor i, token in enumerate(text_tokens_decoded):highlighted_text.append((str(token), float(text_scores[i])))# Apply NER to extract named entities, and run the explainability method# for each named entity.highlighed_entities = []4 unmodified linesprint(highlighed_entities)return overlapped, highlighted_textinput_img = gr.inputs.Image(type='pil', label="Original Image")input_txt = "text"inputs = [input_img, input_txt]outputs = [gr.inputs.Image(type='pil', label="Output Image"), "highlight"]iface = gr.Interface(fn=run_demo,inputs=inputs,outputs=outputs,title="CLIP Grounding Explainability",10 unmodified lines["example_images/dogs_on_bed.png", "Book"],["example_images/dogs_on_bed.png", "Cat"]])demo_tabs = gr.TabbedInterface([iface, iface], ["Default", "NER"])demo_tabs.launch(debug=True)47 unmodified lines4849505152535455565758596061626364656667686970717273747576777879808182834 unmodified lines88899091929394959697989910010110210310 unmodified lines11411511611711811947 unmodified linesfor i, token in enumerate(text_tokens_decoded):highlighted_text.append((str(token), float(text_scores[i])))return overlapped, highlighted_text# Default demo:input_img = gr.inputs.Image(type='pil', label="Original Image")input_txt = "text"inputs = [input_img, input_txt]outputs = [gr.inputs.Image(type='pil', label="Output Image"), "highlight"]iface = gr.Interface(fn=run_demo,inputs=inputs,outputs=outputs,title="CLIP Grounding Explainability",description="A demonstration based on the Generic Attention-model Explainability method for Interpreting Bi-Modal Transformers by Chefer et al. (2021): https://github.com/hila-chefer/Transformer-MM-Explainability.",examples=[["example_images/London.png", "London Eye"],["example_images/London.png", "Big Ben"],["example_images/harrypotter.png", "Harry"],["example_images/harrypotter.png", "Hermione"],["example_images/harrypotter.png", "Ron"],["example_images/Amsterdam.png", "Amsterdam canal"],["example_images/Amsterdam.png", "Old buildings"],["example_images/Amsterdam.png", "Pink flowers"],["example_images/dogs_on_bed.png", "Two dogs"],["example_images/dogs_on_bed.png", "Book"],["example_images/dogs_on_bed.png", "Cat"]])# NER demo:def NER_demo(image, text):# Apply NER to extract named entities, and run the explainability method# for each named entity.highlighed_entities = []4 unmodified linesprint(highlighed_entities)return highlighed_entitiesinput_img = gr.inputs.Image(type='pil', label="Original Image")input_txt = "text"inputs = [input_img, input_txt]outputs = ["highlight"]iface_NER = gr.Interface(fn=NER_demo,inputs=inputs,outputs=outputs,title="CLIP Grounding Explainability",10 unmodified lines["example_images/dogs_on_bed.png", "Book"],["example_images/dogs_on_bed.png", "Cat"]])demo_tabs = gr.TabbedInterface([iface, iface_NER], ["Default", "NER"])demo_tabs.launch(debug=True)
app.py+35-4