Spaces:
Runtime error
Runtime error
What is the correct way to connect to your API?
#11
by
Superchik
- opened
import json
import aiohttp
import asyncio
from aiohttp import FormData
print(aiohttp.__version__)
API_URL = "https://huggingface.co/spaces/sanchit-gandhi/whisper-jax"
async def query(filename):
async with aiohttp.ClientSession() as session:
with open(filename, "rb") as f:
data = f.read()
payload = {"task": "transcribe", "options": {"wait_for_model": True}}
form_data = FormData()
form_data.add_field('json', json.dumps(payload), content_type='application/json')
form_data.add_field('data', data, content_type='application/octet-stream')
async with session.post(API_URL, data=form_data) as response:
print(response.status)
return await response.json()
async def main():
data = await query("audio.mp3")
print(data)
asyncio.run(main())
3.8.4
404
---------------------------------------------------------------------------
ContentTypeError Traceback (most recent call last)
<ipython-input-10-6eff912379fe> in <cell line: 32>()
30 print(data)
31
---> 32 asyncio.run(main())
6 frames
/usr/local/lib/python3.10/dist-packages/aiohttp/client_reqrep.py in json(self, encoding, loads, content_type)
1102 ctype = self.headers.get(hdrs.CONTENT_TYPE, "").lower()
1103 if not _is_expected_content_type(ctype, content_type):
-> 1104 raise ContentTypeError(
1105 self.request_info,
1106 self.history,
ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: text/html; charset=utf-8', url=URL('https://huggingface.co/spaces/sanchit-gandhi/whisper-jax')