Spaces:
Runtime error
Runtime error
Update main.py
Browse files
main.py
CHANGED
|
@@ -157,11 +157,17 @@ 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, max_retries=3):
|
| 161 |
headers = {
|
| 162 |
'Content-Type': 'application/json',
|
| 163 |
'Authorization': 'Bearer ' + token
|
| 164 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
for _ in range(max_retries):
|
| 166 |
try:
|
| 167 |
async with session.post(url, headers=headers, json=data) as response:
|
|
@@ -279,7 +285,7 @@ async def GeneraTestoAsync(url, input_data):
|
|
| 279 |
ListaInput = await CreaListaInput(input_data)
|
| 280 |
for data in ListaInput:
|
| 281 |
LoggaTesto("RICHIESTA ASINCRONA", data)
|
| 282 |
-
tasks.extend([make_request(session, token, data, url) for _ in range(input_data.NumeroGenerazioni)])
|
| 283 |
return await asyncio.gather(*tasks)
|
| 284 |
|
| 285 |
|
|
|
|
| 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, max_retries=3, index):
|
| 161 |
headers = {
|
| 162 |
'Content-Type': 'application/json',
|
| 163 |
'Authorization': 'Bearer ' + token
|
| 164 |
}
|
| 165 |
+
if index % 3 == 1:
|
| 166 |
+
data.max_new_tokens = data.max_new_tokens
|
| 167 |
+
elif index % 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
|
| 171 |
for _ in range(max_retries):
|
| 172 |
try:
|
| 173 |
async with session.post(url, headers=headers, json=data) as response:
|
|
|
|
| 285 |
ListaInput = await CreaListaInput(input_data)
|
| 286 |
for data in ListaInput:
|
| 287 |
LoggaTesto("RICHIESTA ASINCRONA", data)
|
| 288 |
+
tasks.extend([make_request(session, token, data, url, index+1) for _ in range(input_data.NumeroGenerazioni)])
|
| 289 |
return await asyncio.gather(*tasks)
|
| 290 |
|
| 291 |
|