File size: 1,672 Bytes
f43f2d3
 
 
 
 
 
4d74be9
f43f2d3
 
4d74be9
0ad77c8
4d74be9
 
 
f43f2d3
4d74be9
f43f2d3
4d74be9
f43f2d3
 
 
 
 
 
 
 
 
4d74be9
f43f2d3
 
4d74be9
4ee8b9e
a811652
f43f2d3
a811652
 
 
f43f2d3
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""
Main entry point for the PharmaCircle AI Data Analyst application.
This script initializes the necessary services and launches the Gradio user interface.
It has been refactored to be a lean entry point, delegating all complex logic
to specialized modules.
"""
import logging
import connections
from ui import create_ui


# --- Suppress Matplotlib Debug Logs ---
logging.getLogger('matplotlib').setLevel(logging.WARNING)

def main():
    """
    Initializes connections and launches the Gradio application.
    """
    # Initialize all external connections (SSH, Solr, LLM)
    ssh_tunnel, solr_client, llm_model = connections.initialize_connections()

    if not all([ssh_tunnel, solr_client, llm_model]):
        print("\nSkipping Gradio launch due to initialization errors.")
        # Ensure the tunnel is closed if it was partially opened
        if ssh_tunnel and ssh_tunnel.is_active:
            ssh_tunnel.stop()
        return

    # Create and launch the Gradio UI
    demo = create_ui(llm_model, solr_client)
    try:
        demo.queue().launch(debug=True, share=True, allowed_paths=['/tmp/plots'])
    except (IOError, OSError) as e:
        print(f"An error occurred while launching the Gradio app: {e}")
        print("Please check if the port is already in use or if you have the necessary permissions.")
    except Exception as e:
        print(f"An unexpected error occurred: {e}")
    finally:
        # Ensure the SSH tunnel is closed when the app is shut down
        print("\nClosing SSH tunnel...")
        if ssh_tunnel.is_active:
            ssh_tunnel.stop()
        print("SSH tunnel closed. Exiting.")

if __name__ == "__main__":
    main()