Update app.py
Browse files
app.py
CHANGED
@@ -433,171 +433,7 @@ class GenerationManager:
|
|
433 |
|
434 |
# Modifiez votre fonction create_interface comme ceci
|
435 |
def create_interface():
|
436 |
-
|
437 |
-
|
438 |
-
css = """
|
439 |
-
.container { max-width: 1200px; margin: auto; }
|
440 |
-
.welcome { text-align: center; margin: 20px 0; padding: 20px; background: #1e293b; border-radius: 10px; }
|
441 |
-
.controls-group { background: #2d3748; padding: 15px; border-radius: 5px; margin: 10px 0; }
|
442 |
-
.advanced-controls { background: #374151; padding: 12px; border-radius: 5px; margin: 8px 0; }
|
443 |
-
"""
|
444 |
-
|
445 |
-
generator = ImageGenerator()
|
446 |
-
generation_manager = GenerationManager() # Ajout du gestionnaire
|
447 |
-
|
448 |
-
with gr.Blocks(css=css) as app:
|
449 |
-
# [Gardez toute votre interface existante jusqu'à la fin]
|
450 |
-
|
451 |
-
# Ajoutez cet onglet à la fin, avant les boutons de génération
|
452 |
-
with gr.Tab("📜 Historique"):
|
453 |
-
with gr.Row():
|
454 |
-
history_gallery = gr.Gallery(
|
455 |
-
label="Générations Récentes",
|
456 |
-
columns=3,
|
457 |
-
height=400,
|
458 |
-
show_label=True
|
459 |
-
)
|
460 |
-
|
461 |
-
with gr.Row():
|
462 |
-
refresh_btn = gr.Button("🔄 Actualiser")
|
463 |
-
)
|
464 |
-
|
465 |
-
with gr.Row():
|
466 |
-
refresh_btn = gr.Button("🔄 Actualiser")
|
467 |
-
|
468 |
-
# Modification de la fonction generate existante
|
469 |
-
def generate(*args):
|
470 |
-
logger.info("Démarrage d'une nouvelle génération")
|
471 |
-
params = {
|
472 |
-
"format_size": args[0],
|
473 |
-
"orientation": args[1],
|
474 |
-
"style": args[2],
|
475 |
-
"layout": args[3],
|
476 |
-
"ambiance": args[4],
|
477 |
-
"palette": args[5],
|
478 |
-
"subject": args[6],
|
479 |
-
"title": args[7],
|
480 |
-
"detail_level": args[8],
|
481 |
-
"contrast": args[9],
|
482 |
-
"saturation": args[10],
|
483 |
-
"quality": args[11],
|
484 |
-
"creativity": args[12]
|
485 |
-
}
|
486 |
-
result = generator.generate(params)
|
487 |
-
|
488 |
-
# Ajout de la sauvegarde automatique
|
489 |
-
if result[0] is not None:
|
490 |
-
generation_manager.save_generation(result[0], params)
|
491 |
-
|
492 |
-
logger.info(f"Génération terminée avec statut: {result[1]}")
|
493 |
-
return result
|
494 |
-
|
495 |
-
def refresh_history():
|
496 |
-
def refresh_history():
|
497 |
-
recent = generation_manager.get_recent_generations()
|
498 |
-
return gr.Gallery.update(value=[entry["image_path"] for entry in recent])
|
499 |
-
|
500 |
-
refresh_btn.click(
|
501 |
-
refresh_history,
|
502 |
-
outputs=[history_gallery]
|
503 |
-
)
|
504 |
-
|
505 |
-
|
506 |
-
# Connexion des boutons
|
507 |
-
generate_btn.click(
|
508 |
-
generate,
|
509 |
-
inputs=[
|
510 |
-
format_size,
|
511 |
-
orientation,
|
512 |
-
style,
|
513 |
-
layout,
|
514 |
-
ambiance,
|
515 |
-
palette,
|
516 |
-
subject,
|
517 |
-
title,
|
518 |
-
detail_level,
|
519 |
-
contrast,
|
520 |
-
saturation,
|
521 |
-
quality,
|
522 |
-
creativity
|
523 |
-
],
|
524 |
-
outputs=[image_output, status]
|
525 |
-
)
|
526 |
-
|
527 |
-
refresh_btn.click(
|
528 |
-
refresh_history,
|
529 |
-
outputs=[history_gallery]
|
530 |
-
)
|
531 |
-
|
532 |
-
clear_btn.click(
|
533 |
-
lambda: (None, "🗑️ Image effacée"),
|
534 |
-
outputs=[image_output, status]
|
535 |
-
)
|
536 |
-
|
537 |
-
logger.info("Interface créée avec succès")
|
538 |
-
return app
|
539 |
-
# [Gardez tous vos imports existants]
|
540 |
-
# Ajoutez ces imports en haut du fichier
|
541 |
-
from pathlib import Path
|
542 |
-
import time
|
543 |
-
import json
|
544 |
-
from datetime import datetime
|
545 |
-
|
546 |
-
# [Gardez toutes vos configurations existantes (ART_STYLES, etc.)]
|
547 |
-
|
548 |
-
# Ajoutez cette classe juste avant la classe ImageGenerator
|
549 |
-
class GenerationManager:
|
550 |
-
def __init__(self):
|
551 |
-
self.save_dir = Path("generations")
|
552 |
-
self.save_dir.mkdir(exist_ok=True)
|
553 |
-
self.history_file = self.save_dir / "history.json"
|
554 |
-
self.history = self.load_history()
|
555 |
-
|
556 |
-
def load_history(self):
|
557 |
-
if self.history_file.exists():
|
558 |
-
try:
|
559 |
-
with open(self.history_file, "r", encoding="utf-8") as f:
|
560 |
-
return json.load(f)
|
561 |
-
except Exception as e:
|
562 |
-
logger.error(f"Erreur chargement historique: {e}")
|
563 |
-
return []
|
564 |
-
return []
|
565 |
-
|
566 |
-
def save_generation(self, image, params):
|
567 |
-
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
568 |
-
image_name = f"generation_{timestamp}.png"
|
569 |
-
image_path = self.save_dir / image_name
|
570 |
-
|
571 |
-
# Sauvegarde de l'image
|
572 |
-
image.save(image_path)
|
573 |
-
|
574 |
-
# Création de l'entrée
|
575 |
-
entry = {
|
576 |
-
"id": timestamp,
|
577 |
-
"image_path": str(image_path),
|
578 |
-
"params": params,
|
579 |
-
"created_at": timestamp
|
580 |
-
}
|
581 |
-
|
582 |
-
self.history.append(entry)
|
583 |
-
self._save_history()
|
584 |
-
return entry
|
585 |
-
|
586 |
-
def _save_history(self):
|
587 |
-
with open(self.history_file, "w", encoding="utf-8") as f:
|
588 |
-
json.dump(self.history, f, indent=2, ensure_ascii=False)
|
589 |
-
|
590 |
-
def get_recent_generations(self, limit=10):
|
591 |
-
return sorted(
|
592 |
-
self.history,
|
593 |
-
key=lambda x: x["created_at"],
|
594 |
-
reverse=True
|
595 |
-
)[:limit]
|
596 |
-
|
597 |
-
# [Gardez votre classe ImageGenerator existante]
|
598 |
-
|
599 |
-
# Modifiez votre fonction create_interface comme ceci
|
600 |
-
def create_interface():
|
601 |
logger.info("Création de l'interface Gradio")
|
602 |
|
603 |
css = """
|
|
|
433 |
|
434 |
# Modifiez votre fonction create_interface comme ceci
|
435 |
def create_interface():
|
436 |
+
def create_interface():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
437 |
logger.info("Création de l'interface Gradio")
|
438 |
|
439 |
css = """
|