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