| import gradio as gr |
| from huggingface_hub import hf_hub_download |
| from llama_cpp import Llama |
|
|
| |
| model_id = "Qwen/Qwen2.5-Coder-3B-Instruct-GGUF" |
| filename = "qwen2.5-coder-3b-instruct-q4_k_m.gguf" |
|
|
| print("Sedang mengunduh model... (Ini mungkin memakan waktu beberapa menit saat pertama kali berjalan)") |
| model_path = hf_hub_download(repo_id=model_id, filename=filename) |
| print("Model berhasil diunduh!") |
|
|
| |
| |
| llm = Llama( |
| model_path=model_path, |
| n_ctx=2048, |
| n_threads=2 |
| ) |
|
|
| |
| def chat_with_bot(message, history): |
| |
| prompt = "<|im_start|>system\nAnda adalah asisten Reverse Engineering dan Cybersecurity. Tugas Anda adalah membantu membaca Assembly, C/C++, merapikan pseudo-code dari dekompiler (Ghidra/IDA), dan menjelaskan logika malware/software.<|im_end|>\n" |
| |
| |
| for user_msg, bot_msg in history: |
| prompt += f"<|im_start|>user\n{user_msg}<|im_end|>\n" |
| prompt += f"<|im_start|>assistant\n{bot_msg}<|im_end|>\n" |
| |
| |
| prompt += f"<|im_start|>user\n{message}<|im_end|>\n<|im_start|>assistant\n" |
|
|
| |
| response = "" |
| output = llm( |
| prompt, |
| max_tokens=512, |
| stop=["<|im_end|>"], |
| stream=True |
| ) |
| for chunk in output: |
| delta = chunk['choices'][0]['text'] |
| response += delta |
| yield response |
|
|
| |
| demo = gr.ChatInterface( |
| fn=chat_with_bot, |
| title="Asisten Reverse Engineering (Qwen2.5-Coder-3B CPU)", |
| description="Berjalan di Hugging Face Free Tier. Masukkan potongan kode Assembly, x86, atau pseudo-code C Anda di sini untuk dianalisis.", |
| theme="soft" |
| ) |
|
|
| |
| if __name__ == "__main__": |
| demo.launch() |