Spaces:
Runtime error
Runtime error
Update main.py
Browse files
main.py
CHANGED
|
@@ -40,6 +40,7 @@ class InputData(BaseModel):
|
|
| 40 |
NumeroGenerazioni: int = 1
|
| 41 |
StringaSplit: str = '********'
|
| 42 |
NumeroCaratteriSplitInstruction: int = 30000
|
|
|
|
| 43 |
|
| 44 |
class InputDataAsync(InputData):
|
| 45 |
test: str = ''
|
|
@@ -75,6 +76,8 @@ def generate_text(request: Request, input_data: InputData):
|
|
| 75 |
input_data.asincrono = False
|
| 76 |
result_data = asyncio.run(GeneraTestoAsync("https://matteoscript-fastapi.hf.space/Genera", input_data))
|
| 77 |
LoggaTesto("RISPOSTA ASINCRONA FINALE", {"response": result_data})
|
|
|
|
|
|
|
| 78 |
return {"response": result_data}
|
| 79 |
|
| 80 |
def generate_input_text(input_data):
|
|
@@ -164,19 +167,6 @@ async def make_request(session, token, data, url, max_retries=3):
|
|
| 164 |
await asyncio.sleep(1)
|
| 165 |
raise Exception("Max retries reached or skipping retries. Unable to make the request.")
|
| 166 |
|
| 167 |
-
|
| 168 |
-
async def make_request_old(session, token, data, url):
|
| 169 |
-
headers = {
|
| 170 |
-
'Content-Type': 'application/json',
|
| 171 |
-
'Authorization': 'Bearer ' + token
|
| 172 |
-
}
|
| 173 |
-
async with session.post(url, headers=headers, json=data) as response:
|
| 174 |
-
try:
|
| 175 |
-
result_data = await response.json()
|
| 176 |
-
except aiohttp.ContentTypeError:
|
| 177 |
-
result_data = await response.text()
|
| 178 |
-
return result_data
|
| 179 |
-
|
| 180 |
async def CreaListaInput(input_data):
|
| 181 |
if input_data.instruction.startswith("http"):
|
| 182 |
try:
|
|
@@ -270,7 +260,6 @@ def DividiInstructionText(input_data):
|
|
| 270 |
ListaInput.append(data)
|
| 271 |
return ListaInput
|
| 272 |
|
| 273 |
-
|
| 274 |
async def GeneraTestoAsync(url, input_data):
|
| 275 |
token = os.getenv('TOKEN')
|
| 276 |
async with aiohttp.ClientSession() as session:
|
|
@@ -281,7 +270,6 @@ async def GeneraTestoAsync(url, input_data):
|
|
| 281 |
tasks.extend([make_request(session, token, data, url) for _ in range(input_data.NumeroGenerazioni)])
|
| 282 |
return await asyncio.gather(*tasks)
|
| 283 |
|
| 284 |
-
|
| 285 |
|
| 286 |
#--------------------------------------------------- Generazione IMMAGINE ------------------------------------------------------
|
| 287 |
style_image = {
|
|
|
|
| 40 |
NumeroGenerazioni: int = 1
|
| 41 |
StringaSplit: str = '********'
|
| 42 |
NumeroCaratteriSplitInstruction: int = 30000
|
| 43 |
+
EliminaRisposteNonPertinenti: bool = False
|
| 44 |
|
| 45 |
class InputDataAsync(InputData):
|
| 46 |
test: str = ''
|
|
|
|
| 76 |
input_data.asincrono = False
|
| 77 |
result_data = asyncio.run(GeneraTestoAsync("https://matteoscript-fastapi.hf.space/Genera", input_data))
|
| 78 |
LoggaTesto("RISPOSTA ASINCRONA FINALE", {"response": result_data})
|
| 79 |
+
if input_data.EliminaRisposteNonPertinenti and "response" in result_data and "NOTFOUND" in result_data["response"]:
|
| 80 |
+
del result_data["response"]
|
| 81 |
return {"response": result_data}
|
| 82 |
|
| 83 |
def generate_input_text(input_data):
|
|
|
|
| 167 |
await asyncio.sleep(1)
|
| 168 |
raise Exception("Max retries reached or skipping retries. Unable to make the request.")
|
| 169 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
async def CreaListaInput(input_data):
|
| 171 |
if input_data.instruction.startswith("http"):
|
| 172 |
try:
|
|
|
|
| 260 |
ListaInput.append(data)
|
| 261 |
return ListaInput
|
| 262 |
|
|
|
|
| 263 |
async def GeneraTestoAsync(url, input_data):
|
| 264 |
token = os.getenv('TOKEN')
|
| 265 |
async with aiohttp.ClientSession() as session:
|
|
|
|
| 270 |
tasks.extend([make_request(session, token, data, url) for _ in range(input_data.NumeroGenerazioni)])
|
| 271 |
return await asyncio.gather(*tasks)
|
| 272 |
|
|
|
|
| 273 |
|
| 274 |
#--------------------------------------------------- Generazione IMMAGINE ------------------------------------------------------
|
| 275 |
style_image = {
|