Youngger9765 commited on
Commit
3de426f
·
1 Parent(s): 6ceaded

fix: Use importlib to avoid module name conflicts in HF Spaces

Browse files

- Replace direct imports with importlib.util.spec_from_file_location
- Avoids conflicts between root app.py and backend/app module
- Resolves ModuleNotFoundError: No module named 'app.config'

Files changed (1) hide show
  1. app.py +11 -3
app.py CHANGED
@@ -22,9 +22,17 @@ from dotenv import load_dotenv
22
  load_dotenv(".env.local")
23
  load_dotenv(".env")
24
 
25
- # Now we can import from the backend
26
- from app.config.settings import settings
27
- from app.routers import grading
 
 
 
 
 
 
 
 
28
 
29
  # Configure logging
30
  logging.basicConfig(
 
22
  load_dotenv(".env.local")
23
  load_dotenv(".env")
24
 
25
+ # Now we can import from the backend - use specific module imports to avoid conflicts
26
+ import importlib.util
27
+ spec = importlib.util.spec_from_file_location("settings", backend_path / "app" / "config" / "settings.py")
28
+ settings_module = importlib.util.module_from_spec(spec)
29
+ spec.loader.exec_module(settings_module)
30
+ settings = settings_module.settings
31
+
32
+ spec_grading = importlib.util.spec_from_file_location("grading", backend_path / "app" / "routers" / "grading.py")
33
+ grading_module = importlib.util.module_from_spec(spec_grading)
34
+ spec_grading.loader.exec_module(grading_module)
35
+ grading = grading_module
36
 
37
  # Configure logging
38
  logging.basicConfig(