J Z
Update app.py
7b9dba6 verified
Raw
History Blame Contribute Delete
2.25 kB
import os
import sys
import subprocess
import time
# Configure paths
DARWIN_SCRIPTS_PATH = "/data/DarwinChatbot/scripts"
DARWIN_STREAM_CHUNKS_PATH = "/data/DarwinChatbot/stream/chunks"
OLLAMA_PATH = "/data/DarwinChatbot/ollama"
CONDA_PATH = "/data/miniconda3"
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
# First, copy app_hf.py to the scripts directory using cp command
print(f"Copying app_hf.py to {DARWIN_SCRIPTS_PATH}")
app_hf_source = os.path.join(CURRENT_DIR, "app_hf.py")
app_hf_dest = os.path.join(DARWIN_SCRIPTS_PATH, "app_hf.py")
try:
subprocess.run(f"cp {app_hf_source} {app_hf_dest}", shell=True, check=True)
print(f"Successfully copied app_hf.py to {app_hf_dest}")
except subprocess.CalledProcessError as e:
print(f"Error copying app_hf.py: {e}")
sys.exit(1)
# Make sure the destination directory exists
subprocess.run(f"mkdir -p {DARWIN_STREAM_CHUNKS_PATH}", shell=True, check=True)
# Copy the chunk folders to the stream/chunks directory
chunk_folders = ["blinking_chunks", "head_motion_chunks", "img2vid_chunks"]
for folder in chunk_folders:
source_path = os.path.join(CURRENT_DIR, folder)
dest_path = os.path.join(DARWIN_STREAM_CHUNKS_PATH, folder)
print(f"Copying {folder} to {dest_path}")
try:
# Use rsync to copy the entire directory and its contents
subprocess.run(f"rsync -av {source_path}/ {dest_path}/", shell=True, check=True)
print(f"Successfully copied {folder} to {dest_path}")
except subprocess.CalledProcessError as e:
print(f"Error copying {folder}: {e}")
sys.exit(1)
# Start Ollama in background using basic shell command
print("Starting Ollama server...")
subprocess.run(f"{OLLAMA_PATH} serve &", shell=True)
# Wait a moment for Ollama to initialize
time.sleep(3)
# Change to the DarwinChatbot scripts directory
os.chdir(DARWIN_SCRIPTS_PATH)
# Configure environment for NiceGUI
os.environ["NICEGUI_PORT"] = "7860"
os.environ["NICEGUI_HOST"] = "0.0.0.0"
# Run app_hf.py instead of app.py with conda activate
print("Starting Darwin Avatar app with conda environment...")
conda_command = f". {CONDA_PATH}/bin/activate DarwinChatbot && python app_hf.py"
subprocess.run(conda_command, shell=True, executable="/bin/bash")