Spaces:
Sleeping
Sleeping
Commit ·
0586f3b
1
Parent(s): f082cb2
cleanup
Browse files
app.py
CHANGED
|
@@ -5,15 +5,10 @@ import re
|
|
| 5 |
import subprocess
|
| 6 |
import tempfile
|
| 7 |
from transformers import pipeline
|
| 8 |
-
from transformers.utils import logging as hf_logging
|
| 9 |
|
| 10 |
|
| 11 |
MODEL_ID = "ejschwartz/oo-method-test-model-bylibrary"
|
| 12 |
|
| 13 |
-
hf_logging.set_verbosity_debug()
|
| 14 |
-
hf_logging.enable_default_handler()
|
| 15 |
-
hf_logging.enable_explicit_format()
|
| 16 |
-
|
| 17 |
classifier = pipeline(
|
| 18 |
"text-classification",
|
| 19 |
model=MODEL_ID,
|
|
@@ -33,8 +28,6 @@ def run_model(text):
|
|
| 33 |
best_label = max(confidences, key=lambda entry: entry["confidence"])["label"] if confidences else "unknown"
|
| 34 |
return {"label": best_label, "confidences": confidences}
|
| 35 |
|
| 36 |
-
print("Model loaded")
|
| 37 |
-
|
| 38 |
def get_all_dis(bname, addrs=None):
|
| 39 |
|
| 40 |
anafile = tempfile.NamedTemporaryFile(prefix=os.path.basename(bname) + "_", suffix=".bat_ana")
|
|
@@ -121,8 +114,6 @@ with gr.Blocks() as demo:
|
|
| 121 |
|
| 122 |
def file_change_fn(file, progress=gr.Progress()):
|
| 123 |
|
| 124 |
-
print("File change")
|
| 125 |
-
|
| 126 |
if file is None:
|
| 127 |
return {col: gr.update(visible=False),
|
| 128 |
all_dis_state: None}
|
|
@@ -142,16 +133,9 @@ with gr.Blocks() as demo:
|
|
| 142 |
|
| 143 |
def function_change_fn(selected_fun, fun_data):
|
| 144 |
|
| 145 |
-
print("Selected function:", selected_fun)
|
| 146 |
-
|
| 147 |
disassembly_str = fun_data[int(selected_fun, 16)].decode("utf-8")
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
load_results = run_model(disassembly_str)
|
| 151 |
-
except Exception as e:
|
| 152 |
-
print("Error evaluating model:", e)
|
| 153 |
-
raise
|
| 154 |
-
print("Done with model")
|
| 155 |
top_k = {e['label']: e['confidence'] for e in load_results['confidences']}
|
| 156 |
|
| 157 |
return {disassembly: gr.update(value=disassembly_str),
|
|
|
|
| 5 |
import subprocess
|
| 6 |
import tempfile
|
| 7 |
from transformers import pipeline
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
MODEL_ID = "ejschwartz/oo-method-test-model-bylibrary"
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
classifier = pipeline(
|
| 13 |
"text-classification",
|
| 14 |
model=MODEL_ID,
|
|
|
|
| 28 |
best_label = max(confidences, key=lambda entry: entry["confidence"])["label"] if confidences else "unknown"
|
| 29 |
return {"label": best_label, "confidences": confidences}
|
| 30 |
|
|
|
|
|
|
|
| 31 |
def get_all_dis(bname, addrs=None):
|
| 32 |
|
| 33 |
anafile = tempfile.NamedTemporaryFile(prefix=os.path.basename(bname) + "_", suffix=".bat_ana")
|
|
|
|
| 114 |
|
| 115 |
def file_change_fn(file, progress=gr.Progress()):
|
| 116 |
|
|
|
|
|
|
|
| 117 |
if file is None:
|
| 118 |
return {col: gr.update(visible=False),
|
| 119 |
all_dis_state: None}
|
|
|
|
| 133 |
|
| 134 |
def function_change_fn(selected_fun, fun_data):
|
| 135 |
|
|
|
|
|
|
|
| 136 |
disassembly_str = fun_data[int(selected_fun, 16)].decode("utf-8")
|
| 137 |
+
|
| 138 |
+
load_results = run_model(disassembly_str)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
top_k = {e['label']: e['confidence'] for e in load_results['confidences']}
|
| 140 |
|
| 141 |
return {disassembly: gr.update(value=disassembly_str),
|