Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
4 |
+
|
5 |
+
# Load the trained model and tokenizer
|
6 |
+
model_path = 'viv/AIKIA'
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
8 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_path)
|
9 |
+
|
10 |
+
# Preprocessing function for Greek text
|
11 |
+
def preprocessing_greek(text):
|
12 |
+
# Your preprocessing steps
|
13 |
+
text = text.lower() # Example step
|
14 |
+
return text
|
15 |
+
|
16 |
+
# Prediction function
|
17 |
+
def predict(sentence):
|
18 |
+
model.eval()
|
19 |
+
preprocessed_sentence = preprocessing_greek(sentence)
|
20 |
+
inputs = tokenizer(preprocessed_sentence, return_tensors="pt")
|
21 |
+
with torch.no_grad():
|
22 |
+
outputs = model(**inputs)
|
23 |
+
logits = outputs.logits
|
24 |
+
probabilities = torch.nn.functional.softmax(logits, dim=1)
|
25 |
+
predicted_label = torch.argmax(probabilities, dim=1).item()
|
26 |
+
labels_map = {0: 'NOT', 1: 'OFFENSIVE'}
|
27 |
+
return labels_map[predicted_label], probabilities.tolist()
|
28 |
+
|
29 |
+
# Gradio Interface
|
30 |
+
iface = gr.Interface(fn=predict, inputs="text", outputs=["text", "json"])
|
31 |
+
iface.launch()
|