|
|
|
""" |
|
AdvisorAI Data Pipeline Monitor - Gradio App |
|
This is the main entry point for Hugging Face Spaces |
|
""" |
|
|
|
import gradio as gr |
|
import json |
|
import os |
|
import sys |
|
import logging |
|
import time |
|
from datetime import datetime |
|
|
|
|
|
logging.basicConfig(level=logging.INFO) |
|
logger = logging.getLogger(__name__) |
|
|
|
def get_basic_health(): |
|
"""Get basic health status without external dependencies""" |
|
return { |
|
"status": "healthy", |
|
"timestamp": datetime.now().isoformat(), |
|
"message": "AdvisorAI Data Pipeline Monitor is running" |
|
} |
|
|
|
def get_basic_pipeline_status(): |
|
"""Get basic pipeline status""" |
|
return { |
|
"status": "monitoring", |
|
"message": "Data pipeline monitoring active", |
|
"last_check": datetime.now().isoformat() |
|
} |
|
|
|
def get_sample_data(): |
|
"""Get sample data for display""" |
|
return [ |
|
["sample_data.json", "merged/features/", "2.5 MB", "2025-01-18 10:30"], |
|
["market_data.parquet", "alpaca/", "15.3 MB", "2025-01-18 10:25"], |
|
["sentiment_data.json", "finviz/features/", "1.2 MB", "2025-01-18 10:20"] |
|
] |
|
|
|
def get_sample_logs(): |
|
"""Get sample log entries""" |
|
return """=== scheduler.log === |
|
2025-01-18 10:30:15 - INFO - Scheduler started successfully |
|
2025-01-18 10:30:16 - INFO - Data collection task initiated |
|
2025-01-18 10:30:45 - INFO - Market data fetched successfully |
|
|
|
=== monitor.log === |
|
2025-01-18 10:30:00 - INFO - System monitoring active |
|
2025-01-18 10:30:30 - INFO - Memory usage: 45% |
|
2025-01-18 10:31:00 - INFO - All services running normally |
|
""" |
|
|
|
|
|
with gr.Blocks(title="AdvisorAI Data Pipeline Monitor", theme=gr.themes.Soft()) as app: |
|
gr.Markdown("# π€ AdvisorAI Data Pipeline Monitor") |
|
gr.Markdown("Real-time monitoring of the AdvisorAI data collection and processing pipeline") |
|
|
|
with gr.Tabs(): |
|
with gr.TabItem("π Dashboard"): |
|
with gr.Row(): |
|
with gr.Column(): |
|
gr.Markdown("### Health Status") |
|
health_display = gr.JSON(label="System Health & Status") |
|
|
|
with gr.Column(): |
|
gr.Markdown("### Pipeline Status") |
|
pipeline_display = gr.JSON(label="Data Pipeline Status") |
|
|
|
with gr.Row(): |
|
refresh_btn = gr.Button("π Refresh", variant="primary") |
|
|
|
with gr.TabItem("π Recent Files"): |
|
gr.Markdown("### Recently Modified Data Files") |
|
files_display = gr.Dataframe( |
|
headers=["File", "Path", "Size", "Modified"], |
|
value=get_sample_data(), |
|
label="Recent Files" |
|
) |
|
refresh_files_btn = gr.Button("π Refresh Files") |
|
|
|
with gr.TabItem("π Logs"): |
|
gr.Markdown("### Recent Log Entries") |
|
logs_display = gr.Textbox( |
|
label="Recent Logs", |
|
value=get_sample_logs(), |
|
lines=15, |
|
max_lines=25, |
|
show_copy_button=True |
|
) |
|
refresh_logs_btn = gr.Button("π Refresh Logs") |
|
|
|
|
|
def refresh_dashboard(): |
|
health = get_basic_health() |
|
pipeline = get_basic_pipeline_status() |
|
return json.dumps(health, indent=2), json.dumps(pipeline, indent=2) |
|
|
|
def refresh_files(): |
|
return get_sample_data() |
|
|
|
def refresh_logs(): |
|
return get_sample_logs() |
|
|
|
|
|
refresh_btn.click( |
|
refresh_dashboard, |
|
outputs=[health_display, pipeline_display] |
|
) |
|
|
|
refresh_files_btn.click( |
|
refresh_files, |
|
outputs=[files_display] |
|
) |
|
|
|
refresh_logs_btn.click( |
|
refresh_logs, |
|
outputs=[logs_display] |
|
) |
|
|
|
|
|
app.load( |
|
refresh_dashboard, |
|
outputs=[health_display, pipeline_display] |
|
) |
|
|
|
if __name__ == "__main__": |
|
logger.info("Starting Gradio app...") |
|
app.launch( |
|
server_name="0.0.0.0", |
|
server_port=7860, |
|
share=False, |
|
show_error=True |
|
) |
|
|