Spaces:
Sleeping
Fix terminal issues: persistent logs + force HF Spaces rebuild
Browse files🔧 Fixes:
1. **Log Preservation**: Replace queue with persistent list + threading.Lock
- Logs now persist throughout session instead of being consumed
- Thread-safe access with proper locking
- Stores last 200 entries, displays last 100
2. **HF Spaces Deployment**: Force fresh rebuild
- HF Spaces was still using old gr.Code version despite gr.Textbox fix
- Small change to trigger complete rebuild and cache refresh
- Should resolve the 'Language bash not supported' error
3. **Improved Log Storage**:
- Uses list instead of queue for persistent storage
- Thread-safe with proper locking mechanism
- Better memory management with rolling window
The terminal will now maintain log history throughout the session
and HF Spaces should properly deploy with gr.Textbox component.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- data/memories.json +9 -0
- src/app.py +32 -39
|
@@ -51,5 +51,14 @@
|
|
| 51 |
"maya_response": "Hello! I'm doing great, thank you! I'm ready to help you with your questions about learning programming. \ud83d\udcbb How can I assist you today? \ud83d\ude0a",
|
| 52 |
"source": "gradio_chat"
|
| 53 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
}
|
| 55 |
]
|
|
|
|
| 51 |
"maya_response": "Hello! I'm doing great, thank you! I'm ready to help you with your questions about learning programming. \ud83d\udcbb How can I assist you today? \ud83d\ude0a",
|
| 52 |
"source": "gradio_chat"
|
| 53 |
}
|
| 54 |
+
},
|
| 55 |
+
{
|
| 56 |
+
"content": "User asked: hello maya, how you doin?. Maya responded: Hello there! I'm doing great, thanks for asking! How about you? \ud83d\ude0a What's up? \ud83c\udf1f",
|
| 57 |
+
"metadata": {
|
| 58 |
+
"timestamp": "2025-07-15T14:41:09.772128",
|
| 59 |
+
"user_message": "hello maya, how you doin?",
|
| 60 |
+
"maya_response": "Hello there! I'm doing great, thanks for asking! How about you? \ud83d\ude0a What's up? \ud83c\udf1f",
|
| 61 |
+
"source": "gradio_chat"
|
| 62 |
+
}
|
| 63 |
}
|
| 64 |
]
|
|
@@ -23,36 +23,35 @@ from model_interface import ModelInterface
|
|
| 23 |
logging.basicConfig(level=logging.INFO)
|
| 24 |
logger = logging.getLogger(__name__)
|
| 25 |
|
| 26 |
-
# Global log
|
| 27 |
-
|
|
|
|
| 28 |
|
| 29 |
class TerminalLogHandler(logging.Handler):
|
| 30 |
"""Custom log handler that captures all logs for terminal display"""
|
| 31 |
def emit(self, record):
|
| 32 |
log_entry = self.format(record)
|
| 33 |
timestamp = datetime.now().strftime('%H:%M:%S.%f')[:-3] # Include milliseconds
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
except queue.Empty:
|
| 55 |
-
pass
|
| 56 |
|
| 57 |
# Add custom handler to root logger to capture ALL logs
|
| 58 |
terminal_handler = TerminalLogHandler()
|
|
@@ -410,24 +409,18 @@ Communication style:
|
|
| 410 |
return output
|
| 411 |
|
| 412 |
def get_terminal_logs(self) -> str:
|
| 413 |
-
"""Get
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
while not log_queue.empty():
|
| 418 |
-
try:
|
| 419 |
-
log_entry = log_queue.get_nowait()
|
| 420 |
-
logs.append(log_entry)
|
| 421 |
-
except queue.Empty:
|
| 422 |
-
break
|
| 423 |
-
|
| 424 |
-
# Keep only last 100 entries for performance
|
| 425 |
-
if len(logs) > 100:
|
| 426 |
-
logs = logs[-100:]
|
| 427 |
|
| 428 |
if not logs:
|
| 429 |
return "\033[32m[MAYA TERMINAL]\033[0m Waiting for system activity...\n"
|
| 430 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 431 |
# Join logs and add terminal header
|
| 432 |
terminal_output = "\033[32m[MAYA TERMINAL - REAL-TIME BACKEND ACTIVITY]\033[0m\n"
|
| 433 |
terminal_output += "\033[36m" + "="*80 + "\033[0m\n"
|
|
@@ -672,7 +665,7 @@ Communication style:
|
|
| 672 |
|
| 673 |
terminal_output = gr.Textbox(
|
| 674 |
label="System Activity",
|
| 675 |
-
value="🔧 Maya Backend Terminal - Click 'Show Real-time Logs' to see system activity",
|
| 676 |
lines=15,
|
| 677 |
max_lines=25,
|
| 678 |
interactive=False,
|
|
|
|
| 23 |
logging.basicConfig(level=logging.INFO)
|
| 24 |
logger = logging.getLogger(__name__)
|
| 25 |
|
| 26 |
+
# Global log storage for terminal display
|
| 27 |
+
log_storage = []
|
| 28 |
+
log_lock = threading.Lock()
|
| 29 |
|
| 30 |
class TerminalLogHandler(logging.Handler):
|
| 31 |
"""Custom log handler that captures all logs for terminal display"""
|
| 32 |
def emit(self, record):
|
| 33 |
log_entry = self.format(record)
|
| 34 |
timestamp = datetime.now().strftime('%H:%M:%S.%f')[:-3] # Include milliseconds
|
| 35 |
+
|
| 36 |
+
# Color code different log levels
|
| 37 |
+
level_colors = {
|
| 38 |
+
'DEBUG': '\033[36m', # Cyan
|
| 39 |
+
'INFO': '\033[32m', # Green
|
| 40 |
+
'WARNING': '\033[33m', # Yellow
|
| 41 |
+
'ERROR': '\033[31m', # Red
|
| 42 |
+
'CRITICAL': '\033[35m' # Magenta
|
| 43 |
+
}
|
| 44 |
+
reset_color = '\033[0m'
|
| 45 |
+
|
| 46 |
+
level_color = level_colors.get(record.levelname, '')
|
| 47 |
+
formatted_log = f"[{timestamp}] {level_color}{record.levelname:<8}{reset_color} {record.name}: {record.getMessage()}"
|
| 48 |
+
|
| 49 |
+
# Store logs in persistent list with thread safety
|
| 50 |
+
with log_lock:
|
| 51 |
+
log_storage.append(formatted_log)
|
| 52 |
+
# Keep only last 200 entries
|
| 53 |
+
if len(log_storage) > 200:
|
| 54 |
+
log_storage.pop(0)
|
|
|
|
|
|
|
| 55 |
|
| 56 |
# Add custom handler to root logger to capture ALL logs
|
| 57 |
terminal_handler = TerminalLogHandler()
|
|
|
|
| 409 |
return output
|
| 410 |
|
| 411 |
def get_terminal_logs(self) -> str:
|
| 412 |
+
"""Get all terminal logs with formatting"""
|
| 413 |
+
with log_lock:
|
| 414 |
+
# Get copy of all stored logs
|
| 415 |
+
logs = log_storage.copy()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 416 |
|
| 417 |
if not logs:
|
| 418 |
return "\033[32m[MAYA TERMINAL]\033[0m Waiting for system activity...\n"
|
| 419 |
|
| 420 |
+
# Keep only last 100 entries for display performance
|
| 421 |
+
if len(logs) > 100:
|
| 422 |
+
logs = logs[-100:]
|
| 423 |
+
|
| 424 |
# Join logs and add terminal header
|
| 425 |
terminal_output = "\033[32m[MAYA TERMINAL - REAL-TIME BACKEND ACTIVITY]\033[0m\n"
|
| 426 |
terminal_output += "\033[36m" + "="*80 + "\033[0m\n"
|
|
|
|
| 665 |
|
| 666 |
terminal_output = gr.Textbox(
|
| 667 |
label="System Activity",
|
| 668 |
+
value="🔧 Maya Backend Terminal - Click 'Show Real-time Logs' to see live system activity",
|
| 669 |
lines=15,
|
| 670 |
max_lines=25,
|
| 671 |
interactive=False,
|