Spaces:
Sleeping
Sleeping
Update api_server.py
Browse files- api_server.py +17 -7
api_server.py
CHANGED
@@ -81,13 +81,23 @@ def get_jpg_files(path):
|
|
81 |
|
82 |
def clip_model (choice="find_similar_words",image=None,word=None):
|
83 |
client = Client(GRADIO_URL)
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
return clip_result
|
92 |
|
93 |
|
|
|
81 |
|
82 |
def clip_model (choice="find_similar_words",image=None,word=None):
|
83 |
client = Client(GRADIO_URL)
|
84 |
+
# 當 image 存在時才處理
|
85 |
+
if image is not None:
|
86 |
+
image_input = handle_file(image)
|
87 |
+
else:
|
88 |
+
image_input = None
|
89 |
+
|
90 |
+
try:
|
91 |
+
clip_result = client.predict(
|
92 |
+
choice=choice,
|
93 |
+
image=image_input,
|
94 |
+
word=word,
|
95 |
+
top_k=3,
|
96 |
+
api_name="/run_function"
|
97 |
+
)
|
98 |
+
except Exception as e:
|
99 |
+
return f"Error occurred while processing the request: {e}"
|
100 |
+
|
101 |
return clip_result
|
102 |
|
103 |
|