de-Rodrigo commited on
Commit
9392036
Β·
1 Parent(s): d0aeaf6

Basic Interactive Plot Hosted in HF Space

Browse files
Files changed (2) hide show
  1. app.py +54 -23
  2. data/data.csv +6 -0
app.py CHANGED
@@ -1,34 +1,65 @@
1
- # Ejemplo usando st.bokeh_chart en lugar de st.components.v1.html
 
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
- # Generar datos
9
- N = 10
10
- x = np.random.rand(N)
11
- y = np.random.rand(N)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
- red_image = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAF/wK+bNykAAAAAElFTkSuQmCC"
14
- blue_image = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mN8/f8/AwAI/AL+fB/9AAAAAElFTkSuQmCC"
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(x=x, y=y, img=images, label=labels))
19
- p = figure(title="Interactive Plot with Hover Images", tools="hover", width=600, height=600)
20
- p.scatter('x', 'y', size=15, source=source, fill_color="navy", alpha=0.5)
 
 
 
21
 
22
- hover = p.select_one(HoverTool)
23
- hover.tooltips = """
24
  <div>
25
- <div>
26
- <span style="font-size: 12px; font-weight: bold;">Label: @label</span>
27
- </div>
28
- <div>
29
- <img src="@img" alt="Image" style="width:100px;"/>
30
- </div>
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