sachinchandrankallar commited on
Commit
62f6391
·
1 Parent(s): 5547093

updates for huggingface competence

Browse files
Files changed (31) hide show
  1. README_HF_SPACES.md +42 -0
  2. __init__.py +9 -0
  3. app.py +53 -0
  4. requirements.txt +1 -1
  5. services/ai-service/src/__pycache__/config_settings.cpython-311.pyc +0 -0
  6. services/ai-service/src/ai_med_extract/__pycache__/__init__.cpython-311.pyc +0 -0
  7. services/ai-service/src/ai_med_extract/__pycache__/api_endpoints.cpython-311.pyc +0 -0
  8. services/ai-service/src/ai_med_extract/__pycache__/api_middleware.cpython-311.pyc +0 -0
  9. services/ai-service/src/ai_med_extract/__pycache__/app.cpython-311.pyc +0 -0
  10. services/ai-service/src/ai_med_extract/__pycache__/database_audit.cpython-311.pyc +0 -0
  11. services/ai-service/src/ai_med_extract/__pycache__/health_endpoints.cpython-311.pyc +0 -0
  12. services/ai-service/src/ai_med_extract/__pycache__/inference_service.cpython-311.pyc +0 -0
  13. services/ai-service/src/ai_med_extract/__pycache__/monitoring_observability.cpython-311.pyc +0 -0
  14. services/ai-service/src/ai_med_extract/__pycache__/phi_scrubber_service.cpython-311.pyc +0 -0
  15. services/ai-service/src/ai_med_extract/__pycache__/scalable_service_mesh.cpython-311.pyc +0 -0
  16. services/ai-service/src/ai_med_extract/agents/__pycache__/__init__.cpython-311.pyc +0 -0
  17. services/ai-service/src/ai_med_extract/agents/__pycache__/medical_data_extractor.cpython-311.pyc +0 -0
  18. services/ai-service/src/ai_med_extract/agents/__pycache__/patient_summary_agent.cpython-311.pyc +0 -0
  19. services/ai-service/src/ai_med_extract/agents/__pycache__/phi_scrubber.cpython-311.pyc +0 -0
  20. services/ai-service/src/ai_med_extract/agents/__pycache__/summarizer.cpython-311.pyc +0 -0
  21. services/ai-service/src/ai_med_extract/agents/__pycache__/text_extractor.cpython-311.pyc +0 -0
  22. services/ai-service/src/ai_med_extract/api/__pycache__/__init__.cpython-311.pyc +0 -0
  23. services/ai-service/src/ai_med_extract/api/__pycache__/model_management_fastapi.cpython-311.pyc +0 -0
  24. services/ai-service/src/ai_med_extract/api/__pycache__/routes_fastapi.cpython-311.pyc +0 -0
  25. services/ai-service/src/ai_med_extract/utils/__pycache__/__init__.cpython-311.pyc +0 -0
  26. services/ai-service/src/ai_med_extract/utils/__pycache__/file_utils.cpython-311.pyc +0 -0
  27. services/ai-service/src/ai_med_extract/utils/__pycache__/json_slimmer.cpython-311.pyc +0 -0
  28. services/ai-service/src/ai_med_extract/utils/__pycache__/model_config.cpython-311.pyc +0 -0
  29. services/ai-service/src/ai_med_extract/utils/__pycache__/model_manager.cpython-311.pyc +0 -0
  30. services/ai-service/src/ai_med_extract/utils/__pycache__/openvino_summarizer_utils.cpython-311.pyc +0 -0
  31. services/ai-service/src/ai_med_extract/utils/__pycache__/quantization_utils.cpython-311.pyc +0 -0
