@@ -13,41 +13,41 @@ def minimax_generate_cover(your_file_path):
1313 Returns:
1414 str, local download path of the generated cover image file
1515 """
16- cover_name = time .strftime ("%Y%m%d%H%M%S" ) + ".png"
17- temp_cover_path = os .path .join (os .path .dirname (your_file_path ), cover_name )
1816
1917 with open (your_file_path , "rb" ) as image_file :
20- data = base64 .b64encode (image_file .read ()).decode (' utf-8' )
18+ data = base64 .b64encode (image_file .read ()).decode (" utf-8" )
2119
22- payload = json .dumps ({
23- "model" : "image-01" ,
24- "prompt" : "这是一个视频截图,请生成其对应的吉普力风格的图片" ,
25- "subject_reference" : [
26- {
27- "type" : "character" ,
28- "image_file" : f"data:image/jpeg;base64,{ data } "
29- }
30- ],
31- "n" : 2
32- })
20+ payload = json .dumps (
21+ {
22+ "model" : "image-01" ,
23+ "prompt" : "这是一个视频截图,请生成其对应的吉普力风格的图片" ,
24+ "subject_reference" : [
25+ {"type" : "character" , "image_file" : f"data:image/jpeg;base64,{ data } " }
26+ ],
27+ "n" : 2 ,
28+ }
29+ )
3330 headers = {
34- ' Authorization' : f' Bearer { MINIMAX_API_KEY } ' ,
35- ' Content-Type' : ' application/json'
31+ " Authorization" : f" Bearer { MINIMAX_API_KEY } " ,
32+ " Content-Type" : " application/json" ,
3633 }
3734
3835 url = "https://api.minimax.chat/v1/image_generation"
3936 response = requests .request ("POST" , url , headers = headers , data = payload ).json ()
40- if response [' base_resp' ][ ' status_code' ] == 0 :
41- image_url = response [' data' ][ ' image_urls' ][0 ]
37+ if response [" base_resp" ][ " status_code" ] == 0 :
38+ image_url = response [" data" ][ " image_urls" ][0 ]
4239 img_data = requests .get (image_url ).content
43- with open (temp_cover_path , 'wb' ) as handler :
40+ cover_name = time .strftime ("%Y%m%d%H%M%S" ) + ".png"
41+ temp_cover_path = os .path .join (os .path .dirname (your_file_path ), cover_name )
42+ with open (temp_cover_path , "wb" ) as handler :
4443 handler .write (img_data )
4544 os .remove (your_file_path )
4645 return temp_cover_path
4746 else :
48- print (response [' base_resp' ][ ' error_msg' ] )
47+ print (response [" base_resp" ][ " error_msg" ], flush = True )
4948 return None
5049
50+
5151if __name__ == "__main__" :
5252 your_file_path = ""
53- print (minimax_generate_cover (your_file_path ))
53+ print (minimax_generate_cover (your_file_path ))
0 commit comments