Spaces:
Sleeping
Sleeping
Commit
·
3396761
1
Parent(s):
b11932d
First commit for deployment
Browse files- README.md +1 -0
- prompts.yaml +4 -1
- requirements.txt +2 -1
- streamlit_app.py +154 -161
README.md
CHANGED
@@ -125,6 +125,7 @@ The original Gradio interface is still available:
|
|
125 |
- **Data Visualization**: Request and generate charts directly in the chat
|
126 |
- **Code Execution**: Run Python code generated by the agent within the chat interface
|
127 |
- **Timezone Display**: Check current time in different time zones
|
|
|
128 |
|
129 |
### Agent Tools
|
130 |
|
|
|
125 |
- **Data Visualization**: Request and generate charts directly in the chat
|
126 |
- **Code Execution**: Run Python code generated by the agent within the chat interface
|
127 |
- **Timezone Display**: Check current time in different time zones
|
128 |
+
- **Custom Icon**: Uses a custom ico.webp icon for the application and sidebar
|
129 |
|
130 |
### Agent Tools
|
131 |
|
prompts.yaml
CHANGED
@@ -503,7 +503,10 @@
|
|
503 |
10. Don't give up! You're in charge of solving the task, not providing directions to solve it.
|
504 |
11. When using the final_answer tool, provide Streamlit code as an argument. This code will be rendered as an interactive web application.
|
505 |
12. Always use the validate_final_answer tool before using final_answer to ensure your Streamlit code is valid.
|
506 |
-
13.
|
|
|
|
|
|
|
507 |
|
508 |
Now Begin! If you solve the task correctly, you will receive a reward of $1,000,000.
|
509 |
"planning":
|
|
|
503 |
10. Don't give up! You're in charge of solving the task, not providing directions to solve it.
|
504 |
11. When using the final_answer tool, provide Streamlit code as an argument. This code will be rendered as an interactive web application.
|
505 |
12. Always use the validate_final_answer tool before using final_answer to ensure your Streamlit code is valid.
|
506 |
+
13. DO NOT include in your streamlit code any code related to st.sidebar. It will not be rendered correctly.
|
507 |
+
14. YOU CAN'T AT ANY TIME USE st.sidebar function.
|
508 |
+
14. When writing Streamlit code for the final_answer, make sure to include all necessary imports and provide a complete, standalone application.
|
509 |
+
|
510 |
|
511 |
Now Begin! If you solve the task correctly, you will receive a reward of $1,000,000.
|
512 |
"planning":
|
requirements.txt
CHANGED
@@ -9,4 +9,5 @@ pytz>=2023.3
|
|
9 |
pyyaml>=6.0
|
10 |
plotly>=5.18.0
|
11 |
pandas>=2.0.0
|
12 |
-
numpy>=1.24.0
|
|
|
|
9 |
pyyaml>=6.0
|
10 |
plotly>=5.18.0
|
11 |
pandas>=2.0.0
|
12 |
+
numpy>=1.24.0
|
13 |
+
yfinance>=0.1.70
|
streamlit_app.py
CHANGED
@@ -51,7 +51,7 @@ from visualizations import (
|
|
51 |
|
52 |
# Configure Streamlit page settings
|
53 |
st.set_page_config(
|
54 |
-
page_title="
|
55 |
page_icon="🤖",
|
56 |
layout="wide", # Use wide layout for better display of content
|
57 |
)
|
@@ -77,14 +77,7 @@ def initialize_agent(model_type="openai_server", model_config=None):
|
|
77 |
|
78 |
# Configure the model based on the selected type
|
79 |
if model_type == "openai_server":
|
80 |
-
|
81 |
-
if model_config is None:
|
82 |
-
model_config = {
|
83 |
-
"api_base": "https://openrouter.ai/api/v1",
|
84 |
-
"model_id": "google/gemini-2.0-pro-exp-02-05:free",
|
85 |
-
"api_key": "nop" # Replace with actual API key in production
|
86 |
-
}
|
87 |
-
|
88 |
# Initialize OpenAI-compatible model
|
89 |
model = OpenAIServerModel(
|
90 |
api_base=model_config["api_base"],
|
@@ -148,9 +141,9 @@ def initialize_agent(model_type="openai_server", model_config=None):
|
|
148 |
ValidateFinalAnswer(), # Validates final answers for quality
|
149 |
DuckDuckGoSearchTool(), # Enables web search capabilities
|
150 |
VisitWebpageTool(), # Allows visiting and extracting content from webpages
|
151 |
-
ShellCommandTool(), # Enables execution of shell commands
|
152 |
-
CreateFileTool(), # Allows creation of new files
|
153 |
-
ModifyFileTool() # Enables modification of existing files
|
154 |
],
|
155 |
max_steps=20, # Maximum number of reasoning steps
|
156 |
verbosity_level=1, # Level of detail in agent's output
|
@@ -160,7 +153,7 @@ def initialize_agent(model_type="openai_server", model_config=None):
|
|
160 |
description=None, # Agent description
|
161 |
prompt_templates=prompt_templates, # Custom prompt templates
|
162 |
# Additional Python modules the agent is allowed to import in generated code
|
163 |
-
additional_authorized_imports=["pandas", "numpy", "matplotlib", "seaborn", "plotly", "requests", "yaml"]
|
164 |
)
|
165 |
|
166 |
return agent
|
@@ -341,8 +334,16 @@ def launch_app(code_to_launch):
|
|
341 |
code_to_launch (str): Python code string to be executed
|
342 |
"""
|
343 |
with st.container(border = True):
|
344 |
-
|
345 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
346 |
return
|
347 |
|
348 |
def main():
|
@@ -353,7 +354,7 @@ def main():
|
|
353 |
It's the central orchestrator of the application's functionality.
|
354 |
"""
|
355 |
# Set up the main page title and welcome message
|
356 |
-
st.title("
|
357 |
|
358 |
st.markdown("""
|
359 |
Bienvenue! Cet agent utilise SmoLAgents pour se connecter à un modèle de langage.
|
@@ -362,99 +363,109 @@ def main():
|
|
362 |
|
363 |
# Set up the sidebar for model configuration
|
364 |
with st.sidebar:
|
365 |
-
|
366 |
-
|
367 |
-
#
|
368 |
-
model_type = st.selectbox(
|
369 |
-
"Type de modèle",
|
370 |
-
["openai_server", "hf_api", "hf_cloud"],
|
371 |
-
index=0,
|
372 |
-
help="Choisissez le type de modèle à utiliser avec l'agent"
|
373 |
-
)
|
374 |
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
model_config["api_base"] = st.text_input(
|
383 |
-
"URL du serveur",
|
384 |
-
value="https://openrouter.ai/api/v1",
|
385 |
-
help="Adresse du serveur OpenAI compatible"
|
386 |
-
)
|
387 |
-
# Model ID to use with the server
|
388 |
-
model_config["model_id"] = st.text_input(
|
389 |
-
"ID du modèle",
|
390 |
-
value="google/gemini-2.0-pro-exp-02-05:free",
|
391 |
-
help="Identifiant du modèle local"
|
392 |
-
)
|
393 |
-
# API key for authentication
|
394 |
-
model_config["api_key"] = st.text_input(
|
395 |
-
"Clé API",
|
396 |
-
value=os.getenv("OPEN_ROUTER_TOKEN") or "dummy",
|
397 |
-
type="password",
|
398 |
-
help="Clé API pour le serveur (dummy pour LMStudio)"
|
399 |
)
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
"
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
458 |
|
459 |
# Check server connection for OpenAI server type
|
460 |
if model_type == "openai_server":
|
@@ -464,10 +475,8 @@ def main():
|
|
464 |
# Attempt to connect to the server's health endpoint
|
465 |
import requests
|
466 |
response = requests.get(f"{llm_api_url}/health", timeout=2)
|
467 |
-
if response
|
468 |
st.success("✅ Connexion au serveur LLM établie")
|
469 |
-
else:
|
470 |
-
st.warning("⚠️ Le serveur LLM est accessible mais renvoie un statut non-OK")
|
471 |
except Exception:
|
472 |
st.error("❌ Impossible de se connecter au serveur LLM. Vérifiez que le serveur est en cours d'exécution à l'adresse spécifiée.")
|
473 |
|
@@ -509,60 +518,44 @@ def main():
|
|
509 |
if response and hasattr(response, "model_output"):
|
510 |
st.session_state.messages.append({"role": "assistant", "content": response.model_output})
|
511 |
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
st.
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
|
|
|
|
|
|
|
|
|
|
520 |
|
521 |
# Additional information and features in the sidebar
|
522 |
with st.sidebar:
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
st.markdown("""
|
546 |
-
Vous pouvez demander des visualisations en utilisant des phrases comme:
|
547 |
-
- "Montre-moi un graphique en ligne des températures"
|
548 |
-
- "Crée un diagramme à barres des ventes par région"
|
549 |
-
- "Affiche un nuage de points de l'âge vs revenu"
|
550 |
-
|
551 |
-
L'agent détectera automatiquement votre demande et générera une visualisation appropriée.
|
552 |
-
""")
|
553 |
-
|
554 |
-
# Current time display in different timezones
|
555 |
-
st.subheader("Heure actuelle")
|
556 |
-
# Timezone selection dropdown
|
557 |
-
selected_timezone = st.selectbox(
|
558 |
-
"Choisissez un fuseau horaire",
|
559 |
-
["Europe/Paris", "America/New_York", "Asia/Tokyo", "Australia/Sydney"]
|
560 |
-
)
|
561 |
-
|
562 |
-
# Get and display current time in selected timezone
|
563 |
-
tz = pytz.timezone(selected_timezone)
|
564 |
-
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
565 |
-
st.write(f"L'heure actuelle à {selected_timezone} est: {local_time}")
|
566 |
|
567 |
if __name__ == "__main__":
|
568 |
main()
|
|
|
51 |
|
52 |
# Configure Streamlit page settings
|
53 |
st.set_page_config(
|
54 |
+
page_title="Streamlit generator 🤖",
|
55 |
page_icon="🤖",
|
56 |
layout="wide", # Use wide layout for better display of content
|
57 |
)
|
|
|
77 |
|
78 |
# Configure the model based on the selected type
|
79 |
if model_type == "openai_server":
|
80 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
# Initialize OpenAI-compatible model
|
82 |
model = OpenAIServerModel(
|
83 |
api_base=model_config["api_base"],
|
|
|
141 |
ValidateFinalAnswer(), # Validates final answers for quality
|
142 |
DuckDuckGoSearchTool(), # Enables web search capabilities
|
143 |
VisitWebpageTool(), # Allows visiting and extracting content from webpages
|
144 |
+
# ShellCommandTool(), # Enables execution of shell commands
|
145 |
+
# CreateFileTool(), # Allows creation of new files
|
146 |
+
# ModifyFileTool() # Enables modification of existing files
|
147 |
],
|
148 |
max_steps=20, # Maximum number of reasoning steps
|
149 |
verbosity_level=1, # Level of detail in agent's output
|
|
|
153 |
description=None, # Agent description
|
154 |
prompt_templates=prompt_templates, # Custom prompt templates
|
155 |
# Additional Python modules the agent is allowed to import in generated code
|
156 |
+
additional_authorized_imports=["pandas", "numpy", "matplotlib", "seaborn", "plotly", "requests", "yaml", "yfinance", "datetime", "pytz"]
|
157 |
)
|
158 |
|
159 |
return agent
|
|
|
334 |
code_to_launch (str): Python code string to be executed
|
335 |
"""
|
336 |
with st.container(border = True):
|
337 |
+
app_tab, source_tab = st.tabs(["Application", "Code source"])
|
338 |
+
with app_tab:
|
339 |
+
# Execute the code within a bordered container for visual separation
|
340 |
+
exec(code_to_launch)
|
341 |
+
with source_tab:
|
342 |
+
# Display the generated code for reference
|
343 |
+
st.code(code_to_launch, language="python")
|
344 |
+
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)")
|
345 |
+
|
346 |
+
|
347 |
return
|
348 |
|
349 |
def main():
|
|
|
354 |
It's the central orchestrator of the application's functionality.
|
355 |
"""
|
356 |
# Set up the main page title and welcome message
|
357 |
+
st.title("🤖 Streamlit generator")
|
358 |
|
359 |
st.markdown("""
|
360 |
Bienvenue! Cet agent utilise SmoLAgents pour se connecter à un modèle de langage.
|
|
|
363 |
|
364 |
# Set up the sidebar for model configuration
|
365 |
with st.sidebar:
|
366 |
+
# Display the application icon
|
367 |
+
st.title("🤖 Streamlit generator")
|
368 |
+
# st.image("ico.webp", width=100, caption="SmoLAgents Icon")
|
|
|
|
|
|
|
|
|
|
|
|
|
369 |
|
370 |
+
with st.expander("🛠️ Configuration du Modèle", expanded=True):
|
371 |
+
# Model type selection dropdown
|
372 |
+
model_type = st.selectbox(
|
373 |
+
"Type de modèle",
|
374 |
+
["Par défaut", "openai_server", "hf_api", "hf_cloud"],
|
375 |
+
index=0,
|
376 |
+
help="Choisissez le type de modèle à utiliser avec l'agent"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
377 |
)
|
378 |
+
|
379 |
+
# Initialize empty configuration dictionary
|
380 |
+
model_config = {}
|
381 |
+
if model_type == "Par défaut":
|
382 |
+
st.success("Modèle par défaut 🟢")
|
383 |
+
|
384 |
+
model_config["api_base"] = "https://generativelanguage.googleapis.com/v1beta/openai/"
|
385 |
+
model_config["model_id"] = "gemini-2.0-pro-exp-02-05"
|
386 |
+
model_config["api_key"] = st.secrets["API_GEMINI_KEY"] #os.getenv("OPEN_ROUTER_TOKEN") or "dummy",
|
387 |
+
model_type = "openai_server"
|
388 |
+
|
389 |
+
# Dynamic configuration UI based on selected model type
|
390 |
+
elif model_type == "openai_server":
|
391 |
+
st.subheader("Configuration OpenAI Server")
|
392 |
+
# OpenAI-compatible server URL (OpenRouter, LMStudio, etc.)
|
393 |
+
model_config["api_base"] = st.text_input(
|
394 |
+
"URL du serveur",
|
395 |
+
value="https://openrouter.ai/api/v1",
|
396 |
+
help="Adresse du serveur OpenAI compatible"
|
397 |
+
)
|
398 |
+
# Model ID to use with the server
|
399 |
+
model_config["model_id"] = st.text_input(
|
400 |
+
"ID du modèle",
|
401 |
+
value="google/gemini-2.0-pro-exp-02-05:free",
|
402 |
+
help="Identifiant du modèle local"
|
403 |
+
)
|
404 |
+
# API key for authentication
|
405 |
+
model_config["api_key"] = st.text_input(
|
406 |
+
"Clé API",
|
407 |
+
value=os.getenv("OPEN_ROUTER_TOKEN") or "dummy",
|
408 |
+
type="password",
|
409 |
+
help="Clé API pour le serveur (dummy pour LMStudio)"
|
410 |
+
)
|
411 |
+
|
412 |
+
elif model_type == "hf_api":
|
413 |
+
st.subheader("Configuration Hugging Face API")
|
414 |
+
# Hugging Face API endpoint URL
|
415 |
+
model_config["model_id"] = st.text_input(
|
416 |
+
"URL du modèle",
|
417 |
+
value="http://192.168.1.141:1234/v1",
|
418 |
+
help="URL du modèle ou endpoint"
|
419 |
+
)
|
420 |
+
# Maximum tokens to generate in responses
|
421 |
+
model_config["max_new_tokens"] = st.slider(
|
422 |
+
"Tokens maximum",
|
423 |
+
min_value=512,
|
424 |
+
max_value=4096,
|
425 |
+
value=2096,
|
426 |
+
help="Nombre maximum de tokens à générer"
|
427 |
+
)
|
428 |
+
# Temperature controls randomness in generation
|
429 |
+
model_config["temperature"] = st.slider(
|
430 |
+
"Température",
|
431 |
+
min_value=0.1,
|
432 |
+
max_value=1.0,
|
433 |
+
value=0.5,
|
434 |
+
step=0.1,
|
435 |
+
help="Température pour la génération (plus élevée = plus créatif)"
|
436 |
+
)
|
437 |
+
|
438 |
+
elif model_type == "hf_cloud":
|
439 |
+
st.subheader("Configuration Hugging Face Cloud")
|
440 |
+
# Hugging Face cloud endpoint URL
|
441 |
+
model_config["model_id"] = st.text_input(
|
442 |
+
"URL du endpoint cloud",
|
443 |
+
value="https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud",
|
444 |
+
help="URL de l'endpoint cloud Hugging Face"
|
445 |
+
)
|
446 |
+
# Maximum tokens to generate in responses
|
447 |
+
model_config["max_new_tokens"] = st.slider(
|
448 |
+
"Tokens maximum",
|
449 |
+
min_value=512,
|
450 |
+
max_value=4096,
|
451 |
+
value=2096,
|
452 |
+
help="Nombre maximum de tokens à générer"
|
453 |
+
)
|
454 |
+
# Temperature controls randomness in generation
|
455 |
+
model_config["temperature"] = st.slider(
|
456 |
+
"Température",
|
457 |
+
min_value=0.1,
|
458 |
+
max_value=1.0,
|
459 |
+
value=0.5,
|
460 |
+
step=0.1,
|
461 |
+
help="Température pour la génération (plus élevée = plus créatif)"
|
462 |
+
)
|
463 |
+
|
464 |
+
# Button to apply configuration changes and reinitialize the agent
|
465 |
+
if st.button("Appliquer la configuration"):
|
466 |
+
with st.spinner("Initialisation de l'agent avec le nouveau modèle..."):
|
467 |
+
st.session_state.agent = initialize_agent(model_type, model_config)
|
468 |
+
st.success("✅ Configuration appliquée avec succès!")
|
469 |
|
470 |
# Check server connection for OpenAI server type
|
471 |
if model_type == "openai_server":
|
|
|
475 |
# Attempt to connect to the server's health endpoint
|
476 |
import requests
|
477 |
response = requests.get(f"{llm_api_url}/health", timeout=2)
|
478 |
+
if response:
|
479 |
st.success("✅ Connexion au serveur LLM établie")
|
|
|
|
|
480 |
except Exception:
|
481 |
st.error("❌ Impossible de se connecter au serveur LLM. Vérifiez que le serveur est en cours d'exécution à l'adresse spécifiée.")
|
482 |
|
|
|
518 |
if response and hasattr(response, "model_output"):
|
519 |
st.session_state.messages.append({"role": "assistant", "content": response.model_output})
|
520 |
|
521 |
+
|
522 |
+
# Additional information and features in the sidebar
|
523 |
+
with st.sidebar:
|
524 |
+
with st.container(border = True):
|
525 |
+
st.markdown(f"🤖 Modèle sélectionné: \n\n `{model_config["model_id"]}`")
|
526 |
+
# Button to clear conversation history and start a new chat
|
527 |
+
if st.button("Nouvelle conversation"):
|
528 |
+
# Reset conversation to initial greeting
|
529 |
+
st.session_state.messages = [
|
530 |
+
{"role": "assistant", "content": "Bonjour! Comment puis-je vous aider aujourd'hui?"}
|
531 |
+
]
|
532 |
+
# Reload the page to reset the UI
|
533 |
+
st.rerun()
|
534 |
|
535 |
# Additional information and features in the sidebar
|
536 |
with st.sidebar:
|
537 |
+
with st.container(border = True):
|
538 |
+
|
539 |
+
# About section with information about the agent
|
540 |
+
st.title("❓ À propos")
|
541 |
+
st.markdown("""
|
542 |
+
|
543 |
+
Cet agent utilise la librairie SmoLAgents pour vous aider à générer l'application streamlit de vos rêves ✨.
|
544 |
+
|
545 |
+
Essayer par vous même ! Vous pouvez demander des visualisations en utilisant des phrases comme:
|
546 |
+
- "Montre-moi un graphique en ligne des températures"
|
547 |
+
- "Crée un diagramme à barres des ventes par région"
|
548 |
+
- "Affiche un nuage de points de l'âge vs revenu"
|
549 |
+
|
550 |
+
L'agent détectera automatiquement votre demande et générera une visualisation appropriée.
|
551 |
+
""")
|
552 |
+
with st.container(border = True):
|
553 |
+
st.title("🚧 Aide 🚧")
|
554 |
+
st.markdown("""
|
555 |
+
- Si l'agent ne répond pas, vérifiez que l'agent est bien connecté.
|
556 |
+
- Assurez-vous qu'il vous reste suffisamment de crédit si vous utilisez un agent personnalisé !
|
557 |
+
- Essayer de générer une application moins complexe ou d'améliorer votre prompt.""")
|
558 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
559 |
|
560 |
if __name__ == "__main__":
|
561 |
main()
|