Spaces:
Runtime error
Runtime error
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.") | |