Spaces:
Sleeping
Sleeping
import gradio as gr | |
from fastai.text.all import * | |
from fastai.imports import * | |
learn = load_learner('lstm_clean.pkl') | |
labels = ['Low','High'] | |
article = '''<img src="https://corporateweb-v3-corporatewebv3damstrawebassetbuck-1lruglqypgb84.s3-ap-southeast-2.amazonaws.com/public/cta-2.jpg"/> ''' | |
examples = [ | |
[ | |
''' | |
A truck narrowly missed a person on a bicycle when they were reversing out of the depot on Friday. It was early morning before the sun was up and the ccyclist did not have a light. Fortunately the driver spotted the rider and braked heavily to avoid a collision. | |
'''], | |
[ | |
''' | |
When making a coffee I noticed the cord to the coffee machine was frayed and tagged it out of serivce. Now I need to find a barista!'''], | |
[ | |
''' | |
A worker was using a grinder in a confined space when he became dizzy from the fumes in the area and had to be helped out. The gas monitor he was using was found to be faulty and when the area was assessed with another monitor there was an unacceptably high level of CO2 in the area''']] | |
def predict(txt): | |
pred,_,probs = learn.predict(txt) | |
return {labels[i]: float(probs[i]) for i in range(len(labels))} | |
# return {labels[i]: float(probs[i]) for i in range(1)} | |
#return learn.predict(txt) | |
# formating of return f"Rating: {pred} prob: float(probs[pred_idx[i]]" | |
#return f'{pred}' | |
title = "Incident Prioritisation Tool" | |
description = "Triage new incidents based on a language AI that has been trained on the how similar incidents have been rated in the past" | |
interpretation = 'default' | |
demo = gr.Interface( | |
fn=predict, | |
title = title, | |
description = description, | |
interpretation = interpretation, | |
inputs=gr.Textbox(lines=10, placeholder="Enter Report here"), | |
outputs=gr.outputs.Label(num_top_classes=2), | |
examples=examples, | |
article=article, | |
allow_flagging="never" | |
) | |
demo.launch(debug=True, share=True) | |