|
""" |
|
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 |
|
|
|
|
|
|
|
logging.getLogger('matplotlib').setLevel(logging.WARNING) |
|
|
|
def main(): |
|
""" |
|
Initializes connections and launches the Gradio application. |
|
""" |
|
|
|
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.") |
|
|
|
if ssh_tunnel and ssh_tunnel.is_active: |
|
ssh_tunnel.stop() |
|
return |
|
|
|
|
|
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: |
|
|
|
print("\nClosing SSH tunnel...") |
|
if ssh_tunnel.is_active: |
|
ssh_tunnel.stop() |
|
print("SSH tunnel closed. Exiting.") |
|
|
|
if __name__ == "__main__": |
|
main() |