LalitMahale
commited on
Commit
·
642a8cb
1
Parent(s):
9322f35
error solved
Browse files
app.py
CHANGED
|
@@ -94,26 +94,24 @@ async def audio_chat(audio: UploadFile = File(...), token: str = ""):
|
|
| 94 |
raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")
|
| 95 |
|
| 96 |
|
| 97 |
-
UPLOAD_DIR = "uploads"
|
| 98 |
-
Path(UPLOAD_DIR).mkdir(exist_ok=True)
|
| 99 |
-
|
| 100 |
# Request model
|
| 101 |
class FileUploadRequest(BaseModel):
|
| 102 |
filename: str
|
| 103 |
content_type: str
|
| 104 |
base64_file: str
|
| 105 |
|
|
|
|
|
|
|
|
|
|
| 106 |
@app.post("/summarizer")
|
| 107 |
async def upload_base64(file_data: FileUploadRequest):
|
| 108 |
try:
|
| 109 |
print(file_data.filename)
|
| 110 |
file_path = os.path.join(UPLOAD_DIR, file_data.filename)
|
| 111 |
|
| 112 |
-
# Decode and save file
|
| 113 |
with open(file_path, "wb") as f:
|
| 114 |
f.write(base64.b64decode(file_data.base64_file))
|
| 115 |
|
| 116 |
-
# Simulate processing
|
| 117 |
extracted_text = f"Saved file: {file_path}\nContent-Type: {file_data.content_type}\n"
|
| 118 |
extracted_text += f"(First 100 bytes shown)\n\n"
|
| 119 |
with open(file_path, "rb") as f:
|
|
@@ -123,6 +121,7 @@ async def upload_base64(file_data: FileUploadRequest):
|
|
| 123 |
|
| 124 |
except Exception as e:
|
| 125 |
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
| 126 |
|
| 127 |
@app.post("/upload")
|
| 128 |
async def upload_file(req: UploadRequest):
|
|
|
|
| 94 |
raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")
|
| 95 |
|
| 96 |
|
|
|
|
|
|
|
|
|
|
| 97 |
# Request model
|
| 98 |
class FileUploadRequest(BaseModel):
|
| 99 |
filename: str
|
| 100 |
content_type: str
|
| 101 |
base64_file: str
|
| 102 |
|
| 103 |
+
UPLOAD_DIR = "/tmp/uploads"
|
| 104 |
+
Path(UPLOAD_DIR).mkdir(parents=True, exist_ok=True)
|
| 105 |
+
|
| 106 |
@app.post("/summarizer")
|
| 107 |
async def upload_base64(file_data: FileUploadRequest):
|
| 108 |
try:
|
| 109 |
print(file_data.filename)
|
| 110 |
file_path = os.path.join(UPLOAD_DIR, file_data.filename)
|
| 111 |
|
|
|
|
| 112 |
with open(file_path, "wb") as f:
|
| 113 |
f.write(base64.b64decode(file_data.base64_file))
|
| 114 |
|
|
|
|
| 115 |
extracted_text = f"Saved file: {file_path}\nContent-Type: {file_data.content_type}\n"
|
| 116 |
extracted_text += f"(First 100 bytes shown)\n\n"
|
| 117 |
with open(file_path, "rb") as f:
|
|
|
|
| 121 |
|
| 122 |
except Exception as e:
|
| 123 |
raise HTTPException(status_code=500, detail=str(e))
|
| 124 |
+
|
| 125 |
|
| 126 |
@app.post("/upload")
|
| 127 |
async def upload_file(req: UploadRequest):
|