Initial commit
This commit is contained in:
277
generer_taches_demo.py
Executable file
277
generer_taches_demo.py
Executable file
@@ -0,0 +1,277 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Script pour générer des tâches de démonstration dans RPA Vision V2.
|
||||
Crée des tâches fictives avec embeddings pour tester le système de suggestions.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
import numpy as np
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
# Ajouter le chemin vers geniusia2
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'geniusia2'))
|
||||
|
||||
from core.logger import Logger
|
||||
from core.embeddings_manager import EmbeddingsManager
|
||||
from core.learning_manager import LearningManager
|
||||
from core.config import get_config, ensure_directories
|
||||
from PIL import Image
|
||||
import cv2
|
||||
|
||||
|
||||
def creer_image_demo(texte: str, couleur=(100, 150, 200)) -> np.ndarray:
|
||||
"""
|
||||
Crée une image de démonstration avec du texte.
|
||||
|
||||
Args:
|
||||
texte: Texte à afficher
|
||||
couleur: Couleur de fond (BGR)
|
||||
|
||||
Returns:
|
||||
Image numpy array
|
||||
"""
|
||||
# Créer une image 400x300
|
||||
img = np.zeros((300, 400, 3), dtype=np.uint8)
|
||||
img[:] = couleur
|
||||
|
||||
# Ajouter du texte
|
||||
font = cv2.FONT_HERSHEY_SIMPLEX
|
||||
cv2.putText(img, texte, (50, 150), font, 1, (255, 255, 255), 2, cv2.LINE_AA)
|
||||
|
||||
return img
|
||||
|
||||
|
||||
def generer_taches_demo():
|
||||
"""Génère des tâches de démonstration."""
|
||||
|
||||
print("🎨 Génération de tâches de démonstration...")
|
||||
print("=" * 60)
|
||||
|
||||
# Initialiser les composants
|
||||
print("\n1. Initialisation des composants...")
|
||||
ensure_directories()
|
||||
|
||||
config = get_config()
|
||||
logger = Logger()
|
||||
embeddings_manager = EmbeddingsManager(logger=logger)
|
||||
learning_manager = LearningManager(embeddings_manager, logger, config)
|
||||
|
||||
print(" ✓ Composants initialisés")
|
||||
|
||||
# Définir les tâches de démonstration
|
||||
taches_demo = [
|
||||
{
|
||||
"nom": "Ouvrir Calculatrice",
|
||||
"description": "Ouvre l'application calculatrice",
|
||||
"actions": [
|
||||
{"type": "key_press", "key": "super", "texte": "Menu"},
|
||||
{"type": "key_press", "key": "c", "texte": "Calc"},
|
||||
{"type": "key_press", "key": "enter", "texte": "Enter"}
|
||||
],
|
||||
"couleur": (100, 150, 200)
|
||||
},
|
||||
{
|
||||
"nom": "Calcul Simple",
|
||||
"description": "Effectue un calcul simple (2+2)",
|
||||
"actions": [
|
||||
{"type": "mouse_click", "x": 150, "y": 200, "texte": "Bouton 2"},
|
||||
{"type": "mouse_click", "x": 200, "y": 250, "texte": "Bouton +"},
|
||||
{"type": "mouse_click", "x": 150, "y": 200, "texte": "Bouton 2"},
|
||||
{"type": "mouse_click", "x": 250, "y": 250, "texte": "Bouton ="}
|
||||
],
|
||||
"couleur": (150, 100, 200)
|
||||
},
|
||||
{
|
||||
"nom": "Ouvrir Navigateur",
|
||||
"description": "Ouvre le navigateur web",
|
||||
"actions": [
|
||||
{"type": "key_press", "key": "super", "texte": "Menu"},
|
||||
{"type": "key_press", "key": "f", "texte": "Firefox"},
|
||||
{"type": "key_press", "key": "enter", "texte": "Enter"}
|
||||
],
|
||||
"couleur": (200, 150, 100)
|
||||
},
|
||||
{
|
||||
"nom": "Recherche Google",
|
||||
"description": "Effectue une recherche sur Google",
|
||||
"actions": [
|
||||
{"type": "mouse_click", "x": 400, "y": 100, "texte": "Barre recherche"},
|
||||
{"type": "key_press", "key": "r", "texte": "RPA"},
|
||||
{"type": "key_press", "key": "p", "texte": ""},
|
||||
{"type": "key_press", "key": "a", "texte": ""},
|
||||
{"type": "key_press", "key": "enter", "texte": "Rechercher"}
|
||||
],
|
||||
"couleur": (100, 200, 150)
|
||||
},
|
||||
{
|
||||
"nom": "Fermer Fenêtre",
|
||||
"description": "Ferme la fenêtre active",
|
||||
"actions": [
|
||||
{"type": "key_press", "key": "alt+f4", "texte": "Alt+F4"}
|
||||
],
|
||||
"couleur": (200, 100, 100)
|
||||
}
|
||||
]
|
||||
|
||||
print(f"\n2. Création de {len(taches_demo)} tâches de démonstration...")
|
||||
|
||||
taches_creees = []
|
||||
|
||||
for i, tache_def in enumerate(taches_demo, 1):
|
||||
print(f"\n 📝 Tâche {i}/{len(taches_demo)}: {tache_def['nom']}")
|
||||
|
||||
# Créer les signatures pour chaque action
|
||||
signatures = []
|
||||
|
||||
for j, action in enumerate(tache_def['actions']):
|
||||
# Créer une image de démonstration
|
||||
img = creer_image_demo(action['texte'], tache_def['couleur'])
|
||||
|
||||
# Générer l'embedding
|
||||
embedding = embeddings_manager.encode_image(img)
|
||||
|
||||
# Créer la signature
|
||||
signature = {
|
||||
"action_type": action['type'],
|
||||
"x": action.get('x', 0),
|
||||
"y": action.get('y', 0),
|
||||
"key": action.get('key', ''),
|
||||
"embedding": embedding,
|
||||
"screenshot": img,
|
||||
"window": "Demo Window",
|
||||
"timestamp": datetime.now().isoformat()
|
||||
}
|
||||
|
||||
signatures.append(signature)
|
||||
print(f" ✓ Action {j+1}: {action['type']} - {action['texte']}")
|
||||
|
||||
# Créer la tâche
|
||||
try:
|
||||
task = learning_manager.create_task_from_signatures(
|
||||
signatures,
|
||||
description=tache_def['nom']
|
||||
)
|
||||
|
||||
# Marquer comme observée plusieurs fois pour permettre le rejeu
|
||||
for _ in range(25): # Plus que le seuil de 20
|
||||
task.observation_count += 1
|
||||
|
||||
# Sauvegarder (méthode privée mais accessible)
|
||||
learning_manager._save_task(task)
|
||||
|
||||
taches_creees.append(task)
|
||||
print(f" ✅ Tâche créée: {task.task_id}")
|
||||
print(f" Observations: {task.observation_count}")
|
||||
|
||||
except Exception as e:
|
||||
print(f" ❌ Erreur: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
# Sauvegarder l'index FAISS
|
||||
print(f"\n3. Sauvegarde de l'index FAISS...")
|
||||
try:
|
||||
embeddings_manager.save_index()
|
||||
print(" ✓ Index FAISS sauvegardé")
|
||||
except Exception as e:
|
||||
print(f" ⚠️ Erreur lors de la sauvegarde: {e}")
|
||||
|
||||
# Résumé
|
||||
print("\n" + "=" * 60)
|
||||
print("✅ GÉNÉRATION TERMINÉE")
|
||||
print("=" * 60)
|
||||
print(f"\n📊 Résumé:")
|
||||
print(f" - Tâches créées: {len(taches_creees)}")
|
||||
print(f" - Embeddings générés: {sum(len(t.signatures) for t in taches_creees)}")
|
||||
print(f" - Index FAISS: {embeddings_manager.faiss_index.ntotal} embeddings")
|
||||
|
||||
print(f"\n💡 Prochaines étapes:")
|
||||
print(f" 1. Lancez l'application: cd geniusia2 && ./run.sh")
|
||||
print(f" 2. L'application devrait maintenant avoir des tâches à suggérer")
|
||||
print(f" 3. Effectuez des actions similaires pour voir les suggestions")
|
||||
|
||||
print(f"\n📁 Fichiers créés:")
|
||||
print(f" - geniusia2/data/embeddings/faiss_index.bin")
|
||||
print(f" - geniusia2/data/embeddings/metadata.pkl")
|
||||
print(f" - geniusia2/data/tasks/*.json")
|
||||
|
||||
return taches_creees
|
||||
|
||||
|
||||
def verifier_taches():
|
||||
"""Vérifie les tâches créées."""
|
||||
print("\n🔍 Vérification des tâches créées...")
|
||||
print("=" * 60)
|
||||
|
||||
try:
|
||||
config = get_config()
|
||||
logger = Logger()
|
||||
embeddings_manager = EmbeddingsManager(logger=logger)
|
||||
learning_manager = LearningManager(embeddings_manager, logger, config)
|
||||
|
||||
# Lister les tâches
|
||||
tasks = learning_manager.get_all_tasks()
|
||||
|
||||
print(f"\n📋 Tâches disponibles: {len(tasks)}")
|
||||
|
||||
for i, task in enumerate(tasks, 1):
|
||||
print(f"\n {i}. {task.task_name}")
|
||||
print(f" ID: {task.task_id}")
|
||||
print(f" Actions: {len(task.signatures)}")
|
||||
print(f" Observations: {task.observation_count}")
|
||||
print(f" Prêt pour rejeu: {'✅ Oui' if task.observation_count >= 20 else '❌ Non'}")
|
||||
|
||||
# Vérifier l'index FAISS
|
||||
print(f"\n📊 Index FAISS:")
|
||||
print(f" - Embeddings: {embeddings_manager.faiss_index.ntotal}")
|
||||
print(f" - Métadonnées: {len(embeddings_manager.metadata_store)}")
|
||||
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
print(f"\n❌ Erreur lors de la vérification: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return False
|
||||
|
||||
|
||||
def main():
|
||||
"""Point d'entrée principal."""
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser(description='Génère des tâches de démonstration')
|
||||
parser.add_argument(
|
||||
'--verifier',
|
||||
action='store_true',
|
||||
help='Vérifie les tâches existantes au lieu de les créer'
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
if args.verifier:
|
||||
verifier_taches()
|
||||
else:
|
||||
taches = generer_taches_demo()
|
||||
|
||||
# Vérification automatique
|
||||
if taches:
|
||||
print("\n")
|
||||
verifier_taches()
|
||||
|
||||
print("\n✅ Script terminé avec succès!")
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("\n\n⚠️ Interruption par l'utilisateur")
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(f"\n❌ Erreur fatale: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user