Spaces:
Sleeping
Sleeping
File size: 1,882 Bytes
b836427 |
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 61 62 63 64 65 |
import streamlit as st
from transformers import pipeline
# Initialize sentiment analysis pipeline
sentiment_pipeline = pipeline("sentiment-analysis")
# Use a sarcasm detection model
sarcasm_model_name = "mrm8488/t5-base-finetuned-sarcasm-twitter" # Correct model name for sarcasm detection
# Create the sarcasm detection pipeline
sarcasm_pipeline = pipeline("text2text-generation", model=sarcasm_model_name)
def classify_sentence(sentence):
# Detect sarcasm
sarcasm_result = sarcasm_pipeline(sentence)[0]['generated_text']
is_sarcastic = sarcasm_result.strip().lower() == 'true'
# Detect sentiment
sentiment_result = sentiment_pipeline(sentence)[0]
sentiment_label = sentiment_result['label']
sentiment_score = sentiment_result['score']
# Determine sentiment
if sentiment_label == "NEGATIVE":
sentiment = "negative"
elif sentiment_label == "POSITIVE":
sentiment = "positive"
else:
sentiment = "neutral"
# Handle sarcasm
if is_sarcastic:
sentiment += " (sarcastic)"
return sentiment
# Streamlit app
st.title("Sentence Analyzer")
# User input
sentence = st.text_input("Enter a sentence:", "")
if st.button("Analyze"):
if sentence:
classification = classify_sentence(sentence)
st.write(f"Sentence: {sentence}")
st.write(f"Classification: {classification}")
else:
st.write("Please enter a sentence to analyze.")
# Example sentences
st.subheader("Example Sentences")
example_sentences = [
"they are so beautiful",
"This is the best day of my life.",
"I'm not happy with your work.",
"Yeah,you are not a good person!"
]
if st.button("Analyze Example Sentences"):
for sentence in example_sentences:
st.write(f"Sentence: {sentence}")
st.write(f"Classification: {classify_sentence(sentence)}")
st.write()
|