Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -28,7 +28,7 @@ pdf_file_path = "Private_Book/KOMBI_all2.pdf" # Replace with your PDF file path
|
|
28 |
|
29 |
|
30 |
def cloud_button(label, query, key=None, color=None, overlap=30):
|
31 |
-
button_id = f"cloud-button-{key or label}"
|
32 |
color_class = f"color-{color}" if color else ""
|
33 |
num_circles = max(3, min(35, len(label) // 4))
|
34 |
circle_size = 60
|
@@ -40,55 +40,20 @@ def cloud_button(label, query, key=None, color=None, overlap=30):
|
|
40 |
circles_html += f'<div class="circle-text">{label}</div>'
|
41 |
|
42 |
cloud_button_html = f"""
|
43 |
-
<div class="cloud" id="{button_id}" style="margin-bottom: 20px;">
|
44 |
<div class="wrapper {color_class}">
|
45 |
{circles_html}
|
46 |
</div>
|
47 |
</div>
|
48 |
-
<style>
|
49 |
-
.cloud {{
|
50 |
-
position: relative;
|
51 |
-
display: inline-flex;
|
52 |
-
align-items: center;
|
53 |
-
justify-content: center;
|
54 |
-
}}
|
55 |
-
.wrapper {{
|
56 |
-
display: flex;
|
57 |
-
align-items: center;
|
58 |
-
justify-content: center;
|
59 |
-
position: relative;
|
60 |
-
padding: 10px 20px;
|
61 |
-
}}
|
62 |
-
.circle {{
|
63 |
-
background-color: #FF6347;
|
64 |
-
border-radius: 50%;
|
65 |
-
width: {circle_size}px;
|
66 |
-
height: {circle_size}px;
|
67 |
-
position: relative;
|
68 |
-
}}
|
69 |
-
.circle-text {{
|
70 |
-
position: absolute;
|
71 |
-
top: 50%;
|
72 |
-
left: 50%;
|
73 |
-
transform: translate(-50%, -50%);
|
74 |
-
font-weight: bold;
|
75 |
-
z-index: 2;
|
76 |
-
white-space: nowrap;
|
77 |
-
text-align: center;
|
78 |
-
}}
|
79 |
-
.cloud:hover .circle {{
|
80 |
-
transform: scale(1.1);
|
81 |
-
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
82 |
-
}}
|
83 |
-
.color-1 .circle {{ background-color: #FFA07A; }}
|
84 |
-
.color-2 .circle {{ background-color: #FF7F50; }}
|
85 |
-
.color-3 .circle {{ background-color: #FF6347; }}
|
86 |
-
</style>
|
87 |
<script>
|
88 |
document.getElementById("{button_id}").onclick = function() {{
|
|
|
|
|
|
|
89 |
window.parent.postMessage({{
|
|
|
90 |
'type': 'streamlit:setComponentValue',
|
91 |
-
'value': {{
|
92 |
'key': 'button_clicked'
|
93 |
}}, '*');
|
94 |
}};
|
@@ -96,6 +61,7 @@ def cloud_button(label, query, key=None, color=None, overlap=30):
|
|
96 |
"""
|
97 |
st.markdown(cloud_button_html, unsafe_allow_html=True)
|
98 |
|
|
|
99 |
def display_chat_history(chat_history):
|
100 |
for sender, msg, _ in chat_history:
|
101 |
background_color = "#FFA07A" if sender == "User" else "#caf"
|
@@ -173,10 +139,16 @@ def main():
|
|
173 |
|
174 |
user_input = st.empty()
|
175 |
|
176 |
-
if "button_clicked" in st.session_state
|
177 |
-
|
178 |
-
|
179 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
180 |
|
181 |
if st.button("Ask"):
|
182 |
user_input = st.session_state.user_query
|
|
|
28 |
|
29 |
|
30 |
def cloud_button(label, query, key=None, color=None, overlap=30):
|
31 |
+
button_id = f"cloud-button-{key or label}".replace(" ", "-")
|
32 |
color_class = f"color-{color}" if color else ""
|
33 |
num_circles = max(3, min(35, len(label) // 4))
|
34 |
circle_size = 60
|
|
|
40 |
circles_html += f'<div class="circle-text">{label}</div>'
|
41 |
|
42 |
cloud_button_html = f"""
|
43 |
+
<div class="cloud" id="{button_id}" style="margin-bottom: 20px; cursor: pointer;">
|
44 |
<div class="wrapper {color_class}">
|
45 |
{circles_html}
|
46 |
</div>
|
47 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
<script>
|
49 |
document.getElementById("{button_id}").onclick = function() {{
|
50 |
+
const query = "{query}";
|
51 |
+
const label = "{label}";
|
52 |
+
const button_id = "{button_id}";
|
53 |
window.parent.postMessage({{
|
54 |
+
'isStreamlitMessage': true,
|
55 |
'type': 'streamlit:setComponentValue',
|
56 |
+
'value': {{'label': label, 'query': query, 'button_id': button_id}},
|
57 |
'key': 'button_clicked'
|
58 |
}}, '*');
|
59 |
}};
|
|
|
61 |
"""
|
62 |
st.markdown(cloud_button_html, unsafe_allow_html=True)
|
63 |
|
64 |
+
|
65 |
def display_chat_history(chat_history):
|
66 |
for sender, msg, _ in chat_history:
|
67 |
background_color = "#FFA07A" if sender == "User" else "#caf"
|
|
|
139 |
|
140 |
user_input = st.empty()
|
141 |
|
142 |
+
if "button_clicked" in st.session_state:
|
143 |
+
button_info = st.session_state["button_clicked"]
|
144 |
+
if button_info:
|
145 |
+
st.write(f"You clicked: {button_info['label']}")
|
146 |
+
st.write(f"Query: {button_info['query']}")
|
147 |
+
# Handle the button click as needed
|
148 |
+
# For example, you can call a function to process the query
|
149 |
+
# process_query(button_info['query'])
|
150 |
+
st.session_state["button_clicked"] = None # Reset after handling
|
151 |
+
|
152 |
|
153 |
if st.button("Ask"):
|
154 |
user_input = st.session_state.user_query
|