Anne31415 commited on
Commit
c960b96
·
1 Parent(s): 8b58a9c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -20
app.py CHANGED
@@ -31,54 +31,49 @@ import streamlit as st
31
 
32
  import streamlit as st
33
 
 
 
34
  def cloud_button(label, key=None, color=None):
35
  button_id = f"cloud-button-{key or label}"
36
  color_class = f"color-{color}" if color else ""
37
  num_circles = max(3, min(12, len(label) // 4)) # Adjust the number of circles based on text length
 
38
 
39
  # Generate circles on both sides of the text
40
  circles_html = ''.join([
41
- f'<div class="circle {color_class}" style="margin-right: -15px;"></div>' for _ in range(num_circles//2)
42
  ] + [
43
- f'<div class="circle {color_class}" style="margin-left: -15px;"></div>' for _ in range(num_circles//2)
44
  ])
45
 
46
  cloud_button_html = f"""
47
- <div class="cloud {color_class}" id="{button_id}" style="margin-bottom: 20px; display: inline-block;">
48
  {circles_html}
49
- <div class="rectangle {color_class}">{label}</div>
50
  </div>
51
  <style>
52
  .cloud {{
53
  position: relative;
54
  display: inline-flex;
55
  align-items: center;
56
- cursor: pointer;
57
- user-select: none;
58
- font-size: 16px;
59
- white-space: nowrap;
60
  }}
61
- .rectangle {{
62
- min-width: 120px;
63
- height: auto;
64
- border-radius: 30px;
65
  position: relative;
66
- display: inline-flex;
67
- align-items: center;
68
- justify-content: center;
69
  font-weight: bold;
70
  padding: 10px 20px;
71
  z-index: 2;
72
- background-color: #9BBEFF;
73
  }}
74
  .circle {{
75
  background-color: #9BBEFF;
76
  border-radius: 50%;
77
- width: 30px;
78
- height: 30px;
79
  position: relative;
80
  z-index: 1;
81
  }}
 
 
 
82
  </style>
83
  <script>
84
  document.getElementById("{button_id}").onclick = function() {{
@@ -88,14 +83,12 @@ def cloud_button(label, key=None, color=None):
88
  """
89
  st.markdown(cloud_button_html, unsafe_allow_html=True)
90
 
91
- # Examples
92
  cloud_button("Short Text", color="1")
93
  cloud_button("This is a longer piece of text", color="2")
94
  cloud_button("This is an even longer piece of text to test the cloud button", color="3")
95
 
96
 
97
 
98
-
99
  def load_pdf(file_path):
100
  pdf_reader = PdfReader(file_path)
101
  text = ""
 
31
 
32
  import streamlit as st
33
 
34
+ import streamlit as st
35
+
36
  def cloud_button(label, key=None, color=None):
37
  button_id = f"cloud-button-{key or label}"
38
  color_class = f"color-{color}" if color else ""
39
  num_circles = max(3, min(12, len(label) // 4)) # Adjust the number of circles based on text length
40
+ circle_size = 60
41
 
42
  # Generate circles on both sides of the text
43
  circles_html = ''.join([
44
+ f'<div class="circle {color_class}" style="margin-right: -{circle_size // 2}px;"></div>' for _ in range(num_circles//2)
45
  ] + [
46
+ f'<div class="circle {color_class}" style="margin-left: -{circle_size // 2}px;"></div>' for _ in range(num_circles//2)
47
  ])
48
 
49
  cloud_button_html = f"""
50
+ <div class="cloud" id="{button_id}" style="margin-bottom: 20px;">
51
  {circles_html}
52
+ <div class="text">{label}</div>
53
  </div>
54
  <style>
55
  .cloud {{
56
  position: relative;
57
  display: inline-flex;
58
  align-items: center;
 
 
 
 
59
  }}
60
+ .text {{
 
 
 
61
  position: relative;
 
 
 
62
  font-weight: bold;
63
  padding: 10px 20px;
64
  z-index: 2;
 
65
  }}
66
  .circle {{
67
  background-color: #9BBEFF;
68
  border-radius: 50%;
69
+ width: {circle_size}px;
70
+ height: {circle_size}px;
71
  position: relative;
72
  z-index: 1;
73
  }}
74
+ .color-1 .circle {{ background-color: #FFA07A; }}
75
+ .color-2 .circle {{ background-color: #FF7F50; }}
76
+ .color-3 .circle {{ background-color: #FF6347; }}
77
  </style>
78
  <script>
79
  document.getElementById("{button_id}").onclick = function() {{
 
83
  """
84
  st.markdown(cloud_button_html, unsafe_allow_html=True)
85
 
 
86
  cloud_button("Short Text", color="1")
87
  cloud_button("This is a longer piece of text", color="2")
88
  cloud_button("This is an even longer piece of text to test the cloud button", color="3")
89
 
90
 
91
 
 
92
  def load_pdf(file_path):
93
  pdf_reader = PdfReader(file_path)
94
  text = ""