README_HF_SPACES.md ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Hugging Face Spaces Deployment
2
+
3
+ This document explains the changes made to support Hugging Face Spaces deployment.
4
+
5
+ ## Changes Made
6
+
7
+ ### 1. Root-level Entry Point (`app.py`)
8
+ - Created a root-level `app.py` file that serves as the entry point for Hugging Face Spaces
9
+ - This file imports the FastAPI app from the `ai_med_extract` package
10
+ - Includes proper error handling and fallback mechanisms
11
+
12
+ ### 2. Package Structure
13
+ - Added `__init__.py` at the root level to make it a proper Python package
14
+ - The main application code remains in `services/ai-service/src/ai_med_extract/`
15
+
16
+ ### 3. Requirements File
17
+ - Created a root-level `requirements.txt` with all necessary dependencies
18
+ - This is used by Hugging Face Spaces for dependency installation
19
+
20
+ ### 4. Environment Configuration
21
+ - Set `FAST_MODE=true` and `PRELOAD_SMALL_MODELS=false` for Hugging Face Spaces
22
+ - This ensures faster startup and reduced memory usage
23
+
24
+ ## How It Works
25
+
26
+ 1. Hugging Face Spaces looks for `app.py` at the root level
27
+ 2. The `app.py` file adds the source directory to the Python path
28
+ 3. It imports the FastAPI app from `ai_med_extract.app`
29
+ 4. The app is initialized with minimal preloading for faster startup
30
+
31
+ ## Testing
32
+
33
+ Run `python test_import.py` to verify the import structure works correctly.
34
+
35
+ ## Deployment
36
+
37
+ The app should now work correctly when deployed to Hugging Face Spaces. The key changes ensure that:
38
+
39
+ - The module structure is properly recognized
40
+ - Dependencies are correctly installed
41
+ - The app starts with minimal resource usage
42
+ - Error handling provides fallback functionality
__init__.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ HNTAI Medical AI Service
3
+
4
+ A comprehensive medical AI service for text extraction, PHI scrubbing, summarization,
5
+ and medical data extraction from various document formats.
6
+ """
7
+
8
+ __version__ = "1.0.0"
9
+ __author__ = "HNTAI Team"
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Hugging Face Spaces entry point.
3
+
4
+ This file serves as the main entry point for Hugging Face Spaces deployment.
5
+ It imports and exposes the FastAPI app from the ai_med_extract package.
6
+ """
7
+
8
+ import os
9
+ import sys
10
+ import logging
11
+
12
+ # Configure logging for Hugging Face Spaces
13
+ logging.basicConfig(
14
+ level=logging.INFO,
15
+ format="%(asctime)s - %(levelname)s - %(message)s"
16
+ )
17
+
18
+ # Add the services/ai-service/src directory to the Python path
19
+ current_dir = os.path.dirname(os.path.abspath(__file__))
20
+ src_dir = os.path.join(current_dir, "services", "ai-service", "src")
21
+ sys.path.insert(0, src_dir)
22
+
23
+ # Set environment variables for Hugging Face Spaces
24
+ os.environ.setdefault("FAST_MODE", "true")
25
+ os.environ.setdefault("PRELOAD_SMALL_MODELS", "false")
26
+
27
+ try:
28
+ # Import the app from the ai_med_extract package
29
+ from ai_med_extract.app import create_app, initialize_agents
30
+
31
+ # Create the app instance
32
+ app = create_app()
33
+
34
+ # Initialize agents with minimal preloading for Hugging Face Spaces
35
+ try:
36
+ initialize_agents(app, preload_small_models=False)
37
+ logging.info("Agents initialized successfully")
38
+ except Exception as e:
39
+ logging.warning(f"Agent initialization failed: {e}")
40
+ logging.info("App will start with basic functionality")
41
+
42
+ except Exception as e:
43
+ logging.error(f"Failed to create app: {e}")
44
+ # Create a minimal FastAPI app as fallback
45
+ from fastapi import FastAPI
46
+ app = FastAPI(title="Medical AI Service (fallback)")
47
+
48
+ @app.get("/")
49
+ async def root():
50
+ return {"message": "Medical AI Service - Fallback mode", "error": str(e)}
51
+
52
+ # Export the app for Hugging Face Spaces
53
+ __all__ = ["app"]
requirements.txt CHANGED
@@ -83,4 +83,4 @@ asyncpg==0.30.0
83
 
84
  # Development & Monitoring (minimal)
85
  rich==13.9.4
86
- typer==0.9.4
 
83
 
84
  # Development & Monitoring (minimal)
85
  rich==13.9.4
86
+ typer==0.9.4
services/ai-service/src/__pycache__/config_settings.cpython-311.pyc CHANGED
Binary files a/services/ai-service/src/__pycache__/config_settings.cpython-311.pyc and b/services/ai-service/src/__pycache__/config_settings.cpython-311.pyc differ
 
services/ai-service/src/ai_med_extract/__pycache__/__init__.cpython-311.pyc CHANGED
Binary files a/services/ai-service/src/ai_med_extract/__pycache__/__init__.cpython-311.pyc and b/services/ai-service/src/ai_med_extract/__pycache__/__init__.cpython-311.pyc differ
 
