Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,7 +15,7 @@ if TARGET_SITE_PATH not in sys.path:
|
|
| 15 |
sys.path.insert(0, TARGET_SITE_PATH)
|
| 16 |
site.addsitedir(TARGET_SITE_PATH)
|
| 17 |
|
| 18 |
-
#
|
| 19 |
try:
|
| 20 |
from llama_cpp import Llama
|
| 21 |
print("🚀 Perfect! Pre-compiled engine found in /data. Loading instantly...")
|
|
@@ -34,7 +34,7 @@ import gradio as gr
|
|
| 34 |
from huggingface_hub import hf_hub_download
|
| 35 |
import spaces
|
| 36 |
|
| 37 |
-
# 2.
|
| 38 |
print("Checking persistent storage for AI model weights...")
|
| 39 |
|
| 40 |
# Model 1: The Main 27B Monster for GPU (3.9 GB)
|
|
@@ -44,19 +44,19 @@ path_27b = hf_hub_download(
|
|
| 44 |
local_dir="/data"
|
| 45 |
)
|
| 46 |
|
| 47 |
-
# Model 2:
|
| 48 |
-
#
|
| 49 |
path_moe = hf_hub_download(
|
| 50 |
-
repo_id="LiquidAI/LFM2
|
| 51 |
-
filename="LFM2
|
| 52 |
local_dir="/data"
|
| 53 |
)
|
| 54 |
|
| 55 |
-
#
|
| 56 |
print("Initializing Liquid 8B MoE on active CPU thread...")
|
| 57 |
llm_cpu = Llama(model_path=path_moe, n_ctx=4096, n_gpu_layers=0, verbose=False)
|
| 58 |
|
| 59 |
-
# 3. ENDPOINT
|
| 60 |
@spaces.GPU(duration=60)
|
| 61 |
def generate_27b(prompt):
|
| 62 |
clean_prompt = str(prompt).strip()
|
|
@@ -74,7 +74,7 @@ def generate_moe_cpu(prompt):
|
|
| 74 |
clean_prompt = str(prompt).strip()
|
| 75 |
if not clean_prompt: return "Empty prompt."
|
| 76 |
|
| 77 |
-
# Liquid AI specific
|
| 78 |
system_tool_prompt = "You are an advanced AI agent with Tool Calling capabilities."
|
| 79 |
formatted = f"<|im_start|>system\n{system_tool_prompt}<|im_end|>\n<|im_start|>user\n{clean_prompt}<|im_end|>\n<|im_start|>assistant\n"
|
| 80 |
|
|
@@ -82,7 +82,7 @@ def generate_moe_cpu(prompt):
|
|
| 82 |
try: return response["choices"]["text"]
|
| 83 |
except: return str(response)
|
| 84 |
|
| 85 |
-
# 4. GRADIO
|
| 86 |
with gr.Blocks(title="Resilient AI Hub") as demo:
|
| 87 |
gr.Markdown("# 🌳 Unstoppable Split-Brain AI Hub")
|
| 88 |
|
|
|
|
| 15 |
sys.path.insert(0, TARGET_SITE_PATH)
|
| 16 |
site.addsitedir(TARGET_SITE_PATH)
|
| 17 |
|
| 18 |
+
# Pull the pre-compiled llama-cpp wheel built in your previous runtime pass
|
| 19 |
try:
|
| 20 |
from llama_cpp import Llama
|
| 21 |
print("🚀 Perfect! Pre-compiled engine found in /data. Loading instantly...")
|
|
|
|
| 34 |
from huggingface_hub import hf_hub_download
|
| 35 |
import spaces
|
| 36 |
|
| 37 |
+
# 2. UPDATED MODEL WORKSPACE INDEXES (Uses your exact link maps!)
|
| 38 |
print("Checking persistent storage for AI model weights...")
|
| 39 |
|
| 40 |
# Model 1: The Main 27B Monster for GPU (3.9 GB)
|
|
|
|
| 44 |
local_dir="/data"
|
| 45 |
)
|
| 46 |
|
| 47 |
+
# Model 2: YOUR EXACT WORKING LINK SWAP
|
| 48 |
+
# Points precisely to the repo and file schema you provided to eliminate the 404 crash!
|
| 49 |
path_moe = hf_hub_download(
|
| 50 |
+
repo_id="LiquidAI/LFM2-8B-A1B-GGUF",
|
| 51 |
+
filename="LFM2-8B-A1B-Q4_K_M.gguf",
|
| 52 |
local_dir="/data"
|
| 53 |
)
|
| 54 |
|
| 55 |
+
# Initialize the 8B MoE model to the unmetered CPU thread
|
| 56 |
print("Initializing Liquid 8B MoE on active CPU thread...")
|
| 57 |
llm_cpu = Llama(model_path=path_moe, n_ctx=4096, n_gpu_layers=0, verbose=False)
|
| 58 |
|
| 59 |
+
# 3. ENDPOINT Workflows
|
| 60 |
@spaces.GPU(duration=60)
|
| 61 |
def generate_27b(prompt):
|
| 62 |
clean_prompt = str(prompt).strip()
|
|
|
|
| 74 |
clean_prompt = str(prompt).strip()
|
| 75 |
if not clean_prompt: return "Empty prompt."
|
| 76 |
|
| 77 |
+
# Liquid AI specific instruction tags
|
| 78 |
system_tool_prompt = "You are an advanced AI agent with Tool Calling capabilities."
|
| 79 |
formatted = f"<|im_start|>system\n{system_tool_prompt}<|im_end|>\n<|im_start|>user\n{clean_prompt}<|im_end|>\n<|im_start|>assistant\n"
|
| 80 |
|
|
|
|
| 82 |
try: return response["choices"]["text"]
|
| 83 |
except: return str(response)
|
| 84 |
|
| 85 |
+
# 4. GRADIO MULTI-TAB MAPPING DESIGN
|
| 86 |
with gr.Blocks(title="Resilient AI Hub") as demo:
|
| 87 |
gr.Markdown("# 🌳 Unstoppable Split-Brain AI Hub")
|
| 88 |
|