Spaces:
Running
Running
File size: 2,104 Bytes
4fc93b8 | 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 | import os
import sys
import subprocess
def run_command(command, description):
"""Run a command and handle errors."""
print(f"\n{'='*60}")
print(f"π {description}")
print(f"{'='*60}")
try:
result = subprocess.run(command, shell=True, check=True)
return result.returncode == 0
except subprocess.CalledProcessError as e:
print(f"β Error: {description} failed")
return False
def main():
"""Setup the development environment."""
print("\n" + "="*60)
print("π Deepfake Detection Service - Backend Setup")
print("="*60)
print(f"β
Python version: {sys.version}")
# Determine OS for venv activation
is_windows = sys.platform == "win32"
venv_path = "venv"
# Create virtual environment
if not run_command(
f"{sys.executable} -m venv {venv_path}",
"Creating virtual environment"
):
sys.exit(1)
# Activate venv and install dependencies
if is_windows:
activate_cmd = f"{venv_path}\\Scripts\\activate && pip install -r requirements.txt"
else:
activate_cmd = f"source {venv_path}/bin/activate && pip install -r requirements.txt"
if not run_command(activate_cmd, "Installing dependencies"):
sys.exit(1)
# Create .env file if it doesn't exist
if not os.path.exists(".env"):
run_command("copy .env.example .env" if is_windows else "cp .env.example .env",
"Creating .env file from template")
print("\n" + "="*60)
print("β
Setup completed successfully!")
print("="*60)
print("\nπ Next steps:")
print(f" 1. Activate virtual environment:")
if is_windows:
print(f" {venv_path}\\Scripts\\activate")
else:
print(f" source {venv_path}/bin/activate")
print(f"\n 2. Start the server:")
print(f" python main.py")
print(f"\n 3. Visit http://127.0.0.1:8000/docs for interactive API docs")
print(f"\n 4. Check .env file for configuration options")
print("\n" + "="*60)
if __name__ == "__main__":
main()
|