Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -274,7 +274,7 @@ def simple_chat(message, temperature: float = 0.8, max_length: int = 4096, top_p
|
|
| 274 |
thread.join()
|
| 275 |
|
| 276 |
try:
|
| 277 |
-
|
| 278 |
buffer = buffer.strip('`')
|
| 279 |
buffer = buffer.strip('json')
|
| 280 |
json_content = json.loads(buffer)
|
|
@@ -293,9 +293,6 @@ def simple_chat(message, temperature: float = 0.8, max_length: int = 4096, top_p
|
|
| 293 |
return PlainTextResponse(formatted_text)
|
| 294 |
|
| 295 |
def format_json_to_string(json_content):
|
| 296 |
-
"""
|
| 297 |
-
Convierte un diccionario JSON a una cadena JSON sin comillas invertidas.
|
| 298 |
-
"""
|
| 299 |
return json.dumps(json_content, ensure_ascii=False)
|
| 300 |
|
| 301 |
|
|
@@ -304,27 +301,22 @@ async def test_endpoint(
|
|
| 304 |
text: str = Form(...),
|
| 305 |
file: UploadFile = File(None)
|
| 306 |
):
|
| 307 |
-
# Verificar si se ha subido un archivo
|
| 308 |
if file:
|
| 309 |
-
# Leer el archivo en memoria
|
| 310 |
file_content = BytesIO(await file.read())
|
| 311 |
file_name = file.filename
|
| 312 |
|
| 313 |
-
# Construir el mensaje con el archivo y el texto
|
| 314 |
message = {
|
| 315 |
"text": text,
|
| 316 |
"file_content": file_content,
|
| 317 |
"file_name": file_name
|
| 318 |
}
|
| 319 |
else:
|
| 320 |
-
# Si no se sube archivo, solo se incluye el texto
|
| 321 |
message = {
|
| 322 |
"text": text,
|
| 323 |
"file_content": None,
|
| 324 |
"file_name": None
|
| 325 |
}
|
| 326 |
|
| 327 |
-
# Llamar a la función `simple_chat` con el mensaje
|
| 328 |
print(message)
|
| 329 |
response = simple_chat(message)
|
| 330 |
|
|
|
|
| 274 |
thread.join()
|
| 275 |
|
| 276 |
try:
|
| 277 |
+
buffer = buffer.strip()
|
| 278 |
buffer = buffer.strip('`')
|
| 279 |
buffer = buffer.strip('json')
|
| 280 |
json_content = json.loads(buffer)
|
|
|
|
| 293 |
return PlainTextResponse(formatted_text)
|
| 294 |
|
| 295 |
def format_json_to_string(json_content):
|
|
|
|
|
|
|
|
|
|
| 296 |
return json.dumps(json_content, ensure_ascii=False)
|
| 297 |
|
| 298 |
|
|
|
|
| 301 |
text: str = Form(...),
|
| 302 |
file: UploadFile = File(None)
|
| 303 |
):
|
|
|
|
| 304 |
if file:
|
|
|
|
| 305 |
file_content = BytesIO(await file.read())
|
| 306 |
file_name = file.filename
|
| 307 |
|
|
|
|
| 308 |
message = {
|
| 309 |
"text": text,
|
| 310 |
"file_content": file_content,
|
| 311 |
"file_name": file_name
|
| 312 |
}
|
| 313 |
else:
|
|
|
|
| 314 |
message = {
|
| 315 |
"text": text,
|
| 316 |
"file_content": None,
|
| 317 |
"file_name": None
|
| 318 |
}
|
| 319 |
|
|
|
|
| 320 |
print(message)
|
| 321 |
response = simple_chat(message)
|
| 322 |
|