File size: 1,345 Bytes
8a0fb54
9799278
 
4623550
9799278
4623550
9799278
 
 
4623550
 
 
 
 
 
 
 
 
 
 
 
 
8a0fb54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4623550
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
import streamlit as st
from transformers import pipeline

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

def analyze_sentiment(text):
    """
    This function takes user input, performs sentiment analysis using your fine-tuned model,
    maps the predicted labels to desired sentiment categories, and returns the sentiment.
    """
    predictions = nlp_pipeline(text)
    label = predictions[0]["label"]
    probability = predictions[0]["score"]

    sentiment_map = {
        "entailment": "Negative",  # Map based on your fine-tuned model's labels
        "contradiction": "Neutral",
        "neutral": "Positive",
    }

    sentiment = sentiment_map.get(label.lower(), "Unknown")
    return sentiment, label, probability

# Streamlit app layout
st.title("Mongolian Sentiment Analysis")
st.write("Enter some text to analyze its sentiment.")

user_input = st.text_area("Text input")

if st.button("Analyze"):
    if user_input:
        sentiment, label, probability = analyze_sentiment(user_input)
        st.write(f"**Sentiment:** {sentiment}")
        st.write(f"**Label:** {label}")
        st.write(f"**Probability:** {probability:.2f}")
    else:
        st.write("Please enter some text to analyze.")