Spaces:
Runtime error
Runtime error
fix upload
Browse files- app/main.py +4 -9
app/main.py
CHANGED
|
@@ -54,22 +54,17 @@ async def process_input(text: str):
|
|
| 54 |
return StreamingResponse(astreamer(generator), media_type='text/event-stream')
|
| 55 |
|
| 56 |
async def parse_body(request: Request):
|
| 57 |
-
data = await request.body()
|
| 58 |
-
print("TYPE: ")
|
| 59 |
-
print(type(data))
|
| 60 |
-
print("DATA: ")
|
| 61 |
-
print(data)
|
| 62 |
return data
|
| 63 |
|
| 64 |
@app.post("/upload")
|
| 65 |
-
def upload(data = Depends(parse_body)):
|
| 66 |
-
if data
|
| 67 |
try:
|
| 68 |
-
filename = data['filename']
|
| 69 |
print("Filename: " + filename)
|
| 70 |
path = f"{files_dir}/{filename}"
|
| 71 |
with open(path, "wb") as f:
|
| 72 |
-
f.write(data
|
| 73 |
session_assistant.ingest(files_dir)
|
| 74 |
pathlib.Path(path).unlink()
|
| 75 |
except Exception as e:
|
|
|
|
| 54 |
return StreamingResponse(astreamer(generator), media_type='text/event-stream')
|
| 55 |
|
| 56 |
async def parse_body(request: Request):
|
| 57 |
+
data: bytes = await request.body()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
return data
|
| 59 |
|
| 60 |
@app.post("/upload")
|
| 61 |
+
def upload(filename: str, data: bytes = Depends(parse_body)):
|
| 62 |
+
if data:
|
| 63 |
try:
|
|
|
|
| 64 |
print("Filename: " + filename)
|
| 65 |
path = f"{files_dir}/{filename}"
|
| 66 |
with open(path, "wb") as f:
|
| 67 |
+
f.write(data)
|
| 68 |
session_assistant.ingest(files_dir)
|
| 69 |
pathlib.Path(path).unlink()
|
| 70 |
except Exception as e:
|