Spaces:
Sleeping
Sleeping
Added model warmup
Browse files
app.py
CHANGED
|
@@ -565,6 +565,25 @@ def clear_chat():
|
|
| 565 |
system_prompt_initialized = False
|
| 566 |
return [], ""
|
| 567 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 568 |
# --- UI: Interface Creation ---
|
| 569 |
def create_interface():
|
| 570 |
"""Creates and configures the complete Gradio interface."""
|
|
@@ -634,9 +653,24 @@ def create_interface():
|
|
| 634 |
return demo
|
| 635 |
|
| 636 |
# --- Main Execution ---
|
|
|
|
| 637 |
if __name__ == "__main__":
|
| 638 |
try:
|
| 639 |
-
logger.info("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 640 |
interface = create_interface()
|
| 641 |
interface.queue()
|
| 642 |
interface.launch(
|
|
@@ -645,5 +679,7 @@ if __name__ == "__main__":
|
|
| 645 |
debug=True,
|
| 646 |
favicon_path="assets/favicon.ico"
|
| 647 |
)
|
|
|
|
| 648 |
except Exception as e:
|
| 649 |
-
logger.error(f"Failed to launch Mimir: {e}")
|
|
|
|
|
|
| 565 |
system_prompt_initialized = False
|
| 566 |
return [], ""
|
| 567 |
|
| 568 |
+
def warmup_agent():
|
| 569 |
+
"""Warm up the agent with a test query to preload everything."""
|
| 570 |
+
logger.info("Warming up agent with test query...")
|
| 571 |
+
try:
|
| 572 |
+
current_agent = get_agent()
|
| 573 |
+
|
| 574 |
+
# Initialize system prompt
|
| 575 |
+
initialize_system_prompt(current_agent)
|
| 576 |
+
|
| 577 |
+
# Run a simple test query
|
| 578 |
+
test_response = current_agent.run(input="Hello, this is a warmup test.")
|
| 579 |
+
logger.info(f"Agent warmup completed successfully! Test response length: {len(test_response)} chars")
|
| 580 |
+
|
| 581 |
+
# Clear the test interaction from memory
|
| 582 |
+
current_agent.memory.clear()
|
| 583 |
+
|
| 584 |
+
except Exception as e:
|
| 585 |
+
logger.error(f"Agent warmup failed: {e}")
|
| 586 |
+
|
| 587 |
# --- UI: Interface Creation ---
|
| 588 |
def create_interface():
|
| 589 |
"""Creates and configures the complete Gradio interface."""
|
|
|
|
| 653 |
return demo
|
| 654 |
|
| 655 |
# --- Main Execution ---
|
| 656 |
+
# At the end of your app.py file, replace the main execution block:
|
| 657 |
if __name__ == "__main__":
|
| 658 |
try:
|
| 659 |
+
logger.info("=" * 50)
|
| 660 |
+
logger.info("Starting Mimir Application")
|
| 661 |
+
logger.info("=" * 50)
|
| 662 |
+
|
| 663 |
+
# Step 1: Preload the model and agent
|
| 664 |
+
logger.info("Loading AI model...")
|
| 665 |
+
start_time = time.time()
|
| 666 |
+
agent = create_langchain_agent()
|
| 667 |
+
load_time = time.time() - start_time
|
| 668 |
+
logger.info(f"Model loaded successfully in {load_time:.2f} seconds")
|
| 669 |
+
|
| 670 |
+
# Step 2: Warm up the model
|
| 671 |
+
logger.info("Warming up model...")
|
| 672 |
+
warmup_agent()
|
| 673 |
+
|
| 674 |
interface = create_interface()
|
| 675 |
interface.queue()
|
| 676 |
interface.launch(
|
|
|
|
| 679 |
debug=True,
|
| 680 |
favicon_path="assets/favicon.ico"
|
| 681 |
)
|
| 682 |
+
|
| 683 |
except Exception as e:
|
| 684 |
+
logger.error(f"❌ Failed to launch Mimir: {e}")
|
| 685 |
+
raise
|