dwfwfwfwf commited on
Commit
cca76bd
·
verified ·
1 Parent(s): 7450b4b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -13
app.py CHANGED
@@ -3,41 +3,36 @@ import os
3
  import sys
4
 
5
  # --- Configuration ---
6
- # Hugging Face Spaces dynamically assigns a port OR uses 7860 by default.
7
- # We read the PORT environment variable if it exists, otherwise default to 7860.
8
  PORT = int(os.environ.get("PORT", 7860))
9
- HOST = "0.0.0.0" # Listen on all interfaces within the container
 
10
 
11
  # Choose the g4f install variant (ensure it matches requirements.txt)
12
- # Helps determine if certain dependencies might be missing if using slim/basic
13
  G4F_VARIANT = "all" # Change to 'slim' or 'base' if needed
14
 
15
  # --- --- --- --- ---
16
 
17
  print(f"--- Starting gpt4free API Server (variant: {G4F_VARIANT}) ---")
18
- print(f"Attempting to listen on: {HOST}:{PORT}")
19
  print(f"Python version: {sys.version}")
20
  print("-" * 30)
21
 
22
- # Construct the command to run the g4f FastAPI server
23
- # Corresponds to `python -m g4f --host 0.0.0.0 --port <PORT> --debug`
24
  command = [
25
- sys.executable, # Use the current python interpreter
26
  "-m",
27
  "g4f",
28
- "--host", HOST,
29
  "--port", str(PORT),
30
- "--debug" # Enable debug logging (useful for troubleshooting)
31
  ]
32
 
33
  print(f"Executing command: {' '.join(command)}")
34
  print("-" * 30, flush=True)
35
 
36
  try:
37
- # Run the command. This will block and keep the Space running
38
- # as long as the g4f server is active.
39
  process = subprocess.Popen(command, stdout=sys.stdout, stderr=sys.stderr)
40
- process.wait() # Wait for the process to exit
41
 
42
  except FileNotFoundError:
43
  print("\nERROR: Could not find the python interpreter or the 'g4f' module.")
 
3
  import sys
4
 
5
  # --- Configuration ---
 
 
6
  PORT = int(os.environ.get("PORT", 7860))
7
+ # Use --bind argument name instead of --host
8
+ BIND_ADDRESS = "0.0.0.0" # Listen on all interfaces within the container
9
 
10
  # Choose the g4f install variant (ensure it matches requirements.txt)
 
11
  G4F_VARIANT = "all" # Change to 'slim' or 'base' if needed
12
 
13
  # --- --- --- --- ---
14
 
15
  print(f"--- Starting gpt4free API Server (variant: {G4F_VARIANT}) ---")
16
+ print(f"Attempting to listen on: {BIND_ADDRESS}:{PORT}")
17
  print(f"Python version: {sys.version}")
18
  print("-" * 30)
19
 
20
+ # Construct the command using --bind instead of --host
 
21
  command = [
22
+ sys.executable,
23
  "-m",
24
  "g4f",
25
+ "--bind", BIND_ADDRESS, # Corrected argument
26
  "--port", str(PORT),
27
+ "--debug"
28
  ]
29
 
30
  print(f"Executing command: {' '.join(command)}")
31
  print("-" * 30, flush=True)
32
 
33
  try:
 
 
34
  process = subprocess.Popen(command, stdout=sys.stdout, stderr=sys.stderr)
35
+ process.wait()
36
 
37
  except FileNotFoundError:
38
  print("\nERROR: Could not find the python interpreter or the 'g4f' module.")