Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os, subprocess, urllib.request, tarfile, sys
|
| 2 |
+
from huggingface_hub import hf_hub_download
|
| 3 |
+
|
| 4 |
+
repo = "HauhauCS/Gemma-4-E2B-Uncensored-HauhauCS-Aggressive"
|
| 5 |
+
model_file = "Gemma-4-E2B-Uncensored-HauhauCS-Aggressive-Q5_K_P.gguf"
|
| 6 |
+
mmproj_file = "mmproj-Gemma-4-E2B-Uncensored-HauhauCS-Aggressive-f16.gguf"
|
| 7 |
+
LLAMA_RELEASE = "https://github.com/ggml-org/llama.cpp/releases/download/b9294/llama-b9294-bin-ubuntu-x64.tar.gz"
|
| 8 |
+
|
| 9 |
+
BIN_DIR = "llama-bin"
|
| 10 |
+
PORT = 7860
|
| 11 |
+
|
| 12 |
+
if not os.path.exists(BIN_DIR):
|
| 13 |
+
os.makedirs(BIN_DIR)
|
| 14 |
+
tar_path = os.path.join(BIN_DIR, "llama.tar.gz")
|
| 15 |
+
print("Downloading llama-server binary...")
|
| 16 |
+
urllib.request.urlretrieve(LLAMA_RELEASE, tar_path)
|
| 17 |
+
with tarfile.open(tar_path, "r:gz") as tar:
|
| 18 |
+
tar.extractall(path=BIN_DIR)
|
| 19 |
+
os.remove(tar_path)
|
| 20 |
+
|
| 21 |
+
llama_dir = [d for d in os.listdir(BIN_DIR) if d.startswith("llama-")][0]
|
| 22 |
+
llama_server = os.path.join(BIN_DIR, llama_dir, "llama-server")
|
| 23 |
+
os.chmod(llama_server, 0o755)
|
| 24 |
+
|
| 25 |
+
print("Downloading model...")
|
| 26 |
+
model_path = hf_hub_download(repo, model_file)
|
| 27 |
+
mmproj_path = hf_hub_download(repo, mmproj_file)
|
| 28 |
+
|
| 29 |
+
env = os.environ.copy()
|
| 30 |
+
env["LD_LIBRARY_PATH"] = os.path.join(BIN_DIR, llama_dir) + ":" + env.get("LD_LIBRARY_PATH", "")
|
| 31 |
+
|
| 32 |
+
cmd = [
|
| 33 |
+
llama_server,
|
| 34 |
+
"-m", model_path,
|
| 35 |
+
"--mmproj", mmproj_path,
|
| 36 |
+
"--host", "0.0.0.0",
|
| 37 |
+
"--port", str(PORT),
|
| 38 |
+
"-c", "4096",
|
| 39 |
+
"-t", "2",
|
| 40 |
+
"--no-mmap",
|
| 41 |
+
"--reasoning", "off"
|
| 42 |
+
]
|
| 43 |
+
|
| 44 |
+
print(f"Starting llama-server on port {PORT}...")
|
| 45 |
+
subprocess.run(cmd, env=env)
|