Spaces:
Running
on
Zero
Running
on
Zero
File size: 1,544 Bytes
08fedc0 cacf2b7 2c55bb6 b955ca1 08fedc0 536fde5 08fedc0 cacf2b7 77bd6a8 536fde5 08fedc0 3116465 000c947 3116465 02ecf35 08fedc0 |
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 |
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 );
}"""],
inputs="text", outputs="text")
demo.queue()
demo.launch()
|