services/ai-service/src/ai_med_extract/__pycache__/api_endpoints.cpython-311.pyc CHANGED
Binary files a/services/ai-service/src/ai_med_extract/__pycache__/api_endpoints.cpython-311.pyc and b/services/ai-service/src/ai_med_extract/__pycache__/api_endpoints.cpython-311.pyc differ
 
services/ai-service/src/ai_med_extract/__pycache__/api_middleware.cpython-311.pyc CHANGED
Binary files a/services/ai-service/src/ai_med_extract/__pycache__/api_middleware.cpython-311.pyc and b/services/ai-service/src/ai_med_extract/__pycache__/api_middleware.cpython-311.pyc differ
 
services/ai-service/src/ai_med_extract/__pycache__/app.cpython-311.pyc CHANGED
Binary files a/services/ai-service/src/ai_med_extract/__pycache__/app.cpython-311.pyc and b/services/ai-service/src/ai_med_extract/__pycache__/app.cpython-311.pyc differ
 
services/ai-service/src/ai_med_extract/__pycache__/database_audit.cpython-311.pyc CHANGED
Binary files a/services/ai-service/src/ai_med_extract/__pycache__/database_audit.cpython-311.pyc and b/services/ai-service/src/ai_med_extract/__pycache__/database_audit.cpython-311.pyc differ
 
services/ai-service/src/ai_med_extract/__pycache__/health_endpoints.cpython-311.pyc CHANGED
Binary files a/services/ai-service/src/ai_med_extract/__pycache__/health_endpoints.cpython-311.pyc and b/services/ai-service/src/ai_med_extract/__pycache__/health_endpoints.cpython-311.pyc differ
 
services/ai-service/src/ai_med_extract/__pycache__/inference_service.cpython-311.pyc CHANGED
Binary files a/services/ai-service/src/ai_med_extract/__pycache__/inference_service.cpython-311.pyc and b/services/ai-service/src/ai_med_extract/__pycache__/inference_service.cpython-311.pyc differ
 
services/ai-service/src/ai_med_extract/__pycache__/monitoring_observability.cpython-311.pyc CHANGED
Binary files a/services/ai-service/src/ai_med_extract/__pycache__/monitoring_observability.cpython-311.pyc and b/services/ai-service/src/ai_med_extract/__pycache__/monitoring_observability.cpython-311.pyc differ
 
services/ai-service/src/ai_med_extract/__pycache__/phi_scrubber_service.cpython-311.pyc CHANGED
Binary files a/services/ai-service/src/ai_med_extract/__pycache__/phi_scrubber_service.cpython-311.pyc and b/services/ai-service/src/ai_med_extract/__pycache__/phi_scrubber_service.cpython-311.pyc differ
 
services/ai-service/src/ai_med_extract/__pycache__/scalable_service_mesh.cpython-311.pyc CHANGED
Binary files a/services/ai-service/src/ai_med_extract/__pycache__/scalable_service_mesh.cpython-311.pyc and b/services/ai-service/src/ai_med_extract/__pycache__/scalable_service_mesh.cpython-311.pyc differ
 
services/ai-service/src/ai_med_extract/agents/__pycache__/__init__.cpython-311.pyc CHANGED
Binary files a/services/ai-service/src/ai_med_extract/agents/__pycache__/__init__.cpython-311.pyc and b/services/ai-service/src/ai_med_extract/agents/__pycache__/__init__.cpython-311.pyc differ
 
services/ai-service/src/ai_med_extract/agents/__pycache__/medical_data_extractor.cpython-311.pyc CHANGED
Binary files a/services/ai-service/src/ai_med_extract/agents/__pycache__/medical_data_extractor.cpython-311.pyc and b/services/ai-service/src/ai_med_extract/agents/__pycache__/medical_data_extractor.cpython-311.pyc differ
 
services/ai-service/src/ai_med_extract/agents/__pycache__/patient_summary_agent.cpython-311.pyc CHANGED
Binary files a/services/ai-service/src/ai_med_extract/agents/__pycache__/patient_summary_agent.cpython-311.pyc and b/services/ai-service/src/ai_med_extract/agents/__pycache__/patient_summary_agent.cpython-311.pyc differ
 
services/ai-service/src/ai_med_extract/agents/__pycache__/phi_scrubber.cpython-311.pyc CHANGED
Binary files a/services/ai-service/src/ai_med_extract/agents/__pycache__/phi_scrubber.cpython-311.pyc and b/services/ai-service/src/ai_med_extract/agents/__pycache__/phi_scrubber.cpython-311.pyc differ
 
