next-playground commited on
Commit
1f919a0
1 Parent(s): f53517e

Update flask_api_full_song.py

Browse files
Files changed (1) hide show
  1. flask_api_full_song.py +9 -1
flask_api_full_song.py CHANGED
@@ -17,6 +17,8 @@ secret_key = os.getenv('SECRET_KEY')
17
  region = 'na-siliconvalley'
18
  bucket_name = 'xiaohei-cat-ai-1304646510'
19
 
 
 
20
  config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key)
21
  client = CosS3Client(config)
22
 
@@ -32,6 +34,9 @@ response2 = client.get_object(
32
  )
33
  response2['Body'].get_stream_to_file('/tmp/config.json')
34
 
 
 
 
35
 
36
  model_name = "/tmp/G_full.pth" # 模型地址
37
  config_name = "/tmp/config.json" # config地址
@@ -128,7 +133,10 @@ def get_task_status(task_id):
128
 
129
  @app.route('/download/<filename>', methods=['GET'])
130
  def download(filename):
131
- return send_file("/tmp/" + filename, as_attachment=True)
 
 
 
132
 
133
 
134
  if __name__ == '__main__':
 
17
  region = 'na-siliconvalley'
18
  bucket_name = 'xiaohei-cat-ai-1304646510'
19
 
20
+ print("Starting download the model and config...")
21
+
22
  config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key)
23
  client = CosS3Client(config)
24
 
 
34
  )
35
  response2['Body'].get_stream_to_file('/tmp/config.json')
36
 
37
+ print("Download complete!")
38
+
39
+ print("Starting service...")
40
 
41
  model_name = "/tmp/G_full.pth" # 模型地址
42
  config_name = "/tmp/config.json" # config地址
 
133
 
134
  @app.route('/download/<filename>', methods=['GET'])
135
  def download(filename):
136
+ if filename == 'G_full.pth' or filename == 'config.json':
137
+ return jsonify({"error": "File not found"}), 404
138
+ else:
139
+ return send_file("/tmp/" + filename, as_attachment=True)
140
 
141
 
142
  if __name__ == '__main__':