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

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ from langdetect import detect, DetectorFactory
3
+ 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)