services/ai-service/src/ai_med_extract/agents/__pycache__/summarizer.cpython-311.pyc CHANGED
Binary files a/services/ai-service/src/ai_med_extract/agents/__pycache__/summarizer.cpython-311.pyc and b/services/ai-service/src/ai_med_extract/agents/__pycache__/summarizer.cpython-311.pyc differ
 
services/ai-service/src/ai_med_extract/agents/__pycache__/text_extractor.cpython-311.pyc CHANGED
Binary files a/services/ai-service/src/ai_med_extract/agents/__pycache__/text_extractor.cpython-311.pyc and b/services/ai-service/src/ai_med_extract/agents/__pycache__/text_extractor.cpython-311.pyc differ
 
services/ai-service/src/ai_med_extract/api/__pycache__/__init__.cpython-311.pyc CHANGED
Binary files a/services/ai-service/src/ai_med_extract/api/__pycache__/__init__.cpython-311.pyc and b/services/ai-service/src/ai_med_extract/api/__pycache__/__init__.cpython-311.pyc differ
 
services/ai-service/src/ai_med_extract/api/__pycache__/model_management_fastapi.cpython-311.pyc CHANGED
Binary files a/services/ai-service/src/ai_med_extract/api/__pycache__/model_management_fastapi.cpython-311.pyc and b/services/ai-service/src/ai_med_extract/api/__pycache__/model_management_fastapi.cpython-311.pyc differ
 
services/ai-service/src/ai_med_extract/api/__pycache__/routes_fastapi.cpython-311.pyc CHANGED
Binary files a/services/ai-service/src/ai_med_extract/api/__pycache__/routes_fastapi.cpython-311.pyc and b/services/ai-service/src/ai_med_extract/api/__pycache__/routes_fastapi.cpython-311.pyc differ
 
services/ai-service/src/ai_med_extract/utils/__pycache__/__init__.cpython-311.pyc CHANGED
Binary files a/services/ai-service/src/ai_med_extract/utils/__pycache__/__init__.cpython-311.pyc and b/services/ai-service/src/ai_med_extract/utils/__pycache__/__init__.cpython-311.pyc differ
 
services/ai-service/src/ai_med_extract/utils/__pycache__/file_utils.cpython-311.pyc CHANGED
Binary files a/services/ai-service/src/ai_med_extract/utils/__pycache__/file_utils.cpython-311.pyc and b/services/ai-service/src/ai_med_extract/utils/__pycache__/file_utils.cpython-311.pyc differ
 
services/ai-service/src/ai_med_extract/utils/__pycache__/json_slimmer.cpython-311.pyc CHANGED
Binary files a/services/ai-service/src/ai_med_extract/utils/__pycache__/json_slimmer.cpython-311.pyc and b/services/ai-service/src/ai_med_extract/utils/__pycache__/json_slimmer.cpython-311.pyc differ
 
services/ai-service/src/ai_med_extract/utils/__pycache__/model_config.cpython-311.pyc CHANGED
Binary files a/services/ai-service/src/ai_med_extract/utils/__pycache__/model_config.cpython-311.pyc and b/services/ai-service/src/ai_med_extract/utils/__pycache__/model_config.cpython-311.pyc differ
 
services/ai-service/src/ai_med_extract/utils/__pycache__/model_manager.cpython-311.pyc CHANGED
Binary files a/services/ai-service/src/ai_med_extract/utils/__pycache__/model_manager.cpython-311.pyc and b/services/ai-service/src/ai_med_extract/utils/__pycache__/model_manager.cpython-311.pyc differ
 
services/ai-service/src/ai_med_extract/utils/__pycache__/openvino_summarizer_utils.cpython-311.pyc CHANGED
Binary files a/services/ai-service/src/ai_med_extract/utils/__pycache__/openvino_summarizer_utils.cpython-311.pyc and b/services/ai-service/src/ai_med_extract/utils/__pycache__/openvino_summarizer_utils.cpython-311.pyc differ
 
services/ai-service/src/ai_med_extract/utils/__pycache__/quantization_utils.cpython-311.pyc CHANGED
Binary files a/services/ai-service/src/ai_med_extract/utils/__pycache__/quantization_utils.cpython-311.pyc and b/services/ai-service/src/ai_med_extract/utils/__pycache__/quantization_utils.cpython-311.pyc differ