wudysoft commited on
Commit
1b7cd1c
·
verified ·
1 Parent(s): 501edc6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify
2
+ import requests
3
+
4
+ app = Flask(__name__)
5
+
6
+ def AimusicLyrics(prompt):
7
+ url = "https://aimusic.one/api/v3/lyrics/generator"
8
+ headers = {
9
+ "Content-Type": "application/json",
10
+ "User-Agent": "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Mobile Safari/537.36",
11
+ "Referer": "https://aimusic.one/ai-lyrics-generator"
12
+ }
13
+ data = {
14
+ "description": prompt,
15
+ "style": "Auto",
16
+ "topic": "Auto",
17
+ "mood": "Auto",
18
+ "lan": "auto",
19
+ "isPublic": True
20
+ }
21
+ try:
22
+ response = requests.post(url, json=data, headers=headers)
23
+ response.raise_for_status()
24
+ result = response.json()
25
+ return result.get("lyrics")
26
+ except requests.exceptions.RequestException as e:
27
+ print(f"Error: {e}")
28
+ return None
29
+
30
+ @app.route("/lirik", methods=["GET"])
31
+ def get_lyrics():
32
+ prompt = request.args.get("q")
33
+ if not prompt:
34
+ return jsonify({"error": "Query parameter 'q' is required"}), 400
35
+
36
+ lyrics = AimusicLyrics(prompt)
37
+ if lyrics:
38
+ return jsonify({"lyrics": lyrics}), 200
39
+ else:
40
+ return jsonify({"error": "Failed to generate lyrics"}), 500
41
+
42
+ if __name__ == "__main__":
43
+ app.run(debug=True, host="0.0.0.0", port=8080)