grasant commited on
Commit
e06bd40
Β·
verified Β·
1 Parent(s): 56fb9cc

Update frontend_ui.py

Browse files

ui file updated with mcp

Files changed (1) hide show
  1. frontend_ui.py +116 -0
frontend_ui.py CHANGED
@@ -1512,3 +1512,119 @@ def get_batch_processing_status():
1512
 
1513
  except Exception as e:
1514
  return f"❌ Error getting status: {str(e)}", "", {}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1512
 
1513
  except Exception as e:
1514
  return f"❌ Error getting status: {str(e)}", "", {}
1515
+
1516
+ import gradio as gr
1517
+ import pandas as pd
1518
+ import time
1519
+ import threading
1520
+ import asyncio
1521
+ import sys
1522
+ import os
1523
+ import datetime
1524
+ from src.heavy_workload_demo import ModalContainerScalingDemo, RealTimeBatchProcessor
1525
+
1526
+ # Import dashboard functions from app.py to ensure proper integration
1527
+ sys.path.append(os.path.dirname(__file__))
1528
+ # Use dynamic import to avoid circular dependency issues
1529
+ dashboard_state = None
1530
+ add_file_to_dashboard = None
1531
+ get_dashboard_status = None
1532
+ get_processing_queue = None
1533
+ get_dashboard_metrics = None
1534
+ get_jobs_history = None
1535
+
1536
+ def _ensure_app_imports():
1537
+ """Dynamically import app functions to avoid circular dependencies"""
1538
+ global dashboard_state, add_file_to_dashboard, get_dashboard_status
1539
+ global get_processing_queue, get_dashboard_metrics, get_jobs_history
1540
+
1541
+ if dashboard_state is None:
1542
+ try:
1543
+ from app import (
1544
+ dashboard_state as _dashboard_state,
1545
+ add_file_to_dashboard as _add_file_to_dashboard,
1546
+ get_dashboard_status as _get_dashboard_status,
1547
+ get_processing_queue as _get_processing_queue,
1548
+ get_dashboard_metrics as _get_dashboard_metrics,
1549
+ get_jobs_history as _get_jobs_history
1550
+ )
1551
+ dashboard_state = _dashboard_state
1552
+ add_file_to_dashboard = _add_file_to_dashboard
1553
+ get_dashboard_status = _get_dashboard_status
1554
+ get_processing_queue = _get_processing_queue
1555
+ get_dashboard_metrics = _get_dashboard_metrics
1556
+ get_jobs_history = _get_jobs_history
1557
+ except ImportError as e:
1558
+ print(f"Warning: Could not import dashboard functions: {e}")
1559
+ # Set fallback functions that return empty data
1560
+ dashboard_state = {"active_tasks": 0, "total_files": 0}
1561
+ add_file_to_dashboard = lambda *args, **kwargs: None
1562
+ get_dashboard_status = lambda: "πŸ“Š Dashboard not available"
1563
+ get_processing_queue = lambda: [["Status", "Not Available"]]
1564
+ get_dashboard_metrics = lambda: [["Metric", "Not Available"]]
1565
+ get_jobs_history = lambda: []
1566
+
1567
+ # Initialize demo components
1568
+ heavy_workload_demo = ModalContainerScalingDemo()
1569
+ batch_processor = RealTimeBatchProcessor()
1570
+
1571
+ # Global reference to dashboard function (set by create_medical_ui)
1572
+ _add_file_to_dashboard = None
1573
+
1574
+ def is_modal_available():
1575
+ """Check if Modal environment is available"""
1576
+ try:
1577
+ import modal
1578
+ return True
1579
+ except ImportError:
1580
+ return False
1581
+
1582
+ def get_environment_name():
1583
+ """Get current deployment environment name"""
1584
+ if is_modal_available():
1585
+ return "Modal Cloud"
1586
+ else:
1587
+ return "Local/HuggingFace"
1588
+
1589
+ def create_text_processing_tab(process_text_only, cancel_current_task, get_dashboard_status,
1590
+ dashboard_state, get_dashboard_metrics):
1591
+ """Create the text processing tab"""
1592
+
1593
+ with gr.Tab("πŸ“ Text Processing"):
1594
+ gr.Markdown("### Medical Text Analysis")
1595
+ gr.Markdown("Process medical text directly with entity extraction and FHIR generation")
1596
+
1597
+ with gr.Row():
1598
+ with gr.Column():
1599
+ gr.Markdown("### Medical Text Input")
1600
+ text_input = gr.Textbox(
1601
+ label="Medical Text",
1602
+ placeholder="Enter medical text here...",
1603
+ lines=8
1604
+ )
1605
+
1606
+ enable_fhir_text = gr.Checkbox(
1607
+ label="Generate FHIR Resources",
1608
+ value=False
1609
+ )
1610
+
1611
+ with gr.Row():
1612
+ process_text_btn = gr.Button("πŸ” Process Text", variant="primary")
1613
+ cancel_text_btn = gr.Button("❌ Cancel", variant="secondary", visible=False)
1614
+
1615
+ with gr.Column():
1616
+ # Additional UI components here
1617
+ pass
1618
+
1619
+ # Add the Gradio app launch call with mcp_server=True
1620
+ def launch_gradio_app():
1621
+ demo = gr.Interface(
1622
+ fn=lambda x: x,
1623
+ inputs=gr.Textbox(label="Input"),
1624
+ outputs=gr.Textbox(label="Output"),
1625
+ title="FhirFlame Demo"
1626
+ )
1627
+ demo.launch(mcp_server=True)
1628
+
1629
+ if __name__ == "__main__":
1630
+ launch_gradio_app()