sotosbarl commited on
Commit
52f43c9
1 Parent(s): ddfc8e5

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -0
app.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
2
+ import torch
3
+ import streamlit as st
4
+ device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
5
+
6
+ model_name = "MoritzLaurer/mDeBERTa-v3-base-mnli-xnli"
7
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
9
+
10
+ def classify(text)
11
+ input = tokenizer(text, truncation=True, return_tensors="pt")
12
+ output = model(input["input_ids"].to(device)) # device = "cuda:0" or "cpu"
13
+ prediction = torch.softmax(output["logits"][0], -1).tolist()
14
+ label_names = ["θυμός", "χαρά", "λύπη"]
15
+ prediction = {name: round(float(pred) * 100, 1) for pred, name in zip(prediction, label_names)}
16
+ return prediction
17
+
18
+
19
+ text = st.text_input('Enter some text:') # Input field for new text
20
+ if text:
21
+ st.text(classify(text))