NimaKL commited on
Commit
57ec298
Β·
1 Parent(s): 1ce5a07

Upload app-gradle.py

Browse files
Files changed (1) hide show
  1. app-gradle.py +28 -0
app-gradle.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
3
+
4
+ model_name = "NimaKL/FireWatch_tiny_75k"
5
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
6
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
7
+
8
+ def predict(text):
9
+ inputs = tokenizer(text, return_tensors="pt")
10
+ outputs = model(**inputs)
11
+ logits = outputs.logits
12
+ label_id = logits.argmax(axis=1).item()
13
+ return "Danger of fire hazard!" if label_id == 1 else "It is unlikely that a fire will start in this area."
14
+
15
+ io = gr.Interface(
16
+ fn=predict,
17
+ inputs="text",
18
+ outputs="text",
19
+ title="FireWatch",
20
+ description="Predict whether a data row describes a fire hazard or not.",
21
+ output_description="Prediction",
22
+ examples=[['-26.76123, 147.15512, 393.02, 203.63'], ['-26.7598, 147.14514, 361.54, 79.4'], ['-25.70059, 149.48932, 313.9, 5.15'], ['-24.4318, 151.83102, 307.98, 8.79'], ['-23.21878, 148.91298, 314.08, 7.4'], ['7.87518, 19.9241, 316.32, 39.63'], ['-20.10942, 148.14326, 314.39, 8.8'], ['7.87772, 19.9048, 304.14, 13.43'], ['-20.79866, 124.46834, 366.74, 89.06']]
23
+ ,
24
+ output_component_names=["Prediction"],
25
+ theme="Streamlit"
26
+ )
27
+
28
+ io.launch()