Commit
·
b80570e
1
Parent(s):
142339c
support path input from HF UI
Browse files- .idea/.name +1 -0
- handler.py +13 -7
.idea/.name
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
handler.py
|
handler.py
CHANGED
@@ -46,11 +46,17 @@ class EndpointHandler:
|
|
46 |
|
47 |
prompt = data.get("prompt", "Describe the content.")
|
48 |
|
49 |
-
#
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
try:
|
56 |
# 处理输入,调用模型推理
|
@@ -64,8 +70,8 @@ class EndpointHandler:
|
|
64 |
modal=modal
|
65 |
)
|
66 |
finally:
|
67 |
-
|
68 |
-
|
69 |
|
70 |
# 返回结构统一,方便调用方解析
|
71 |
return {
|
|
|
46 |
|
47 |
prompt = data.get("prompt", "Describe the content.")
|
48 |
|
49 |
+
# 判断是 base64 字符串(API调用)还是文件路径(网页上传)
|
50 |
+
if os.path.exists(file_b64): # 是路径,直接用
|
51 |
+
tmp_path = file_b64
|
52 |
+
cleanup = False
|
53 |
+
else:
|
54 |
+
# 是base64字符串,写入临时文件
|
55 |
+
suffix = ".mp4" if modal == "video" else ".png"
|
56 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=suffix) as tmp_file:
|
57 |
+
tmp_file.write(base64.b64decode(file_b64))
|
58 |
+
tmp_path = tmp_file.name
|
59 |
+
cleanup = True
|
60 |
|
61 |
try:
|
62 |
# 处理输入,调用模型推理
|
|
|
70 |
modal=modal
|
71 |
)
|
72 |
finally:
|
73 |
+
if cleanup:
|
74 |
+
os.remove(tmp_path)
|
75 |
|
76 |
# 返回结构统一,方便调用方解析
|
77 |
return {
|