File size: 1,895 Bytes
79113c6
018188f
1daf06e
02c7de4
5594654
018188f
 
79113c6
ac25ae6
 
79113c6
ac25ae6
 
018188f
 
 
 
 
0d9b200
 
 
 
 
 
 
 
 
 
 
 
 
 
018188f
420c4c1
ac25ae6
02c7de4
 
b89d49a
ac25ae6
02c7de4
 
b89d49a
02c7de4
b89d49a
02c7de4
 
 
 
 
b89d49a
02c7de4
 
 
b89d49a
02c7de4
9a919ff
c1bff9e
79113c6
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import streamlit as st
import torch
# from transformers import AutoTokenizer, AutoModelForSequenceClassification, AutoConfig
from transformers import pipeline

model_name = "peace4ever/roberta-large-finetuned-mongolian_v3"
pipeline = pipeline(task="sentiment-analysis", model=model_name)  # Load pre-trained pipeline

st.title("Эерэг? Сөрөг эсвэл аль нь ч биш?")
text = st.text_area("Өгүүлбэр оруулна уу?")

if text is not None:
    predictions = pipeline(text)

    col1, col2 = st.columns(2)
    col1.header("Sentiment")
    col2.header("Probability")

    for label, probability in zip(predictions[0]["label"], predictions[0]["score"]):
        if label == "entailment":
            sentiment = "Negative"
        elif label == "contradiction":
            sentiment = "Neutral"
        else label == "neutral":
            sentiment = "Positive" 

        col1.write(sentiment)
        col2.write(f"{probability:.2f}") 
    # label = predictions[0]["label"]
    # probability = predictions[0]["score"]
    # col1.write(label)
    # col2.write(f"{probability:.2f}")  



# tokenizer = AutoTokenizer.from_pretrained(model_name)
# model = AutoModelForSequenceClassification.from_pretrained(model_name)

# 
# encoded_input = tokenizer(text, return_tensors="pt")
# output = model(**encoded_input)

# label_map = {"positive": 0, "negative": 1, "neutral": 2}

# # Update the model configuration with custom labels
# config = AutoConfig.from_pretrained(model_name)
# config.label2id = {"positive": 0, "negative": 1, "neutral": 2}
# config.id2label = {0: "positive", 1: "negative", 2: "neutral"}
# config.save_pretrained(model_name)

# predicted_label_id = torch.argmax(output.logits, dim=1).item()
# id2label = model.config.id2label
# predicted_label = id2label[predicted_label_id]

# print("Predicted Class:", predicted_label)

# st.json(predicted_label)