File size: 2,273 Bytes
8fce48f
 
 
 
 
 
4563dd7
 
8fce48f
4563dd7
1719ac4
8fce48f
4563dd7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
557b340
 
 
 
 
 
 
 
 
6096be1
557b340
 
 
183d6b1
557b340
 
 
 
 
 
 
 
4563dd7
 
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
import pandas as pd
from langdetect import detect, DetectorFactory
from langdetect.lang_detect_exception import LangDetectException
import streamlit as st
from transformers import pipeline

# Load the text summarization model pipeline
summarizer = pipeline("summarization", model="Falconsai/text_summarization")

# Load the text classification model pipeline
classifier = pipeline("text-classification", model='Rainess/Finturned-Music-Sentiment')

def summary_song(text):
    input_length = len(text)
    if input_length < 200:
        return text  # Return original text if length is less than 200
    else:
        max_length = 200
        min_length = 50
        summary = summarizer(text, max_length=max_length, min_length=min_length, truncation=True)
        summarized_text = summary[0]['summary_text']
        return summarized_text

# Streamlit application title
st.title("Text Summarization and Sentiment Classification for Music Lyrics")
st.write("Classify the sentiment of summarized lyrics as Positive or Negative")

# Text input for user to enter the lyrics
text = st.text_area("Enter the lyrics to summarize and classify", "")

# Perform text summarization and classification when the user clicks the "Summarize and Classify" button
if st.button("Summarize and Classify"):
    if text.strip():
        try:
            # Perform text summarization on the input lyrics
            summarized_text = summary_song(text)
            
            # Perform text classification on the summarized text
            result = classifier(summarized_text)[0]

            # Extract the classification label and score
            max_label = result['label']
            max_score = result['score']
            
            # Map label to sentiment
            sentiment = "Positive" if max_label == "POSITIVE" else "Negative"
            
            # Display the summarized text and classification result
            st.write("Original Lyrics:", text)
            st.write("Summarized Text:", summarized_text)
            st.write("Sentiment:", sentiment)
            st.write("Score:", max_score)
        except Exception as e:
            st.write("Error processing the text:", str(e))
    else:
        st.write("Please enter some lyrics to summarize and classify.")