File size: 1,899 Bytes
f226ee7
cdbd54d
f226ee7
cdbd54d
 
f226ee7
cdbd54d
42e3c1c
cdbd54d
42e3c1c
cdbd54d
 
 
 
 
 
 
 
 
 
42e3c1c
 
cdbd54d
 
 
 
 
 
 
 
 
 
 
 
 
 
42e3c1c
 
 
 
cdbd54d
42e3c1c
 
f226ee7
cdbd54d
 
 
 
 
 
 
 
 
 
 
 
 
f226ee7
42e3c1c
 
 
 
 
 
f226ee7
cdbd54d
f226ee7
cdbd54d
42e3c1c
f226ee7
cdbd54d
 
 
 
42e3c1c
cdbd54d
42e3c1c
cdbd54d
f226ee7
cdbd54d
 
 
42e3c1c
f226ee7
cdbd54d
 
 
 
 
42e3c1c
cdbd54d
42e3c1c
cdbd54d
42e3c1c
cdbd54d
42e3c1c
cdbd54d
42e3c1c
cdbd54d
 
 
 
f226ee7
42e3c1c
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import gradio as gr
from llama_cpp import Llama

MODEL_REPO = "mahmoudalyosify/Horus-OSINT"
MODEL_FILE = "llama-3-8b-instruct.Q4_K_M.gguf"

SYSTEM_PROMPT = """You are Horus-OSINT.

You specialize in:

- Open Source Intelligence (OSINT)
- Cybersecurity
- Threat Intelligence
- Military Analysis
- Geopolitical Analysis
- Risk Assessment

Always provide structured, factual and evidence-based answers.
If uncertain, say so.
Never fabricate sources.
"""

print("Loading model...")

llm = Llama.from_pretrained(
    repo_id=MODEL_REPO,
    filename=MODEL_FILE,
    n_ctx=4096,
    n_threads=8,
    verbose=False,
)

print("Model loaded.")


def chat(message, history):

    messages = [
        {
            "role": "system",
            "content": SYSTEM_PROMPT,
        }
    ]

    for user, assistant in history:
        messages.append(
            {
                "role": "user",
                "content": user,
            }
        )
        messages.append(
            {
                "role": "assistant",
                "content": assistant,
            }
        )

    messages.append(
        {
            "role": "user",
            "content": message,
        }
    )

    output = ""

    stream = llm.create_chat_completion(
        messages=messages,
        stream=True,
        temperature=0.7,
        top_p=0.95,
        max_tokens=1024,
    )

    for chunk in stream:

        delta = chunk["choices"][0]["delta"]

        if "content" in delta:
            output += delta["content"]
            yield output


demo = gr.ChatInterface(
    fn=chat,
    title="🦅 Horus-OSINT",
    description="""
Open Source Intelligence Assistant

Examples:

• Summarize today's conflict in the Red Sea.

• Explain the MITRE ATT&CK framework.

• Create an OSINT collection plan for a ransomware group.

• Analyse this phishing email.
""",
    type="tuples",
)

demo.launch()