allow query to handle simple strings
Browse filesmoved logic for transforming string to an acceptable format inside the API function
- handler.py +7 -3
handler.py
CHANGED
@@ -42,8 +42,11 @@ class EndpointHandler():
|
|
42 |
# process input
|
43 |
print('data', data)
|
44 |
|
|
|
|
|
|
|
45 |
video_url = data.pop("video_url", None)
|
46 |
-
|
47 |
encoded_segments = {}
|
48 |
if video_url:
|
49 |
video_with_transcript = self.transcribe_video(video_url)
|
@@ -57,8 +60,9 @@ class EndpointHandler():
|
|
57 |
**video_with_transcript,
|
58 |
**encoded_segments
|
59 |
}
|
60 |
-
elif
|
61 |
-
|
|
|
62 |
|
63 |
return {
|
64 |
"encoded_segments": encoded_segments
|
|
|
42 |
# process input
|
43 |
print('data', data)
|
44 |
|
45 |
+
if "inputs" not in data:
|
46 |
+
raise Exception(f"data is missing 'inputs' key which EndpointHandler expects. Received: {data}"
|
47 |
+
f" See: https://huggingface.co/docs/inference-endpoints/guides/custom_handler#2-create-endpointhandler-cp")
|
48 |
video_url = data.pop("video_url", None)
|
49 |
+
query = data.pop("query", None)
|
50 |
encoded_segments = {}
|
51 |
if video_url:
|
52 |
video_with_transcript = self.transcribe_video(video_url)
|
|
|
60 |
**video_with_transcript,
|
61 |
**encoded_segments
|
62 |
}
|
63 |
+
elif query:
|
64 |
+
query = [{"text": query, "id": ""}]
|
65 |
+
encoded_segments = self.encode_sentences(query)
|
66 |
|
67 |
return {
|
68 |
"encoded_segments": encoded_segments
|