File size: 2,250 Bytes
e233f2e
 
 
 
bb18fee
543ea03
e233f2e
7b9dba6
bb8b189
8bf01fc
5e76aba
 
 
 
 
 
 
 
 
 
 
 
e233f2e
7b9dba6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
543ea03
 
 
 
 
 
e233f2e
c395d65
 
 
543ea03
 
 
e233f2e
5e76aba
d8df6a1
5e76aba
4e62b13
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
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")