Spaces:
Sleeping
Sleeping
File size: 8,991 Bytes
b172fa2 aaa20d9 66dc777 aaa20d9 66dc777 aaa20d9 66dc777 aaa20d9 66dc777 b172fa2 66dc777 b172fa2 66dc777 |
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# app.py
import sys
import os
import importlib.util # Import the utility
import traceback # Import traceback for detailed error printing
print("--- DETAILED DEBUG INFO ---")
print(f"Python Version: {sys.version}")
print(f"Current Working Directory: {os.getcwd()}")
print("sys.path:")
for p in sys.path:
print(f" - {p}")
print("\n--- Checking Directory Structure ---")
root_contents = []
try:
root_contents = os.listdir('.')
except Exception as e:
print(f"[ERROR] Could not list root directory contents: {e}")
print(f"Root Directory Contents: {root_contents}")
src_path = os.path.join(os.getcwd(), 'src')
if os.path.exists(src_path) and os.path.isdir(src_path):
print(f"\n[OK] src Directory ('{src_path}') Exists.")
try:
src_contents = os.listdir(src_path)
print(f" src Contents: {src_contents}")
chimera_path = os.path.join(src_path, 'chimera')
if os.path.exists(chimera_path) and os.path.isdir(chimera_path):
print(f" [OK] chimera Directory ('{chimera_path}') Exists.")
try:
chimera_contents = os.listdir(chimera_path)
print(f" chimera Contents: {chimera_contents}")
# Explicitly check for __init__.py in chimera
chimera_init_path = os.path.join(chimera_path, '__init__.py')
if os.path.exists(chimera_init_path):
print(" [OK] src/chimera/__init__.py Exists.")
else:
print(" [ERROR] src/chimera/__init__.py MISSING!")
core_path = os.path.join(chimera_path, 'core')
if os.path.exists(core_path) and os.path.isdir(core_path):
print(f" [OK] core Directory ('{core_path}') Exists.")
try:
core_contents = os.listdir(core_path)
print(f" core Contents: {core_contents}")
# Explicitly check for __init__.py in core
core_init_path = os.path.join(core_path, '__init__.py')
if os.path.exists(core_init_path):
print(" [OK] src/chimera/core/__init__.py Exists.")
else:
print(" [ERROR] src/chimera/core/__init__.py MISSING!")
orchestrator_path = os.path.join(core_path, 'orchestrator.py')
if os.path.exists(orchestrator_path):
print(f" [OK] orchestrator.py ('{orchestrator_path}') Exists.")
else:
print(f" [ERROR] orchestrator.py ('{orchestrator_path}') MISSING!")
except Exception as e:
print(f" [ERROR] Could not list core directory contents: {e}")
else:
print(f" [ERROR] core Directory ('{core_path}') MISSING or is not a directory.")
except Exception as e:
print(f" [ERROR] Could not list chimera directory contents: {e}")
else:
print(f" [ERROR] chimera Directory ('{chimera_path}') MISSING or is not a directory.")
except Exception as e:
print(f"\n[ERROR] Could not list src directory contents: {e}")
else:
print(f"\n[ERROR] src Directory ('{src_path}') MISSING or is not a directory.")
# --- Test importability using importlib ---
module_name_to_test = "src.chimera.core.orchestrator"
print(f"\n--- Testing importability of '{module_name_to_test}' using importlib ---")
spec = None
try:
# Clear any previous import attempts from sys.modules that might interfere
if module_name_to_test in sys.modules:
del sys.modules[module_name_to_test]
# Also potentially clear parent modules if issues persist
# if "src.chimera.core" in sys.modules: del sys.modules["src.chimera.core"]
# if "src.chimera" in sys.modules: del sys.modules["src.chimera"]
# if "src" in sys.modules: del sys.modules["src"]
spec = importlib.util.find_spec(module_name_to_test)
except Exception as e:
print(f"[ERROR] Exception during importlib.util.find_spec: {type(e).__name__}: {e}")
traceback.print_exc()
if spec is None:
print(f"[FAIL] importlib.util.find_spec could NOT find module '{module_name_to_test}'.")
print(" This means Python's import machinery cannot locate this module.")
print(" Double-check directory names, __init__.py files, and potential typos.")
else:
print(f"[OK] importlib.util.find_spec found module '{module_name_to_test}'.")
print(f" Module Location Hint: {spec.origin}")
# If found, try to actually import it to see if loading fails
print(f"\n--- Attempting direct import of '{module_name_to_test}' using importlib.import_module ---")
try:
imported_module = importlib.import_module(module_name_to_test)
print(f"[OK] Successfully imported '{module_name_to_test}'. Module type: {type(imported_module)}")
# Try accessing the function
if hasattr(imported_module, 'run_analysis'):
print("[OK] Function 'run_analysis' found in the imported module.")
else:
print("[ERROR] Function 'run_analysis' NOT FOUND in the imported module!")
except Exception as e:
print(f"[FAIL] Error occurred DURING import of '{module_name_to_test}':")
traceback.print_exc() # Print the full traceback for the import error
print("\n--- Attempting original failing import ---")
try:
# Ensure sys.modules cache is clean before this attempt too
if module_name_to_test in sys.modules: del sys.modules[module_name_to_test]
from src.chimera.core.orchestrator import run_analysis
print("[OK] Original 'from ... import ...' statement SUCCEEDED.")
# If this succeeds now, the issue might have been temporary or fixed by restart
except ModuleNotFoundError:
print("[FAIL] Original 'from ... import ...' statement FAILED with ModuleNotFoundError.")
print(" Refer to the importlib test above for clues.")
traceback.print_exc() # Also print traceback for ModuleNotFoundError
except Exception as e:
print(f"[FAIL] Original 'from ... import ...' statement FAILED with a different error:")
traceback.print_exc()
print("\n--- End of Debug Script ---")
# Prevent Gradio from starting since imports might have failed
# ===============================================================
# == COMMENT OUT OR REMOVE GRADIO CODE BELOW FOR THIS TEST RUN ==
# ===============================================================
# import gradio as gr
# from src.chimera.utils.logging_config import setup_logging, logger # This import would also fail if orchestrator fails
# from src.chimera.config import GEMINI_API_KEY
# # Setup logging as soon as the app starts
# # setup_logging() # Comment out if logging_config import fails
# # Check essential configurations on startup
# # if not GEMINI_API_KEY:
# # # logger.error("CRITICAL: GEMINI_API_KEY is not set. The application might not function correctly.")
# # print("CRITICAL: GEMINI_API_KEY is not set.") # Use print during early debug
# async def chimera_interface(query: str):
# # Placeholder implementation for debugging
# print(f"Gradio interface received query (debug): {query}")
# if not query:
# return "Please enter a query."
# # logger.info(f"Gradio interface received query: {query}")
# try:
# # Need to import run_analysis successfully first
# from src.chimera.core.orchestrator import run_analysis
# result = await run_analysis(query)
# # logger.info("Gradio interface processing complete.")
# print("Gradio interface processing complete (debug).")
# return result
# except NameError:
# print("Error: run_analysis could not be imported for Gradio.")
# return "Error: Backend function 'run_analysis' is not available due to import issues."
# except Exception as e:
# # logger.exception("Error in Gradio interface call to run_analysis.")
# print(f"Error in Gradio interface call (debug): {e}")
# traceback.print_exc()
# return f"An unexpected error occurred in the backend: {e}"
# # --- Gradio UI Definition ---
# with gr.Blocks(theme=gr.themes.Soft(), title="Project Chimera (Debug Mode)") as demo:
# gr.Markdown(
# """
# # Project Chimera : Real-Time Global Analysis Engine (DEBUG MODE)
# Enter your query to analyze real-time data from SERP and other sources using Gemini.
# (Example: "Analyze recent news about renewable energy investments in the US")
# """
# )
# # ... rest of your Gradio UI definition ...
# # --- Launching the App ---
# if __name__ == "__main__":
# # logger.info("Starting Gradio application...")
# print("Starting Gradio application (debug)...")
# # demo.launch() # Don't launch Gradio if imports fail |