Mbonea commited on
Commit
2bec257
1 Parent(s): 275b80a

retries if it fails

Browse files
App/Generate/database/DescriptAPI.py CHANGED
@@ -107,10 +107,22 @@ class Speak:
107
 
108
  async def _make_transcript(self, links, text):
109
  data = {"audio_url": links, "text": text}
110
- response_data = await self._make_request(
111
- "post", "descript_transcript", json=data
112
- )
113
- return response_data
 
 
 
 
 
 
 
 
 
 
 
 
114
 
115
  async def _make_request(self, method, endpoint, json=None):
116
  async with aiohttp.ClientSession() as session:
 
107
 
108
  async def _make_transcript(self, links, text):
109
  data = {"audio_url": links, "text": text}
110
+ tries = 0
111
+ max_retries = 10
112
+ while tries < max_retries:
113
+ try:
114
+ response_data = await self._make_request(
115
+ "post", "descript_transcript", json=data
116
+ )
117
+ if isinstance(response_data, dict):
118
+ return response_data
119
+ except Exception as e:
120
+ print(f"Attempt {tries + 1} failed: {e}")
121
+
122
+ tries += 1
123
+ await asyncio.sleep(1) # Adding a delay between retries
124
+
125
+ raise Exception("Max retries reached. Unable to get a valid response.")
126
 
127
  async def _make_request(self, method, endpoint, json=None):
128
  async with aiohttp.ClientSession() as session: