Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files14 unmodified lines1516171819202112 unmodified lines343536373839403 unmodified lines4445464748495051525354555657585960616211 unmodified lines747576777879801 unmodified line8283848586878814 unmodified linessys.path.insert(0, TARGET_SITE_PATH)site.addsitedir(TARGET_SITE_PATH)# Check and boot the persistent engine compiled in your previous runtry:from llama_cpp import Llamaprint("π Perfect! Pre-compiled engine found in /data. Loading instantly...")12 unmodified linesfrom huggingface_hub import hf_hub_downloadimport spaces# 2. FIXED MODEL PATH MAPS (Bypasses the 404 Error)print("Checking persistent storage for AI model weights...")# Model 1: The Main 27B Monster for GPU (3.9 GB)3 unmodified lineslocal_dir="/data")# Model 2: FIXED REPOSITORY PATH AND FILE LAYOUT# Changes repo to LiquidAI and filename to use dot quantization separation to fix the 404 crash!path_moe = hf_hub_download(repo_id="LiquidAI/LFM2.5-8B-A1B-GGUF",filename="LFM2.5-8B-A1B.Q4_K_M.gguf",local_dir="/data")# Load the MoE model globally on the free CPU thread so it never falls asleepprint("Initializing Liquid 8B MoE on active CPU thread...")llm_cpu = Llama(model_path=path_moe, n_ctx=4096, n_gpu_layers=0, verbose=False)# 3. ENDPOINT FUNCTION WORKFLOWS@spaces.GPU(duration=60)def generate_27b(prompt):clean_prompt = str(prompt).strip()11 unmodified linesclean_prompt = str(prompt).strip()if not clean_prompt: return "Empty prompt."# Liquid AI specific chat markerssystem_tool_prompt = "You are an advanced AI agent with Tool Calling capabilities."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"1 unmodified linetry: return response["choices"]["text"]except: return str(response)# 4. GRADIO DUAL TAB REGISTRYwith gr.Blocks(title="Resilient AI Hub") as demo:gr.Markdown("# π³ Unstoppable Split-Brain AI Hub")14 unmodified lines1516171819202112 unmodified lines343536373839403 unmodified lines4445464748495051525354555657585960616211 unmodified lines747576777879801 unmodified line8283848586878814 unmodified linessys.path.insert(0, TARGET_SITE_PATH)site.addsitedir(TARGET_SITE_PATH)# Pull the pre-compiled llama-cpp wheel built in your previous runtime passtry:from llama_cpp import Llamaprint("π Perfect! Pre-compiled engine found in /data. Loading instantly...")12 unmodified linesfrom huggingface_hub import hf_hub_downloadimport spaces# 2. UPDATED MODEL WORKSPACE INDEXES (Uses your exact link maps!)print("Checking persistent storage for AI model weights...")# Model 1: The Main 27B Monster for GPU (3.9 GB)3 unmodified lineslocal_dir="/data")# Model 2: YOUR EXACT WORKING LINK SWAP# Points precisely to the repo and file schema you provided to eliminate the 404 crash!path_moe = hf_hub_download(repo_id="LiquidAI/LFM2-8B-A1B-GGUF",filename="LFM2-8B-A1B-Q4_K_M.gguf",local_dir="/data")# Initialize the 8B MoE model to the unmetered CPU threadprint("Initializing Liquid 8B MoE on active CPU thread...")llm_cpu = Llama(model_path=path_moe, n_ctx=4096, n_gpu_layers=0, verbose=False)# 3. ENDPOINT Workflows@spaces.GPU(duration=60)def generate_27b(prompt):clean_prompt = str(prompt).strip()11 unmodified linesclean_prompt = str(prompt).strip()if not clean_prompt: return "Empty prompt."# Liquid AI specific instruction tagssystem_tool_prompt = "You are an advanced AI agent with Tool Calling capabilities."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"1 unmodified linetry: return response["choices"]["text"]except: return str(response)# 4. GRADIO MULTI-TAB MAPPING DESIGNwith gr.Blocks(title="Resilient AI Hub") as demo:gr.Markdown("# π³ Unstoppable Split-Brain AI Hub")
app.py+10-10