Spaces:
Sleeping
Sleeping
Update main.py
Browse files127 unmodified lines128129130131132133134127 unmodified linesresult_data = asyncio.run(GeneraTestoAsync("https://matteoscript-fastapi.hf.space/Genera", input_data))return {"response": result_data}async def make_request(session, token, data, url):headers = {'Content-Type': 'application/json','Authorization': 'Bearer ' + token127 unmodified lines128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161127 unmodified linesresult_data = asyncio.run(GeneraTestoAsync("https://matteoscript-fastapi.hf.space/Genera", input_data))return {"response": result_data}async def make_request(session, token, data, url, max_retries=3):headers = {'Content-Type': 'application/json','Authorization': 'Bearer ' + token}for _ in range(max_retries):try:async with session.post(url, headers=headers, json=data) as response:response.raise_for_status()try:result_data = await response.json()except aiohttp.ContentTypeError:result_data = await response.text()print(result_data)return result_dataexcept (asyncio.TimeoutError, aiohttp.ClientError, requests.exceptions.HTTPError) as e:print(f"Error: {e}.")if isinstance(e, (asyncio.TimeoutError, requests.exceptions.HTTPError)) and e.response.status in [502, 504]:print("Skipping retries for this error.")breakprint("Retrying...")await asyncio.sleep(1)raise Exception("Max retries reached or skipping retries. Unable to make the request.")async def make_request_old(session, token, data, url):headers = {'Content-Type': 'application/json','Authorization': 'Bearer ' + token
main.py+28-1