import streamlit as st
import wizmap
from streamlit import components
st.set_option('deprecation.showPyplotGlobalUse', False)
data_url = 'https://huggingface.co/datasets/xiaohk/embeddings/blob/main/imdb/data.ndjson'
grid_url = 'https://huggingface.co/datasets/xiaohk/embeddings/blob/main/imdb/grid.json'
# import streamlit as st
# import base64
# import random
# import numpy as np
# import random
# import html
# import base64
# import pkgutil
# import ndjson
# from glob import glob
# from os.path import exists, join, basename
# from tqdm import tqdm
# from collections import Counter
# from IPython.display import display_html
# from json import dump, load, dumps
# from sklearn.feature_extraction.text import CountVectorizer, TfidfTransformer
# from quadtreed3 import Quadtree, Node
# from scipy.sparse import csr_matrix
# from sklearn.neighbors import KernelDensity
# from scipy.stats import norm
# from typing import Tuple
# def _make_html(data_url, grid_url):
# # HTML template for WizMap widget
# html_top = """
WizMap"""
# html_bottom = """"""
# # Simulating JS and CSS content with base64 encoding for Streamlit
# js_string = "console.log('Hello from WizMap');"
# js_b = js_string.encode()
# js_base64 = base64.b64encode(js_b).decode("utf-8")
# # Simulating passing data into JS by using another script
# messenger_js = f"""
# (function() {{
# const event = new Event('wizmapData');
# event.dataURL = '{data_url}';
# event.gridURL = '{grid_url}';
# document.dispatchEvent(event);
# }}())
# """
# messenger_js = messenger_js.encode()
# messenger_js_base64 = base64.b64encode(messenger_js).decode("utf-8")
# # Injecting JS into the HTML template
# html_str = (
# html_top
# + """""".format(
# js_base64
# )
# + """""".format(
# messenger_js_base64
# )
# + html_bottom
# )
# return html_str
# def visualize(data_url, grid_url, height=700):
# html_str = _make_html(data_url, grid_url)
# # Randomly generate an ID for the iframe to avoid collision
# iframe_id = "wizmap-iframe-" + str(int(random.random() * 1e8))
# iframe = f"""
#
# """
# st.markdown(display_html(iframe, raw=True), unsafe_allow_html=True)
# visualize(data_url, grid_url)
# st.write("# Display wizmap")
html =wizmap.visualize(data_url, grid_url)
components.v1.html(html, height=700)