Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -157,14 +157,14 @@ def generate_textAsync(request: Request, input_data: InputDataAsync):
|
|
| 157 |
result_data = asyncio.run(GeneraTestoAsync("https://matteoscript-fastapi.hf.space/Genera", input_data))
|
| 158 |
return {"response": result_data}
|
| 159 |
|
| 160 |
-
async def make_request(session, token, data, url,
|
| 161 |
headers = {
|
| 162 |
'Content-Type': 'application/json',
|
| 163 |
'Authorization': 'Bearer ' + token
|
| 164 |
}
|
| 165 |
-
if
|
| 166 |
data.max_new_tokens = data.max_new_tokens
|
| 167 |
-
elif
|
| 168 |
data.max_new_tokens = max(200, data.max_new_tokens - 200)
|
| 169 |
else:
|
| 170 |
data.max_new_tokens = data.max_new_tokens + 200
|
|
@@ -286,7 +286,7 @@ async def GeneraTestoAsync(url, input_data):
|
|
| 286 |
for data in ListaInput:
|
| 287 |
LoggaTesto("RICHIESTA ASINCRONA", data)
|
| 288 |
index = 0
|
| 289 |
-
tasks.extend([make_request(session, token, data, index
|
| 290 |
return await asyncio.gather(*tasks)
|
| 291 |
|
| 292 |
|
|
|
|
| 157 |
result_data = asyncio.run(GeneraTestoAsync("https://matteoscript-fastapi.hf.space/Genera", input_data))
|
| 158 |
return {"response": result_data}
|
| 159 |
|
| 160 |
+
async def make_request(session, token, data, url, i, max_retries=3):
|
| 161 |
headers = {
|
| 162 |
'Content-Type': 'application/json',
|
| 163 |
'Authorization': 'Bearer ' + token
|
| 164 |
}
|
| 165 |
+
if (i+1) % 3 == 1:
|
| 166 |
data.max_new_tokens = data.max_new_tokens
|
| 167 |
+
elif (i+1) % 3 == 2:
|
| 168 |
data.max_new_tokens = max(200, data.max_new_tokens - 200)
|
| 169 |
else:
|
| 170 |
data.max_new_tokens = data.max_new_tokens + 200
|
|
|
|
| 286 |
for data in ListaInput:
|
| 287 |
LoggaTesto("RICHIESTA ASINCRONA", data)
|
| 288 |
index = 0
|
| 289 |
+
tasks.extend([make_request(session, token, data, index, url) for index in range(input_data.NumeroGenerazioni)])
|
| 290 |
return await asyncio.gather(*tasks)
|
| 291 |
|
| 292 |
|