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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -11
app.py CHANGED
@@ -1,5 +1,7 @@
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
 
@@ -13,18 +15,31 @@ def to_serializable(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()
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  from transformers import pipeline
3
+ import json
4
+ from datetime import datetime
5
 
6
  model = pipeline("token-classification", model="benchaffe/Bert-RAdam-Large", aggregation_strategy="simple")
7
 
 
15
  else:
16
  return str(obj)
17
 
18
+ def log_interaction(input_text, prediction):
19
+ log_entry = {
20
+ "timestamp": datetime.now().isoformat(),
21
+ "input": input_text,
22
+ "prediction": to_serializable(prediction)
23
+ }
24
  with open("log.jsonl", "a") as f:
 
 
 
 
 
 
 
25
  f.write(json.dumps(log_entry) + "\n")
26
+
27
+ def predict(text):
28
+ result = model(text)
29
+ log_interaction(text, result)
30
  return result
31
 
32
+ with gr.Blocks() as demo:
33
+ gr.Markdown("## Biomedical Abbreviation Identifier")
34
+
35
+ with gr.Row():
36
+ input_box = gr.Textbox(label="Enter biomedical text")
37
+ output_box = gr.JSON(label="Model Prediction")
38
+
39
+ run_button = gr.Button("Submit")
40
+ run_button.click(fn=predict, inputs=input_box, outputs=output_box)
41
+
42
+ gr.Markdown("### Download Interaction Logs")
43
+ gr.File(label="Download Logs", value="log.jsonl")
44
+
45
+ demo.launch()