Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
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()
|