rogerxavier commited on
Commit
5cfa481
1 Parent(s): 8bdb89d

Update api.py

Browse files
Files changed (1) hide show
  1. api.py +9 -32
api.py CHANGED
@@ -6,7 +6,6 @@ import numpy as np
6
  import urllib.request
7
  import io
8
  import os
9
- from moviepyTest import test
10
  from typing import *
11
  from fastapi.responses import PlainTextResponse #执行其他py的plaintext返回
12
  import subprocess
@@ -33,11 +32,7 @@ def t5(input):
33
 
34
  return {"output": input}
35
 
36
- @app.get("/moviepyTest")
37
- def t5():
38
- result = test()
39
-
40
- return {"output": result}
41
 
42
 
43
 
@@ -165,9 +160,10 @@ async def upload_video(meta:dict,cover_url:str):
165
  bili_jct=bili_jct,
166
  buvid3=buvid3)
167
 
168
- #cover = bilibili_api.utils.picture.Picture.from_url(cover_url)
169
- cover_url = "https://rogerxavier-moviepy-with-manga-cover.hf.space/cover.jpg"#这里使用另一个space暂存从本地请求得到的cover,从而摆脱异步问题
170
- cover = bilibili_api.utils.picture.Picture.from_url(cover_url)#准备用space暂存的图片作为cover
 
171
 
172
 
173
 
@@ -196,27 +192,8 @@ async def get_video(dir:str = "/mp4_out/output.mp4")->"video file in header":
196
  return response
197
 
198
 
199
- #将cover目录下面的0.jpg返回图片作为cover地址
200
- @app.get("/cover.jpg")
201
- async def get_cover_image():
202
- cover_dir = "cover"
203
- file_path = os.path.join(cover_dir, "0.jpg")
204
- return FileResponse(file_path)
205
-
206
-
207
-
208
- #测试能否在处理请求的时候请求另一个接口获取图片
209
- @app.get("/coverTest.jpg")
210
- def get_cover_image():
211
- url = "https://rogerxavier-moviepy-with-manga-cover.hf.space/cover.jpg"
212
- response = requests.get(url)
213
- if response.status_code == 200:
214
- with open("cover/0.jpg", "wb") as f:
215
- f.write(response.content)
216
- print("Cover image downloaded successfully.")
217
- else:
218
- print("Failed to download cover image. Status code:", response.status_code)
219
- cover_dir = "cover"
220
- file_path = os.path.join(cover_dir, "0.jpg")
221
- return FileResponse(file_path)
222
 
 
6
  import urllib.request
7
  import io
8
  import os
 
9
  from typing import *
10
  from fastapi.responses import PlainTextResponse #执行其他py的plaintext返回
11
  import subprocess
 
32
 
33
  return {"output": input}
34
 
35
+
 
 
 
 
36
 
37
 
38
 
 
160
  bili_jct=bili_jct,
161
  buvid3=buvid3)
162
 
163
+ # 读取本地cover/0.jpg文件为字节数据作为cover
164
+ with open("/cover/0.jpg", "rb") as f:
165
+ cover_data = f.read()
166
+ cover = bilibili_api.utils.picture.Picture.from_content(cover_data,"jpg")#直接读取本地图片content
167
 
168
 
169
 
 
192
  return response
193
 
194
 
195
+
196
+
197
+
198
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
199