ning8429 commited on
Commit
4886d7a
·
verified ·
1 Parent(s): 86bee9d

Update api_server.py

Browse files
Files changed (1) hide show
  1. 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
- clip_result = client.predict(
85
- choice = choice,
86
- image= handle_file(image),
87
- word = word,
88
- top_k = 3,
89
- api_name = "/run_function"
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