File size: 1,742 Bytes
baa31df
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81cf0c4
baa31df
 
fa6b908
baa31df
 
 
 
fa6b908
baa31df
 
 
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
60
61
62
63
64
65
66
import os
import subprocess
import sys

# --- 1. MAGIC INSTALLER ---
# This forces the computer to install the engine NOW, inside the correct folder.
def install_engine():
    print("⏳ Installing Brain Engine (Safe Mode)...")
    try:
        subprocess.check_call([
            sys.executable, "-m", "pip", "install", 
            "llama-cpp-python", 
            "--extra-index-url", "https://abetlen.github.io/llama-cpp-python/whl/cpu"
        ])
        print("✅ Engine Installed!")
    except Exception as e:
        print(f"❌ Install Failed: {e}")

# Try to import the library. If it fails, run the installer above.
try:
    import llama_cpp
except ImportError:
    install_engine()
    import llama_cpp

# --- 2. YOUR APP CODE ---
import gradio as gr
from huggingface_hub import hf_hub_download
from llama_cpp import Llama

print("Downloading EMET Brain...")
model_path = hf_hub_download(
    repo_id="pavanc21/EMET-Mistral-2.0-GGUF",
    filename="mistral-7b-v0.3.Q4_K_M.gguf"
)

print("Starting Engine...")
llm = Llama(
    model_path=model_path,
    n_ctx=2048,
    n_threads=2
)

def generate_response(message, history):
    prompt = f"""Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.

### Instruction:
{message}

### Input:


### Response:
"""
    output = llm(prompt, max_tokens=64, stop=["### Instruction:", "</s>"], echo=False)
    return output['choices'][0]['text'].strip()


interface = gr.ChatInterface(
    fn=generate_response,
    title="🤖 EMET 2.0 (Live)",
    description="My custom AI running 24/7 on Hugging Face.",
    examples=["Who created you?", "What is your purpose?"]
)

interface.launch()