Spaces:
Running
Running
Commit
Β·
9392036
1
Parent(s):
d0aeaf6
Basic Interactive Plot Hosted in HF Space
Browse files- app.py +54 -23
- data/data.csv +6 -0
app.py
CHANGED
@@ -1,34 +1,65 @@
|
|
1 |
-
|
|
|
2 |
from bokeh.plotting import figure
|
3 |
from bokeh.models import ColumnDataSource, HoverTool
|
4 |
-
import streamlit as st
|
5 |
-
import numpy as np
|
6 |
-
import random
|
7 |
|
8 |
-
#
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
images = [random.choice([red_image, blue_image]) for _ in range(N)]
|
16 |
-
labels = ["subset1" if img == red_image else "subset2" for img in images]
|
17 |
|
18 |
-
source = ColumnDataSource(data=dict(
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
21 |
|
22 |
-
|
23 |
-
|
24 |
<div>
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
</div>
|
32 |
"""
|
33 |
|
|
|
|
|
|
|
|
|
34 |
st.bokeh_chart(p)
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
from bokeh.plotting import figure
|
4 |
from bokeh.models import ColumnDataSource, HoverTool
|
|
|
|
|
|
|
5 |
|
6 |
+
# --- Define Styles ---
|
7 |
+
st.markdown(
|
8 |
+
"""
|
9 |
+
<style>
|
10 |
+
.main-title {
|
11 |
+
font-size: 50px;
|
12 |
+
color: #4CAF50;
|
13 |
+
text-align: center;
|
14 |
+
}
|
15 |
+
.sub-title {
|
16 |
+
font-size: 30px;
|
17 |
+
color: #555;
|
18 |
+
}
|
19 |
+
.custom-text {
|
20 |
+
font-size: 18px;
|
21 |
+
line-height: 1.5;
|
22 |
+
}
|
23 |
+
</style>
|
24 |
+
""",
|
25 |
+
unsafe_allow_html=True
|
26 |
+
)
|
27 |
+
|
28 |
+
st.markdown('<h1 class="main-title">Merit Secret Embeddings πππ</h1>', unsafe_allow_html=True)
|
29 |
+
st.markdown('<h2 class="sub-title">Donut</h2>', unsafe_allow_html=True)
|
30 |
+
st.markdown(
|
31 |
+
"""
|
32 |
+
<p class="custom-text">
|
33 |
+
Explore how Donut perceive real data.
|
34 |
+
</p>
|
35 |
+
""",
|
36 |
+
unsafe_allow_html=True
|
37 |
+
)
|
38 |
|
39 |
+
# Get Data
|
40 |
+
df = pd.read_csv("data/data.csv")
|
|
|
|
|
41 |
|
42 |
+
source = ColumnDataSource(data=dict(
|
43 |
+
x=df['x'],
|
44 |
+
y=df['y'],
|
45 |
+
label=df['label'],
|
46 |
+
img=df['img']
|
47 |
+
))
|
48 |
|
49 |
+
# Configure figure
|
50 |
+
TOOLTIPS = """
|
51 |
<div>
|
52 |
+
<div>
|
53 |
+
<img src="@img{safe}" style="width:400px; height:auto; float: left; margin: 0px 15px 15px 0px;" alt="@img" border="2"></img>
|
54 |
+
</div>
|
55 |
+
<div>
|
56 |
+
<span style="font-size: 17px; font-weight: bold;">@label</span>
|
57 |
+
</div>
|
58 |
</div>
|
59 |
"""
|
60 |
|
61 |
+
|
62 |
+
p = figure(width=400, height=400, tooltips=TOOLTIPS, title="")
|
63 |
+
p.scatter('x', 'y', size=20, source=source)
|
64 |
+
|
65 |
st.bokeh_chart(p)
|
data/data.csv
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
x,y,label,img
|
2 |
+
0.1,0.2,Point 1,https://docs.bokeh.org/static/snake.jpg
|
3 |
+
0.3,0.4,Point 2,https://docs.bokeh.org/static/snake2.png
|
4 |
+
0.5,0.6,Point 3,https://docs.bokeh.org/static/snake3D.png
|
5 |
+
0.7,0.8,Point 4,https://docs.bokeh.org/static/snake4_TheRevenge.png
|
6 |
+
0.9,0.1,Point 5,https://docs.bokeh.org/static/snakebite.jpg
|