Spaces:
Sleeping
Sleeping
j
commited on
Commit
·
641a02b
1
Parent(s):
fef2baf
add regex for http/2 status
Browse files- reascripts/ReaSpeech/source/ReaSpeechAPI.lua +9 -4
- test +13 -0
reascripts/ReaSpeech/source/ReaSpeechAPI.lua
CHANGED
@@ -193,20 +193,25 @@ end
|
|
193 |
function ReaSpeechAPI.http_status_and_body(response)
|
194 |
local headers, content = ReaSpeechAPI._split_curl_response(response)
|
195 |
local last_status_line = headers[#headers] and headers[#headers][1] or ''
|
196 |
-
|
197 |
-
local status = last_status_line:match("^HTTP
|
|
|
|
|
|
|
|
|
198 |
if not status then
|
199 |
return -1, 'Status not found in headers'
|
200 |
end
|
201 |
-
|
202 |
local body = {}
|
203 |
for _, chunk in pairs(content) do
|
204 |
table.insert(body, table.concat(chunk, "\n"))
|
205 |
end
|
206 |
-
|
207 |
return tonumber(status), table.concat(body, "\n")
|
208 |
end
|
209 |
|
|
|
210 |
function ReaSpeechAPI._split_curl_response(input)
|
211 |
local line_iterator = ReaSpeechAPI._line_iterator(input)
|
212 |
local chunk_iterator = ReaSpeechAPI._chunk_iterator(line_iterator)
|
|
|
193 |
function ReaSpeechAPI.http_status_and_body(response)
|
194 |
local headers, content = ReaSpeechAPI._split_curl_response(response)
|
195 |
local last_status_line = headers[#headers] and headers[#headers][1] or ''
|
196 |
+
|
197 |
+
local status = last_status_line:match("^HTTP/(%d+%.?%d*)%s+(%d+)")
|
198 |
+
if not status then
|
199 |
+
status = last_status_line:match(":status:%s*(%d+)")
|
200 |
+
end
|
201 |
+
|
202 |
if not status then
|
203 |
return -1, 'Status not found in headers'
|
204 |
end
|
205 |
+
|
206 |
local body = {}
|
207 |
for _, chunk in pairs(content) do
|
208 |
table.insert(body, table.concat(chunk, "\n"))
|
209 |
end
|
210 |
+
|
211 |
return tonumber(status), table.concat(body, "\n")
|
212 |
end
|
213 |
|
214 |
+
|
215 |
function ReaSpeechAPI._split_curl_response(input)
|
216 |
local line_iterator = ReaSpeechAPI._line_iterator(input)
|
217 |
local chunk_iterator = ReaSpeechAPI._chunk_iterator(line_iterator)
|
test
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
HTTP/2 200
|
2 |
+
date: Mon, 22 Jul 2024 20:41:31 GMT
|
3 |
+
content-type: application/json
|
4 |
+
content-length: 49
|
5 |
+
server: uvicorn
|
6 |
+
x-proxied-host: http://10.29.14.56
|
7 |
+
x-proxied-path: /asr?output=json&vad_filter=true&task=transcribe&use_async=true&model_name=small&word_timestamps=true
|
8 |
+
link: <https://huggingface.co/spaces/TechAudio/ReaSpeech-Cloud>;rel="canonical"
|
9 |
+
x-request-id: zwtuoe
|
10 |
+
vary: origin, access-control-request-method, access-control-request-headers
|
11 |
+
access-control-allow-credentials: true
|
12 |
+
|
13 |
+
{"job_id":"4bc43230-eb80-4169-b158-aaf7e60fc8df"}
|