Spaces:
Running
Running
mateoluksenberg
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -278,7 +278,8 @@ def simple_chat(message: dict, temperature: float = 0.8, max_length: int = 4096,
|
|
278 |
|
279 |
if "file" in message and message["file"]:
|
280 |
file_contents = message["file"]
|
281 |
-
|
|
|
282 |
if choice == "image":
|
283 |
conversation.append({"role": "user", "image": contents, "content": message["text"]})
|
284 |
elif choice == "doc":
|
@@ -311,21 +312,27 @@ def simple_chat(message: dict, temperature: float = 0.8, max_length: int = 4096,
|
|
311 |
@app.post("/chat/")
|
312 |
async def test_endpoint(
|
313 |
text: str = Form(...),
|
314 |
-
file: UploadFile = File(None)
|
315 |
):
|
316 |
if not text:
|
317 |
raise HTTPException(status_code=400, detail="Missing 'text' in request body")
|
318 |
|
|
|
|
|
319 |
if file:
|
320 |
-
# Process the file if it is provided
|
321 |
file_contents = await file.read()
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
|
|
|
|
|
|
|
|
|
|
329 |
|
330 |
|
331 |
with gr.Blocks(css=CSS, theme="soft", fill_height=True) as demo:
|
|
|
278 |
|
279 |
if "file" in message and message["file"]:
|
280 |
file_contents = message["file"]
|
281 |
+
# Aquí debes asegurarte de que `mode_load` pueda manejar `file_contents` como bytes
|
282 |
+
choice, contents = mode_load(io.BytesIO(file_contents))
|
283 |
if choice == "image":
|
284 |
conversation.append({"role": "user", "image": contents, "content": message["text"]})
|
285 |
elif choice == "doc":
|
|
|
312 |
@app.post("/chat/")
|
313 |
async def test_endpoint(
|
314 |
text: str = Form(...),
|
315 |
+
file: Optional[UploadFile] = File(None)
|
316 |
):
|
317 |
if not text:
|
318 |
raise HTTPException(status_code=400, detail="Missing 'text' in request body")
|
319 |
|
320 |
+
# Lee el archivo si está presente
|
321 |
+
file_contents = None
|
322 |
if file:
|
|
|
323 |
file_contents = await file.read()
|
324 |
+
|
325 |
+
# Construye el diccionario para `simple_chat`
|
326 |
+
message = {
|
327 |
+
"text": text,
|
328 |
+
"file": file_contents
|
329 |
+
}
|
330 |
+
|
331 |
+
print(message)
|
332 |
+
|
333 |
+
# Llama a `simple_chat` con el diccionario
|
334 |
+
response = simple_chat(message)
|
335 |
+
return response
|
336 |
|
337 |
|
338 |
with gr.Blocks(css=CSS, theme="soft", fill_height=True) as demo:
|