Update app.py
Browse files
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 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 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()
|