ejschwartz's picture
Update app.py
8f0cd8c verified
raw
history blame
1.82 kB
import gradio as gr
import spaces
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
model_path = 'LLM4Binary/llm4decompile-6.7b-v2' # V2 Model
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype=torch.bfloat16).cuda()
@spaces.GPU
def predict(input_asm):
before = f"# This is the assembly code:\n"#prompt
after = "\n# What is the source code?\n"#prompt
input_prompt = before+input_asm.strip()+after
inputs = tokenizer(input_prompt, return_tensors="pt").to(model.device)
with torch.no_grad():
outputs = model.generate(**inputs, max_new_tokens=2048)### max length to 4096, max new tokens should be below the range
c_func_decompile = tokenizer.decode(outputs[0][len(inputs[0]):-1])
return c_func_decompile
demo = gr.Interface(fn=predict,
examples=["""undefined4 func0(float param_1,long param_2,int param_3)
{
int local_28;
int local_24;
local_24 = 0;
do {
local_28 = local_24;
if (param_3 <= local_24) {
return 0;
}
while (local_28 = local_28 + 1, local_28 < param_3) {
if ((double)((ulong)(double)(*(float *)(param_2 + (long)local_24 * 4) -
*(float *)(param_2 + (long)local_28 * 4)) &
SUB168(_DAT_00402010,0)) < (double)param_1) {
return 1;
}
}
local_24 = local_24 + 1;
} while( true );
}""","""
undefined8 __cdecl FUN_004025f0(byte *param_1,int param_2)
{
do {
*param_1 = ~*param_1;
*param_1 = *param_1 - 0x37;
*param_1 = *param_1 + 1;
param_1 = param_1 + 1;
param_2 = param_2 + -1;
} while (param_2 != 0);
return 0x3632000137;
}
"""],
inputs="text", outputs="text")
demo.queue()
demo.launch()