benchaffe commited on
Commit
4cb16e0
·
verified ·
1 Parent(s): ba3eaa6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -11
app.py CHANGED
@@ -3,18 +3,28 @@ from transformers import pipeline
3
 
4
  model = pipeline("token-classification", model="benchaffe/Bert-RAdam-Large", aggregation_strategy="simple")
5
 
 
 
 
 
 
 
 
 
 
 
6
  def predict(text):
7
- result = model(text)
8
- with open("log.jsonl", "a") as f:
9
- import json
10
- from datetime import datetime
11
- log_entry = {
12
- "timestamp": datetime.now().isoformat(),
13
- "input": text,
14
- "prediction": result
15
- }
16
- f.write(json.dumps(log_entry) + "\n")
17
- return result
18
 
19
  interface = gr.Interface(fn=predict, inputs="text", outputs="json", title="Abbreviation Detector")
20
  interface.launch()
 
3
 
4
  model = pipeline("token-classification", model="benchaffe/Bert-RAdam-Large", aggregation_strategy="simple")
5
 
6
+ def to_serializable(obj):
7
+ if isinstance(obj, (float, int, str, bool, type(None))):
8
+ return obj
9
+ elif isinstance(obj, dict):
10
+ return {k: to_serializable(v) for k, v in obj.items()}
11
+ elif isinstance(obj, list):
12
+ return [to_serializable(i) for i in obj]
13
+ else:
14
+ return str(obj)
15
+
16
  def predict(text):
17
+ result = model(text)
18
+ with open("log.jsonl", "a") as f:
19
+ import json
20
+ from datetime import datetime
21
+ log_entry = {
22
+ "timestamp": datetime.now().isoformat(),
23
+ "input": text,
24
+ "prediction": to_serializable(result)
25
+ }
26
+ f.write(json.dumps(log_entry) + "\n")
27
+ return result
28
 
29
  interface = gr.Interface(fn=predict, inputs="text", outputs="json", title="Abbreviation Detector")
30
  interface.launch()