Spaces:
Sleeping
Sleeping
Commit
·
3797534
1
Parent(s):
d44d28a
update better streamlit control
Browse files- streamlit_app.py +31 -11
streamlit_app.py
CHANGED
|
@@ -33,7 +33,6 @@ from tools.web_search import DuckDuckGoSearchTool
|
|
| 33 |
from tools.shell_tool import ShellCommandTool
|
| 34 |
from tools.create_file_tool import CreateFileTool
|
| 35 |
from tools.modify_file_tool import ModifyFileTool
|
| 36 |
-
|
| 37 |
# # Telemetry imports (currently disabled)
|
| 38 |
# from phoenix.otel import register
|
| 39 |
# from openinference.instrumentation.smolagents import SmolagentsInstrumentor
|
|
@@ -56,7 +55,7 @@ st.set_page_config(
|
|
| 56 |
layout="wide", # Use wide layout for better display of content
|
| 57 |
)
|
| 58 |
|
| 59 |
-
def initialize_agent(model_type="openai_server", model_config=None):
|
| 60 |
"""Initialize the agent with the specified model and tools.
|
| 61 |
|
| 62 |
This function creates a SmoLAgents CodeAgent instance with the specified language model
|
|
@@ -70,6 +69,8 @@ def initialize_agent(model_type="openai_server", model_config=None):
|
|
| 70 |
- 'hf_cloud': For Hugging Face cloud endpoints
|
| 71 |
model_config (dict, optional): Configuration dictionary for the model.
|
| 72 |
If None, default configurations will be used.
|
|
|
|
|
|
|
| 73 |
|
| 74 |
Returns:
|
| 75 |
CodeAgent: Initialized agent instance, or None if model type is not supported
|
|
@@ -145,7 +146,7 @@ def initialize_agent(model_type="openai_server", model_config=None):
|
|
| 145 |
# CreateFileTool(), # Allows creation of new files
|
| 146 |
# ModifyFileTool() # Enables modification of existing files
|
| 147 |
],
|
| 148 |
-
max_steps=
|
| 149 |
verbosity_level=1, # Level of detail in agent's output
|
| 150 |
grammar=None, # Optional grammar for structured output
|
| 151 |
planning_interval=None, # How often to re-plan (None = no explicit planning)
|
|
@@ -283,25 +284,34 @@ def process_user_input(agent, user_input):
|
|
| 283 |
with response_container:
|
| 284 |
step_container = st.empty()
|
| 285 |
step_text = ""
|
|
|
|
|
|
|
| 286 |
|
| 287 |
# Execute the agent and stream results incrementally
|
| 288 |
for step in agent.run(user_input, stream=True):
|
| 289 |
steps.append(step)
|
| 290 |
|
| 291 |
# Format the current step for display
|
| 292 |
-
|
|
|
|
| 293 |
step_content = format_step_message(step)
|
| 294 |
|
| 295 |
-
#
|
|
|
|
|
|
|
|
|
|
| 296 |
if step_number:
|
| 297 |
-
step_text += f"
|
| 298 |
-
|
|
|
|
|
|
|
| 299 |
|
| 300 |
# Update the display with the latest step information
|
| 301 |
-
|
| 302 |
|
| 303 |
# Keep track of the final step for the response
|
| 304 |
final_step = step
|
|
|
|
| 305 |
|
| 306 |
# Process and return the final answer
|
| 307 |
if final_step:
|
|
@@ -345,6 +355,7 @@ def launch_app(code_to_launch):
|
|
| 345 |
with source_tab:
|
| 346 |
# Display the generated code for reference
|
| 347 |
st.code(code_to_launch, language="python")
|
|
|
|
| 348 |
st.info("Pour mettre en ligne votre application suivre le lien suivant : [Export Streamlit App](https://docs.streamlit.io/deploy/streamlit-community-cloud/deploy-your-app)")
|
| 349 |
|
| 350 |
|
|
@@ -371,7 +382,7 @@ def main():
|
|
| 371 |
st.title("🤖 Streamlit generator")
|
| 372 |
# st.image("ico.webp", width=100, caption="SmoLAgents Icon")
|
| 373 |
|
| 374 |
-
with st.expander("🛠️ Configuration du Modèle", expanded=True):
|
| 375 |
# Model type selection dropdown
|
| 376 |
model_type = st.selectbox(
|
| 377 |
"Type de modèle",
|
|
@@ -380,6 +391,15 @@ def main():
|
|
| 380 |
help="Choisissez le type de modèle à utiliser avec l'agent"
|
| 381 |
)
|
| 382 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 383 |
# Initialize empty configuration dictionary
|
| 384 |
model_config = {}
|
| 385 |
if model_type == "Par défaut":
|
|
@@ -468,7 +488,7 @@ def main():
|
|
| 468 |
# Button to apply configuration changes and reinitialize the agent
|
| 469 |
if st.button("Appliquer la configuration"):
|
| 470 |
with st.spinner("Initialisation de l'agent avec le nouveau modèle..."):
|
| 471 |
-
st.session_state.agent = initialize_agent(model_type, model_config)
|
| 472 |
st.success("✅ Configuration appliquée avec succès!")
|
| 473 |
|
| 474 |
# Check server connection for OpenAI server type
|
|
@@ -487,7 +507,7 @@ def main():
|
|
| 487 |
# Initialize the agent if not already in session state
|
| 488 |
if "agent" not in st.session_state:
|
| 489 |
with st.spinner("Initialisation de l'agent..."):
|
| 490 |
-
st.session_state.agent = initialize_agent(model_type, model_config)
|
| 491 |
|
| 492 |
# Initialize conversation history if not already in session state
|
| 493 |
if "messages" not in st.session_state:
|
|
|
|
| 33 |
from tools.shell_tool import ShellCommandTool
|
| 34 |
from tools.create_file_tool import CreateFileTool
|
| 35 |
from tools.modify_file_tool import ModifyFileTool
|
|
|
|
| 36 |
# # Telemetry imports (currently disabled)
|
| 37 |
# from phoenix.otel import register
|
| 38 |
# from openinference.instrumentation.smolagents import SmolagentsInstrumentor
|
|
|
|
| 55 |
layout="wide", # Use wide layout for better display of content
|
| 56 |
)
|
| 57 |
|
| 58 |
+
def initialize_agent(model_type="openai_server", model_config=None, max_steps=10):
|
| 59 |
"""Initialize the agent with the specified model and tools.
|
| 60 |
|
| 61 |
This function creates a SmoLAgents CodeAgent instance with the specified language model
|
|
|
|
| 69 |
- 'hf_cloud': For Hugging Face cloud endpoints
|
| 70 |
model_config (dict, optional): Configuration dictionary for the model.
|
| 71 |
If None, default configurations will be used.
|
| 72 |
+
max_steps (int, optional): Maximum number of reasoning steps for the agent.
|
| 73 |
+
Default is 10.
|
| 74 |
|
| 75 |
Returns:
|
| 76 |
CodeAgent: Initialized agent instance, or None if model type is not supported
|
|
|
|
| 146 |
# CreateFileTool(), # Allows creation of new files
|
| 147 |
# ModifyFileTool() # Enables modification of existing files
|
| 148 |
],
|
| 149 |
+
max_steps=max_steps, # Maximum number of reasoning steps
|
| 150 |
verbosity_level=1, # Level of detail in agent's output
|
| 151 |
grammar=None, # Optional grammar for structured output
|
| 152 |
planning_interval=None, # How often to re-plan (None = no explicit planning)
|
|
|
|
| 284 |
with response_container:
|
| 285 |
step_container = st.empty()
|
| 286 |
step_text = ""
|
| 287 |
+
# Get the maximum steps from the agent
|
| 288 |
+
max_steps = agent.max_steps
|
| 289 |
|
| 290 |
# Execute the agent and stream results incrementally
|
| 291 |
for step in agent.run(user_input, stream=True):
|
| 292 |
steps.append(step)
|
| 293 |
|
| 294 |
# Format the current step for display
|
| 295 |
+
current_step_num = step.step_number if hasattr(step, "step_number") and step.step_number is not None else 0
|
| 296 |
+
step_number = f"Étape {current_step_num}" if current_step_num else ""
|
| 297 |
step_content = format_step_message(step)
|
| 298 |
|
| 299 |
+
# Add a gray progress indicator
|
| 300 |
+
progress_indicator = f"<span style='color:gray; font-size:0.8em;'>Progression: Étape {current_step_num} sur {max_steps} maximum</span>"
|
| 301 |
+
|
| 302 |
+
# # Build the cumulative step text
|
| 303 |
if step_number:
|
| 304 |
+
step_text += f"{progress_indicator}\n\n"
|
| 305 |
+
# else:
|
| 306 |
+
# step_text += f"{progress_indicator}\n\n"
|
| 307 |
+
# step_text += f"{step_content}\n\n---\n\n"
|
| 308 |
|
| 309 |
# Update the display with the latest step information
|
| 310 |
+
step_container.markdown(step_text, unsafe_allow_html=True)
|
| 311 |
|
| 312 |
# Keep track of the final step for the response
|
| 313 |
final_step = step
|
| 314 |
+
final_step = step
|
| 315 |
|
| 316 |
# Process and return the final answer
|
| 317 |
if final_step:
|
|
|
|
| 355 |
with source_tab:
|
| 356 |
# Display the generated code for reference
|
| 357 |
st.code(code_to_launch, language="python")
|
| 358 |
+
st.download_button("Télécharger le code", str(code_to_launch), "generated_code.py", help="Télécharger le code généré")
|
| 359 |
st.info("Pour mettre en ligne votre application suivre le lien suivant : [Export Streamlit App](https://docs.streamlit.io/deploy/streamlit-community-cloud/deploy-your-app)")
|
| 360 |
|
| 361 |
|
|
|
|
| 382 |
st.title("🤖 Streamlit generator")
|
| 383 |
# st.image("ico.webp", width=100, caption="SmoLAgents Icon")
|
| 384 |
|
| 385 |
+
with st.expander("🛠️ Configuration du Modèle", expanded=True):
|
| 386 |
# Model type selection dropdown
|
| 387 |
model_type = st.selectbox(
|
| 388 |
"Type de modèle",
|
|
|
|
| 391 |
help="Choisissez le type de modèle à utiliser avec l'agent"
|
| 392 |
)
|
| 393 |
|
| 394 |
+
# Configure maximum steps for the agent
|
| 395 |
+
max_steps = st.slider(
|
| 396 |
+
"Nombre maximum d'étapes",
|
| 397 |
+
min_value=1,
|
| 398 |
+
max_value=20,
|
| 399 |
+
value=10,
|
| 400 |
+
help="Nombre maximum d'étapes de raisonnement pour l'agent"
|
| 401 |
+
)
|
| 402 |
+
|
| 403 |
# Initialize empty configuration dictionary
|
| 404 |
model_config = {}
|
| 405 |
if model_type == "Par défaut":
|
|
|
|
| 488 |
# Button to apply configuration changes and reinitialize the agent
|
| 489 |
if st.button("Appliquer la configuration"):
|
| 490 |
with st.spinner("Initialisation de l'agent avec le nouveau modèle..."):
|
| 491 |
+
st.session_state.agent = initialize_agent(model_type, model_config, max_steps)
|
| 492 |
st.success("✅ Configuration appliquée avec succès!")
|
| 493 |
|
| 494 |
# Check server connection for OpenAI server type
|
|
|
|
| 507 |
# Initialize the agent if not already in session state
|
| 508 |
if "agent" not in st.session_state:
|
| 509 |
with st.spinner("Initialisation de l'agent..."):
|
| 510 |
+
st.session_state.agent = initialize_agent(model_type, model_config, max_steps)
|
| 511 |
|
| 512 |
# Initialize conversation history if not already in session state
|
| 513 |
if "messages" not in st.session_state:
|