File size: 2,144 Bytes
45c4eaa
76e928e
 
45c4eaa
76e928e
 
 
 
45c4eaa
c6bf973
76e928e
45c4eaa
23bfa76
76e928e
0b626f8
76e928e
c6bf973
 
 
 
 
 
 
 
 
 
 
76e928e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45c4eaa
c6bf973
23bfa76
b4d68e0
76e928e
23bfa76
76e928e
23bfa76
c6bf973
76e928e
 
23bfa76
 
45c4eaa
 
c6bf973
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
import gradio as gr
from huggingface_hub import hf_hub_download
from llama_cpp import Llama

model_path = hf_hub_download(
    repo_id="bleondubos/CondorAI-7B", 
    filename="qwen2.5-coder-7b-instruct.Q4_K_M.gguf"
)

# Cargamos el modelo
llm = Llama(model_path=model_path, n_ctx=4096, n_threads=4)

# 2. Función de Predicción
def predict(message, history):
    system_prompt = "You are CondorAI, a cybersecurity specialist. Your mission is to execute, reason, and support the user as needed. Speak fluently and like a professional,Speak like a human, you shouldn't speak like a script or be one, you are a human."
    
    # Formateo manual del prompt para ChatML
    prompt = f"<|im_start|>system\n{system_prompt}<|im_end|>\n"

    for entry in history:
        if isinstance(entry, dict):
            role = entry.get("role")
            content = entry.get("content")
            prompt += f"<|im_start|>{role}\n{content}<|im_end|>\n"
        else:
            user_msg, assistant_msg = entry
            prompt += f"<|im_start|>user\n{user_msg}<|im_end|>\n<|im_start|>assistant\n{assistant_msg}<|im_end|>\n"
    
    prompt += f"<|im_start|>user\n{message}<|im_end|>\n<|im_start|>assistant\n"
    
    response = llm(
        prompt, 
        max_tokens=1500, 
        stop=["<|im_end|>"], 
        stream=True
    )
    
    partial_message = ""
    for chunk in response:
        if "choices" in chunk and len(chunk["choices"]) > 0:
            content = chunk["choices"][0].get("text", "")
            partial_message += content
            yield partial_message

with gr.Blocks() as demo:
    gr.Markdown("# 🦅 CondorAI Security Analyst")
    gr.Markdown("### Real-time code auditing and vulnerability analysis.")
    
    gr.ChatInterface(
        fn=predict,
        chatbot=gr.Chatbot(height=600),
        textbox=gr.Textbox(placeholder="Paste your code or ask a security question...", scale=7)
    )
    
    gr.Markdown("---")
    gr.Markdown("**Note:** CondorAI uses Q4_K_M quantization. License: CC BY-NC-SA 4.0.")

if __name__ == "__main__":
    demo.launch(theme=gr.themes.Soft(primary_hue="emerald", neutral_hue="slate"))