Spaces:
Build error
Build error
import streamlit as st | |
st.set_page_config( | |
layout="centered", # Can be "centered" or "wide". In the future also "dashboard", etc. | |
initial_sidebar_state="auto", # Can be "auto", "expanded", "collapsed" | |
page_title='Extractive Summarization', # String or None. Strings get appended with "• Streamlit". | |
page_icon='./favicon.png', # String, anything supported by st.image, or None. | |
) | |
import pandas as pd | |
import numpy as np | |
import json | |
import os | |
import sys | |
sys.path.append(os.path.abspath('./')) | |
import streamlit_apps_config as config | |
from streamlit_ner_output import show_html2, jsl_display_annotations, get_color | |
import sparknlp | |
from sparknlp.base import * | |
from sparknlp.annotator import * | |
from pyspark.sql import functions as F | |
from sparknlp_display import NerVisualizer | |
from pyspark.ml import Pipeline | |
from pyspark.sql.types import StringType | |
spark= sparknlp.start() | |
## Marking down NER Style | |
st.markdown(config.STYLE_CONFIG, unsafe_allow_html=True) | |
root_path = config.project_path | |
########## To Remove the Main Menu Hamburger ######## | |
hide_menu_style = """ | |
<style> | |
#MainMenu {visibility: hidden;} | |
</style> | |
""" | |
st.markdown(hide_menu_style, unsafe_allow_html=True) | |
########## Side Bar ######## | |
## loading logo(newer version with href) | |
import base64 | |
def get_base64_of_bin_file(bin_file): | |
with open(bin_file, 'rb') as f: | |
data = f.read() | |
return base64.b64encode(data).decode() | |
def get_img_with_href(local_img_path, target_url): | |
img_format = os.path.splitext(local_img_path)[-1].replace('.', '') | |
bin_str = get_base64_of_bin_file(local_img_path) | |
html_code = f''' | |
<a href="{target_url}"> | |
<img height="90%" width="90%" src="data:image/{img_format};base64,{bin_str}" /> | |
</a>''' | |
return html_code | |
logo_html = get_img_with_href('./jsl-logo.png', 'https://www.johnsnowlabs.com/') | |
st.sidebar.markdown(logo_html, unsafe_allow_html=True) | |
#sidebar info | |
model_name= ["nerdl_fewnerd_100d", "ner_conll_elmo", "ner_mit_movie_complex_distilbert_base_cased", "ner_conll_albert_large_uncased", "onto_100"] | |
st.sidebar.title("Pretrained model to test") | |
selected_model = st.sidebar.selectbox("", model_name) | |
######## Main Page ######### | |
if selected_model == "nerdl_fewnerd_100d": | |
app_title= "Detect up to 8 entity types in general domain texts" | |
app_description= "Named Entity Recognition model aimed to detect up to 8 entity types from general domain texts. This model was trained on the Few-NERD/inter public dataset using Spark NLP, and it is available in Spark NLP Models hub (https://nlp.johnsnowlabs.com/models)" | |
st.title(app_title) | |
st.markdown("<h2>"+app_description+"</h2>" , unsafe_allow_html=True) | |
st.markdown("**`PERSON`** **,** **`ORGANIZATION`** **,** **`LOCATION`** **,** **`ART`** **,** **`BUILDING`** **,** **`PRODUCT`** **,** **`EVENT`** **,** **`OTHER`**", unsafe_allow_html=True) | |
elif selected_model== "ner_conll_elmo": | |
app_title= "Detect up to 4 entity types in general domain texts" | |
app_description= "Named Entity Recognition model aimed to detect up to 4 entity types from general domain texts. This model was trained on the CoNLL 2003 text corpu using Spark NLP, and it is available in Spark NLP Models hub (https://nlp.johnsnowlabs.com/models)" | |
st.title(app_title) | |
st.markdown("<h2>"+app_description+"</h2>" , unsafe_allow_html=True) | |
st.markdown("**`PER`** **,** **`LOC`** **,** **`ORG`** **,** **`MISC` **", unsafe_allow_html=True) | |
elif selected_model== "ner_mit_movie_complex_distilbert_base_cased": | |
app_title= "Detect up to 12 entity types in movie domain texts" | |
app_description= "Named Entity Recognition model aimed to detect up to 12 entity types from movie domain texts. This model was trained on the MIT Movie Corpus complex queries dataset to detect movie trivia using Spark NLP, and it is available in Spark NLP Models hub (https://nlp.johnsnowlabs.com/models)" | |
st.title(app_title) | |
st.markdown("<h2>"+app_description+"</h2>" , unsafe_allow_html=True) | |
st.markdown("""**`ACTOR`** **,** **`AWARD`** **,** **`CHARACTER_NAME`** **,** **`DIRECTOR`** **,** **`GENRE`** **,** **`OPINION`** **,** **`ORIGIN`** **,** **`PLOT`**, | |
**`QUOTE`** **,** **`RELATIONSHIP`** **,** **`SOUNDTRACK`** **,** **`YEAR` **""", unsafe_allow_html=True) | |
elif selected_model=="ner_conll_albert_large_uncased": | |
app_title= "Detect up to 4 entity types in general domain texts" | |
app_description= "Named Entity Recognition model aimed to detect up to 4 entity types from general domain texts. This model was trained on the CoNLL 2003 text corpus using Spark NLP, and it is available in Spark NLP Models hub (https://nlp.johnsnowlabs.com/models)" | |
st.title(app_title) | |
st.markdown("<h2>"+app_description+"</h2>" , unsafe_allow_html=True) | |
st.markdown("**`PER`** **,** **`LOC`** **,** **`ORG`** **,** **`MISC` **", unsafe_allow_html=True) | |
elif selected_model=="onto_100": | |
app_title= "Detect up to 18 entity types in general domain texts" | |
app_description= "Named Entity Recognition model aimed to detect up to 18 entity types from general domain texts. This model was trained with GloVe 100d word embeddings using Spark NLP, so be sure to use same embeddings in the pipeline. It is available in Spark NLP Models hub (https://nlp.johnsnowlabs.com/models)" | |
st.title(app_title) | |
st.markdown("<h2>"+app_description+"</h2>" , unsafe_allow_html=True) | |
st.markdown("""**`CARDINAL`** **,** **`EVENT`** **,** **`WORK_OF_ART`** **,** **`ORG`** **,** **`DATE`** **,** **`GPE`** **,** **`PERSON`** **,** **`PRODUCT`**, | |
**`NORP`** **,** **`ORDINAL`** **,** **`MONEY`** **,** **`LOC` **, **`FAC`** **,** **`LAW`** **,** **`TIME`** **,** **`PERCENT`** **,** **`QUANTITY`** **,** **`LANGUAGE` **""", unsafe_allow_html=True) | |
st.subheader("") | |