sabonzo commited on
Commit
a34918a
·
verified ·
1 Parent(s): 5315214

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -10
app.py CHANGED
@@ -26,6 +26,7 @@ from langchain_community.tools.ddg_search import DuckDuckGoSearchRun
26
  from langchain_community.utilities.wikipedia import WikipediaAPIWrapper
27
  from langchain_community.tools import WikipediaQueryRun
28
  from langchain_experimental.tools import PythonREPLTool # Use with caution
 
29
  # Custom tools will be defined below (or implicitly used)
30
 
31
  # --- Setup Logging ---
@@ -737,22 +738,52 @@ with gr.Blocks() as demo:
737
 
738
  # --- App Launch ---
739
  if __name__ == "__main__":
740
- print("\n" + "-"*30 + " App Starting " + "-"*30)
741
- # Add Stockfish check here as well for local execution
742
- stockfish_path_startup = STOCKFISH_PATH
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
743
  try:
744
- # Use subprocess.run correctly
745
- p = subprocess.run([stockfish_path_startup, "version"], capture_output=True, text=True, timeout=5, check=False) # Add check=False
746
  if p.returncode == 0 and "Stockfish" in p.stdout:
747
- logging.info(f"✅ Stockfish found at '{stockfish_path_startup}' during startup.")
748
  else:
749
- logging.warning(f"⚠️ Stockfish check command failed or output unexpected at startup: '{stockfish_path_startup} version'. Return code: {p.returncode}. Output: {p.stdout.strip()} / {p.stderr.strip()}")
750
  except FileNotFoundError:
751
- logging.error(f"❌ Stockfish executable not found at '{stockfish_path_startup}' during startup. Chess analysis will fail.")
752
  except subprocess.TimeoutExpired:
753
- logging.warning(f"⚠️ Checking Stockfish version timed out during startup.")
754
  except Exception as e:
755
- logging.warning(f"⚠️ Error checking for Stockfish during startup: {e}")
 
756
 
757
 
758
  # Check for SPACE_HOST and SPACE_ID at startup for information
 
26
  from langchain_community.utilities.wikipedia import WikipediaAPIWrapper
27
  from langchain_community.tools import WikipediaQueryRun
28
  from langchain_experimental.tools import PythonREPLTool # Use with caution
29
+
30
  # Custom tools will be defined below (or implicitly used)
31
 
32
  # --- Setup Logging ---
 
738
 
739
  # --- App Launch ---
740
  if __name__ == "__main__":
741
+ print("\n" + "-"*30 + " App Starting (with explicit checks) " + "-"*30) # Modified print
742
+
743
+ # --- Add Explicit Checks Here ---
744
+ stockfish_path_found = shutil.which("stockfish")
745
+ ffmpeg_path_found = shutil.which("ffmpeg")
746
+
747
+ if stockfish_path_found:
748
+ print(f"✅ [Path Check] Stockfish found by shutil.which: {stockfish_path_found}")
749
+ else:
750
+ # Try common alternative paths if default PATH fails
751
+ common_paths = ["/usr/games/stockfish", "/usr/bin/stockfish"]
752
+ found_alt = False
753
+ for p in common_paths:
754
+ if os.path.exists(p) and os.access(p, os.X_OK):
755
+ print(f"⚠️ [Path Check] Stockfish NOT in PATH, but found at: {p}")
756
+ # Optional: Update STOCKFISH_PATH if found elsewhere
757
+ # STOCKFISH_PATH = p
758
+ # print(f" Attempting to use '{p}' for chess analysis.")
759
+ found_alt = True
760
+ break
761
+ if not found_alt:
762
+ print(f"❌ [Path Check] Stockfish NOT found by shutil.which in PATH and not in common locations.")
763
+
764
+ if ffmpeg_path_found:
765
+ print(f"✅ [Path Check] ffmpeg found by shutil.which: {ffmpeg_path_found}")
766
+ else:
767
+ print(f"❌ [Path Check] ffmpeg NOT found by shutil.which in system PATH.")
768
+ # --- End Explicit Checks ---
769
+
770
+
771
+ # --- Keep Original Startup Checks for Comparison (Optional but useful) ---
772
+ print("--- Running original Stockfish version check command ---")
773
+ stockfish_path_startup = STOCKFISH_PATH # Use the potentially updated path if you uncommented above
774
  try:
775
+ p = subprocess.run([stockfish_path_startup, "version"], capture_output=True, text=True, timeout=5, check=False)
 
776
  if p.returncode == 0 and "Stockfish" in p.stdout:
777
+ logging.info(f"✅ [Subprocess Check] Stockfish version command succeeded using '{stockfish_path_startup}'.")
778
  else:
779
+ logging.warning(f"⚠️ [Subprocess Check] Stockfish version command failed or output unexpected using '{stockfish_path_startup}'. Return code: {p.returncode}. Output: {p.stdout.strip()} / {p.stderr.strip()}")
780
  except FileNotFoundError:
781
+ logging.error(f"❌ [Subprocess Check] Stockfish executable not found at '{stockfish_path_startup}' when running command.")
782
  except subprocess.TimeoutExpired:
783
+ logging.warning(f"⚠️ [Subprocess Check] Checking Stockfish version timed out.")
784
  except Exception as e:
785
+ logging.warning(f"⚠️ [Subprocess Check] Error running Stockfish version command: {e}")
786
+ print("--- End original Stockfish version check command ---")
787
 
788
 
789
  # Check for SPACE_HOST and SPACE_ID at startup for information