Rainess commited on
Commit
4563dd7
1 Parent(s): 8fce48f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -24
app.py CHANGED
@@ -4,31 +4,53 @@ from langdetect.lang_detect_exception import LangDetectException
4
  import streamlit as st
5
  from transformers import pipeline
6
 
7
- # Initialize the pipelines
8
- summarizer = pipeline("summarization", model="Falconsai/text_summarization")
9
- classifier = pipeline("text-classification", model='Rainess/Finturned-Music-Sentiment', return_all_scores=True)
10
-
11
- @app.route('/process_lyrics', methods=['POST'])
12
- def process_lyrics():
13
- data = request.json
14
- lyrics = data.get('lyrics')
15
-
16
- if not lyrics:
17
- return jsonify({'error': 'No lyrics provided'}), 400
18
 
19
- # Summarize the lyrics
20
- summary = summarizer(lyrics, max_length=50, min_length=25, do_sample=False)[0]['summary_text']
21
-
22
- # Classify the summarized text
23
- classification_result = classifier(summary)[0]
24
 
25
- # Determine the sentiment
26
- sentiment = "Negative" if classification_result['label'] == 'LABEL_0' else "Positive"
27
 
28
- return jsonify({
29
- 'summary': summary,
30
- 'sentiment': sentiment
31
- })
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
- if __name__ == '__main__':
34
- app.run(host='0.0.0.0', port=5000)
 
4
  import streamlit as st
5
  from transformers import pipeline
6
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
+ # Load the text summarization model pipeline
9
+ summarizer = pipeline("summarization", model="Falconsai/text_summarization")
 
 
 
10
 
11
+ # Load the text classification model pipeline
12
+ classifier = pipeline("text-classification", model='Rainess/Finturned-Music-Sentiment', return_all_scores=True)
13
 
14
+ def summary_song(text):
15
+ input_length = len(text)
16
+ if input_length < 200:
17
+ return text # Return original text if length is less than 200
18
+ else:
19
+ max_length = 200
20
+ min_length = 50
21
+ summary = summarizer(text, max_length=max_length, min_length=min_length, truncation=True)
22
+ summarized_text = summary[0]['summary_text']
23
+ return summarized_text
24
+
25
+ # Streamlit application title
26
+ st.title("Text Summarization and Sentiment Classification for Music Lyrics")
27
+ st.write("Classify the sentiment of summarized lyrics as Positive or Negative")
28
+
29
+ # Text input for user to enter the lyrics
30
+ text = st.text_area("Enter the lyrics to summarize and classify", "")
31
+
32
+ # Perform text summarization and classification when the user clicks the "Summarize and Classify" button
33
+ if st.button("Summarize and Classify"):
34
+ if text.strip():
35
+ # Perform text summarization on the input lyrics
36
+ summarized_text = summary_song(text)
37
+
38
+ # Perform text classification on the summarized text
39
+ classification_results = classifier(summarized_text)
40
+
41
+ # Get the highest scoring sentiment
42
+ max_score = float('-inf')
43
+ max_label = ''
44
+
45
+
46
+ # Map label to sentiment
47
+ sentiment = "Positive" if max_label == "1" else "Negative"
48
+
49
+ # Display the summarized text and classification result
50
+ st.write("Original Lyrics:", text)
51
+ st.write("Summarized Text:", summarized_text)
52
+ st.write("Sentiment:", sentiment)
53
+ st.write("Score:", max_score)
54
+ else:
55
+ st.write("Please enter some lyrics to summarize and classify.")
56