Gerard-1705
commited on
Commit
·
4a82d0d
1
Parent(s):
7c9bbea
Add application file
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
|
4 |
+
from transformers import AutoModelForSequenceClassification
|
5 |
+
import torch
|
6 |
+
|
7 |
+
from transformers import AutoTokenizer
|
8 |
+
|
9 |
+
|
10 |
+
tokenizer = AutoTokenizer.from_pretrained("Gerard-1705/bertin_base_climate_detection_es")
|
11 |
+
|
12 |
+
model = AutoModelForSequenceClassification.from_pretrained("Gerard-1705/bertin_base_climate_detection_es")
|
13 |
+
|
14 |
+
id2label = {0: "NEGATIVE", 1: "POSITIVE"}
|
15 |
+
label2id = {"NEGATIVE": 0, "POSITIVE": 1}
|
16 |
+
|
17 |
+
def inference_fun(user_input):
|
18 |
+
inputs = tokenizer(user_input, return_tensors="pt")
|
19 |
+
with torch.no_grad():
|
20 |
+
logits = model(**inputs).logits
|
21 |
+
predicted_class_id = logits.argmax().item()
|
22 |
+
output_tag = model.config.id2label[predicted_class_id]
|
23 |
+
|
24 |
+
return output_tag
|
25 |
+
|
26 |
+
iface = gr.Interface(fn=inference_fun, inputs="text", outputs="text")
|
27 |
+
iface.launch()
|