Spaces:
Running
Running
mateoluksenberg
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -225,16 +225,28 @@ def simple_chat(message, temperature: float = 0.8, max_length: int = 4096, top_p
|
|
225 |
|
226 |
conversation = []
|
227 |
prompt_files = []
|
228 |
-
if message["files"]:
|
229 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
230 |
if choice == "image":
|
231 |
conversation.append({"role": "user", "image": contents, "content": message['text']})
|
232 |
elif choice == "doc":
|
233 |
-
format_msg = contents + "\n\n\n" + "{} files uploaded.\n" + message['text']
|
234 |
conversation.append({"role": "user", "content": format_msg})
|
235 |
else:
|
236 |
-
|
237 |
-
|
|
|
238 |
|
239 |
|
240 |
print(f"Conversation is -\n{conversation}")
|
@@ -344,59 +356,38 @@ def simple_chat(message, temperature: float = 0.8, max_length: int = 4096, top_p
|
|
344 |
# return PlainTextResponse(f"Error: {str(e)}")
|
345 |
|
346 |
|
|
|
|
|
347 |
@app.post("/chat/")
|
348 |
async def test_endpoint(
|
349 |
text: str = Form(...),
|
350 |
file: UploadFile = File(None)
|
351 |
):
|
352 |
-
# Construir el mensaje base solo con el texto
|
353 |
-
message = {"text": text, "files": []}
|
354 |
-
|
355 |
# Verificar si se ha subido un archivo
|
356 |
if file:
|
357 |
# Leer el archivo en memoria
|
358 |
file_content = BytesIO(await file.read())
|
359 |
file_name = file.filename
|
360 |
-
|
361 |
-
# Agregar el archivo al mensaje
|
362 |
-
message["files"].append({"file_content": file_content, "file_name": file_name})
|
363 |
-
|
364 |
-
# Llamar a la función `simple_chat` con el mensaje y recolectar la salida
|
365 |
-
response = "".join([chunk for chunk in simple_chat(message)])
|
366 |
-
|
367 |
-
return {"response": response}
|
368 |
-
|
369 |
-
|
370 |
-
# @app.post("/chat/")
|
371 |
-
# async def test_endpoint(
|
372 |
-
# text: str = Form(...),
|
373 |
-
# file: UploadFile = File(None)
|
374 |
-
# ):
|
375 |
-
# # Verificar si se ha subido un archivo
|
376 |
-
# if file:
|
377 |
-
# # Leer el archivo en memoria
|
378 |
-
# file_content = BytesIO(await file.read())
|
379 |
-
# file_name = file.filename
|
380 |
|
381 |
-
#
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
#
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
|
395 |
-
#
|
396 |
-
|
397 |
-
|
398 |
|
399 |
-
|
400 |
|
401 |
|
402 |
with gr.Blocks(css=CSS, theme="soft", fill_height=True) as demo:
|
|
|
225 |
|
226 |
conversation = []
|
227 |
prompt_files = []
|
228 |
+
# if message["files"]:
|
229 |
+
# choice, contents = mode_load(message["files"][-1])
|
230 |
+
# if choice == "image":
|
231 |
+
# conversation.append({"role": "user", "image": contents, "content": message['text']})
|
232 |
+
# elif choice == "doc":
|
233 |
+
# format_msg = contents + "\n\n\n" + "{} files uploaded.\n" + message['text']
|
234 |
+
# conversation.append({"role": "user", "content": format_msg})
|
235 |
+
# else:
|
236 |
+
# choice = ""
|
237 |
+
# conversation.append({"role": "user", "image": "", "content": message['text']})
|
238 |
+
|
239 |
+
if message["file_content"]:
|
240 |
+
choice, contents = mode_load(message["file_content"])
|
241 |
if choice == "image":
|
242 |
conversation.append({"role": "user", "image": contents, "content": message['text']})
|
243 |
elif choice == "doc":
|
244 |
+
format_msg = contents + "\n\n\n" + "{} files uploaded.\n".format(message['file_name']) + message['text']
|
245 |
conversation.append({"role": "user", "content": format_msg})
|
246 |
else:
|
247 |
+
conversation.append({"role": "user", "content": message['text']})
|
248 |
+
|
249 |
+
print(f"Conversation is -\n{conversation}")
|
250 |
|
251 |
|
252 |
print(f"Conversation is -\n{conversation}")
|
|
|
356 |
# return PlainTextResponse(f"Error: {str(e)}")
|
357 |
|
358 |
|
359 |
+
|
360 |
+
|
361 |
@app.post("/chat/")
|
362 |
async def test_endpoint(
|
363 |
text: str = Form(...),
|
364 |
file: UploadFile = File(None)
|
365 |
):
|
|
|
|
|
|
|
366 |
# Verificar si se ha subido un archivo
|
367 |
if file:
|
368 |
# Leer el archivo en memoria
|
369 |
file_content = BytesIO(await file.read())
|
370 |
file_name = file.filename
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
371 |
|
372 |
+
# Construir el mensaje con el archivo y el texto
|
373 |
+
message = {
|
374 |
+
"text": text,
|
375 |
+
"file_content": file_content,
|
376 |
+
"file_name": file_name
|
377 |
+
}
|
378 |
+
else:
|
379 |
+
# Si no se sube archivo, solo se incluye el texto
|
380 |
+
message = {
|
381 |
+
"text": text,
|
382 |
+
"file_content": None,
|
383 |
+
"file_name": None
|
384 |
+
}
|
385 |
|
386 |
+
# Llamar a la función `simple_chat` con el mensaje
|
387 |
+
print(message)
|
388 |
+
response = simple_chat(message)
|
389 |
|
390 |
+
return response
|
391 |
|
392 |
|
393 |
with gr.Blocks(css=CSS, theme="soft", fill_height=True) as demo:
|