ejschwartz commited on
Commit
66ddc02
·
1 Parent(s): 4eca714

avoid gr.load

Browse files
Files changed (1) hide show
  1. app.py +24 -2
app.py CHANGED
@@ -4,8 +4,30 @@ import os
4
  import re
5
  import subprocess
6
  import tempfile
 
7
 
8
- model = gr.load("ejschwartz/oo-method-test-model-bylibrary", src="models")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  print("Model loaded")
11
 
@@ -121,7 +143,7 @@ with gr.Blocks() as demo:
121
  disassembly_str = fun_data[int(selected_fun, 16)].decode("utf-8")
122
  print("Evaluating model")
123
  try:
124
- load_results = model.fn(disassembly_str)
125
  except Exception as e:
126
  print("Error evaluating model:", e)
127
  raise
 
4
  import re
5
  import subprocess
6
  import tempfile
7
+ from transformers import pipeline
8
 
9
+
10
+ MODEL_ID = "ejschwartz/oo-method-test-model-bylibrary"
11
+
12
+
13
+ classifier = pipeline(
14
+ "text-classification",
15
+ model=MODEL_ID,
16
+ )
17
+
18
+ def run_model(text):
19
+ results = classifier(text, top_k=None, truncation=True)
20
+ if isinstance(results, dict):
21
+ results = [results]
22
+ if results and isinstance(results[0], list):
23
+ results = results[0]
24
+
25
+ confidences = [
26
+ {"label": entry["label"], "confidence": entry["score"]}
27
+ for entry in results
28
+ ]
29
+ best_label = max(confidences, key=lambda entry: entry["confidence"])["label"] if confidences else "unknown"
30
+ return {"label": best_label, "confidences": confidences}
31
 
32
  print("Model loaded")
33
 
 
143
  disassembly_str = fun_data[int(selected_fun, 16)].decode("utf-8")
144
  print("Evaluating model")
145
  try:
146
+ load_results = run_model(disassembly_str)
147
  except Exception as e:
148
  print("Error evaluating model:", e)
149
  raise