forked from jgravelle/AutoGroq
-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
custom_button.py
59 lines (50 loc) · 1.99 KB
/
custom_button.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# TeamForgeAI/custom_button.py
import streamlit.components.v1 as components
def custom_button(expert_name: str, index: int, next_agent: str) -> None:
"""
Generate a custom button with specific styles and behaviors.
Args:
expert_name (str): The text to display on the button.
index (int): Unused in this implementation, but could be used for indexing or sorting purposes.
next_agent (str): The next agent to highlight as active.
Returns: None
"""
# Create a CSS style block with two classes: .custom-button and .custom-button.active
button_style = """
<style>
.custom-button {
background-color: #f0f0f0;
color: black;
padding: 0rem 0.3rem;
border: none;
border-radius: 0.25rem;
cursor: pointer;
}
.custom-button.active {
background-color: green;
color: white;
}
</style>
"""
# Determine the class name for the button based on whether it's the active agent or not
button_class = "custom-button active" if next_agent == expert_name else "custom-button"
# Generate an HTML button element with the specified text and class name
button_html = f'<button class="{button_class}">{expert_name}</button>'
# Render the HTML code for the button using Streamlit's components.html function
try:
components.html(button_style + button_html, height=50)
except Exception as e:
print(f"Error in custom_button: {e}")
def agent_button(expert_name: str, index: int, next_agent: str) -> None:
"""
Call the custom_button function to generate a custom button.
Args:
expert_name (str): The text to display on the button.
index (int): Unused in this implementation, but could be used for indexing or sorting purposes.
next_agent (str): The next agent to highlight as active.
Returns: None
"""
try:
custom_button(expert_name, index, next_agent)
except Exception as e:
print(f"Error in agent_button: {e}")