Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,15 +2,25 @@ import gradio as gr
|
|
| 2 |
import spaces
|
| 3 |
import transformers
|
| 4 |
|
| 5 |
-
|
|
|
|
|
|
|
| 6 |
|
| 7 |
@spaces.GPU
|
| 8 |
def predict(asm):
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
demo = gr.Interface(fn=predict,
|
| 13 |
-
examples=["
|
| 14 |
inputs="text", outputs="text")
|
| 15 |
demo.queue()
|
| 16 |
demo.launch()
|
|
|
|
| 2 |
import spaces
|
| 3 |
import transformers
|
| 4 |
|
| 5 |
+
model_path = 'LLM4Binary/llm4decompile-6.7b-v2' # V2 Model
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
| 7 |
+
model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype=torch.bfloat16).cuda()
|
| 8 |
|
| 9 |
@spaces.GPU
|
| 10 |
def predict(asm):
|
| 11 |
+
|
| 12 |
+
before = f"# This is the assembly code:\n"#prompt
|
| 13 |
+
after = "\n# What is the source code?\n"#prompt
|
| 14 |
+
input_prompt = before+input_asm.strip()+after
|
| 15 |
+
|
| 16 |
+
inputs = tokenizer(input_prompt, return_tensors="pt").to(model.device)
|
| 17 |
+
with torch.no_grad():
|
| 18 |
+
outputs = model.generate(**inputs, max_new_tokens=2048)### max length to 4096, max new tokens should be below the range
|
| 19 |
+
c_func_decompile = tokenizer.decode(outputs[0][len(inputs[0]):-1])
|
| 20 |
+
return c_func_decompile
|
| 21 |
|
| 22 |
demo = gr.Interface(fn=predict,
|
| 23 |
+
examples=["void ioabs_tcp_pre_select(connection c, int *n, struct pollfd *pfds) { struct ioabs_tcp *io; io = (struct ioabs_tcp*)c->io; c->s_index = *n; (*n)++; pfds[c->s_index].fd = c->s; pfds[c->s_index].events |= 0x0001; if (((size_t)(((c->wrb)->put + (c->wrb)->len - (c->wrb)->get) % (c->wrb)->len)) > 0) pfds[c->s_index].events |= 0x0004; }"],
|
| 24 |
inputs="text", outputs="text")
|
| 25 |
demo.queue()
|
| 26 |
demo.launch()
|