NimaKL commited on
Commit
062dcc7
·
1 Parent(s): f1cac65

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -1
app.py CHANGED
@@ -1,3 +1,30 @@
1
  import gradio as gr
 
2
 
3
- gr.Interface.load("models/NimaKL/FireWatch_tiny_75k").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
3
 
4
+ model_name = "models/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 "likely" if label_id == 1 else "unlikely"
14
+
15
+ io = gr.Interface(
16
+ fn=predict,
17
+ inputs="text",
18
+ outputs="text",
19
+ title="FireWatch",
20
+ description="Predict whether a given text describes a fire hazard or not.",
21
+ output_description="Prediction",
22
+ examples=[
23
+ ["Dry and windy weather can increase the risk of wildfires."],
24
+ ["It is unlikely that a fire will start in this area."]
25
+ ],
26
+ output_component_names=["Prediction"],
27
+ theme="compact"
28
+ )
29
+
30
+ io.launch()