Spaces:
Runtime error
Runtime error
Update main.py
Browse files
main.py
CHANGED
|
@@ -140,7 +140,6 @@ async def make_request(session, token, data, url):
|
|
| 140 |
return result_data
|
| 141 |
|
| 142 |
async def CreaListaInput(input_data):
|
| 143 |
-
ListaInput = []
|
| 144 |
input_strings = input_data.input.split(input_data.StringaSplit)
|
| 145 |
numerocaratteriSPLIT = 2000
|
| 146 |
if input_data.instruction.startswith("http"):
|
|
@@ -154,12 +153,13 @@ async def CreaListaInput(input_data):
|
|
| 154 |
lista_dizionari = json.loads(input_data.instruction)
|
| 155 |
nuova_lista_dizionari = []
|
| 156 |
if lista_dizionari and "Titolo" in lista_dizionari[0]:
|
| 157 |
-
DividiInstructionJSON()
|
| 158 |
else:
|
| 159 |
-
DividiInstructionText()
|
| 160 |
except json.JSONDecodeError:
|
| 161 |
-
DividiInstructionText()
|
| 162 |
-
|
|
|
|
| 163 |
|
| 164 |
async def split_at_space_or_dot(input_string, length):
|
| 165 |
delimiters = ['\n\n', '.\n', ';\n', '.', ' ']
|
|
@@ -168,7 +168,9 @@ async def split_at_space_or_dot(input_string, length):
|
|
| 168 |
return indice_divisione + 1
|
| 169 |
|
| 170 |
|
| 171 |
-
async def DividiInstructionJSON():
|
|
|
|
|
|
|
| 172 |
for dizionario in lista_dizionari:
|
| 173 |
titolo = dizionario["Titolo"]
|
| 174 |
testo_completo = dizionario["Testo"]
|
|
@@ -186,19 +188,13 @@ async def DividiInstructionJSON():
|
|
| 186 |
if len(testo_completo) > 0:
|
| 187 |
nuovo_dizionario = {"Titolo": titolo, "Testo": testo_completo}
|
| 188 |
nuova_lista_dizionari.append(nuovo_dizionario)
|
|
|
|
| 189 |
|
| 190 |
-
for input_string in input_strings:
|
| 191 |
-
for dizionario in nuova_lista_dizionari:
|
| 192 |
-
data = {
|
| 193 |
-
'input': input_string,
|
| 194 |
-
'instruction': [dizionario]
|
| 195 |
-
}
|
| 196 |
-
ListaInput.append(data)
|
| 197 |
|
| 198 |
-
|
| 199 |
-
async def DividiInstructionText():
|
| 200 |
input_str = instruction
|
| 201 |
sottostringhe = []
|
|
|
|
| 202 |
indice_inizio = 0
|
| 203 |
if len(input_str) > numerocaratteriSPLIT:
|
| 204 |
while indice_inizio < len(input_str):
|
|
@@ -211,23 +207,13 @@ async def DividiInstructionText():
|
|
| 211 |
sottostringhe.append(input_str)
|
| 212 |
testoSeparato = StringaSplit.join(sottostringhe)
|
| 213 |
instruction_strings = testoSeparato.split(StringaSplit)
|
| 214 |
-
|
| 215 |
-
for instruction_string in instruction_strings:
|
| 216 |
-
data = {
|
| 217 |
-
'input': input_string.strip(),
|
| 218 |
-
'instruction': [{instruction_string.strip()}]
|
| 219 |
-
}
|
| 220 |
-
ListaInput.append(data)
|
| 221 |
|
| 222 |
|
| 223 |
async def GeneraTestoAsync(url, input_data):
|
| 224 |
token = os.getenv('TOKEN')
|
| 225 |
async with aiohttp.ClientSession() as session:
|
| 226 |
ListaInput = CreaListaInput(input_data)
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
tasks = []
|
| 232 |
for input_string in input_strings:
|
| 233 |
data = {
|
|
|
|
| 140 |
return result_data
|
| 141 |
|
| 142 |
async def CreaListaInput(input_data):
|
|
|
|
| 143 |
input_strings = input_data.input.split(input_data.StringaSplit)
|
| 144 |
numerocaratteriSPLIT = 2000
|
| 145 |
if input_data.instruction.startswith("http"):
|
|
|
|
| 153 |
lista_dizionari = json.loads(input_data.instruction)
|
| 154 |
nuova_lista_dizionari = []
|
| 155 |
if lista_dizionari and "Titolo" in lista_dizionari[0]:
|
| 156 |
+
nuova_lista_dizionari = DividiInstructionJSON(lista_dizionari)
|
| 157 |
else:
|
| 158 |
+
nuova_lista_dizionari = DividiInstructionText(input_data.instruction, input_data.StringaSplit)
|
| 159 |
except json.JSONDecodeError:
|
| 160 |
+
nuova_lista_dizionari = DividiInstructionText(input_data.instruction, input_data.StringaSplit)
|
| 161 |
+
|
| 162 |
+
return nuova_lista_dizionari
|
| 163 |
|
| 164 |
async def split_at_space_or_dot(input_string, length):
|
| 165 |
delimiters = ['\n\n', '.\n', ';\n', '.', ' ']
|
|
|
|
| 168 |
return indice_divisione + 1
|
| 169 |
|
| 170 |
|
| 171 |
+
async def DividiInstructionJSON(lista_dizionari):
|
| 172 |
+
nuova_lista_dizionari = []
|
| 173 |
+
numerocaratteriSPLIT = 2000
|
| 174 |
for dizionario in lista_dizionari:
|
| 175 |
titolo = dizionario["Titolo"]
|
| 176 |
testo_completo = dizionario["Testo"]
|
|
|
|
| 188 |
if len(testo_completo) > 0:
|
| 189 |
nuovo_dizionario = {"Titolo": titolo, "Testo": testo_completo}
|
| 190 |
nuova_lista_dizionari.append(nuovo_dizionario)
|
| 191 |
+
return nuova_lista_dizionari
|
| 192 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
|
| 194 |
+
async def DividiInstructionText(instruction, StringaSplit):
|
|
|
|
| 195 |
input_str = instruction
|
| 196 |
sottostringhe = []
|
| 197 |
+
numerocaratteriSPLIT = 2000
|
| 198 |
indice_inizio = 0
|
| 199 |
if len(input_str) > numerocaratteriSPLIT:
|
| 200 |
while indice_inizio < len(input_str):
|
|
|
|
| 207 |
sottostringhe.append(input_str)
|
| 208 |
testoSeparato = StringaSplit.join(sottostringhe)
|
| 209 |
instruction_strings = testoSeparato.split(StringaSplit)
|
| 210 |
+
return instruction_strings
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
|
| 212 |
|
| 213 |
async def GeneraTestoAsync(url, input_data):
|
| 214 |
token = os.getenv('TOKEN')
|
| 215 |
async with aiohttp.ClientSession() as session:
|
| 216 |
ListaInput = CreaListaInput(input_data)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
tasks = []
|
| 218 |
for input_string in input_strings:
|
| 219 |
data = {
|