Spaces:
Sleeping
Sleeping
GVAmaresh
commited on
Commit
·
ebe2b18
1
Parent(s):
98b5869
dev: check working
Browse files
app.py
CHANGED
@@ -258,4 +258,96 @@ def main():
|
|
258 |
except Exception as error:
|
259 |
print(f'An error occurred: {error}')
|
260 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
261 |
|
|
|
258 |
except Exception as error:
|
259 |
print(f'An error occurred: {error}')
|
260 |
|
261 |
+
#-----------------------------------------------------------------------------------------
|
262 |
+
|
263 |
+
from fastapi.responses import JSONResponse
|
264 |
+
from pydantic import BaseModel
|
265 |
+
from fastapi import FastAPI, File, UploadFile, HTTPException
|
266 |
+
from typing import List
|
267 |
+
|
268 |
+
service = main()
|
269 |
+
|
270 |
+
@app.get("/api/check")
|
271 |
+
def check_working():
|
272 |
+
try:
|
273 |
+
return JSONResponse(
|
274 |
+
{"status": 200, "message": "Server is working fine", "data": None},
|
275 |
+
status_code=200,
|
276 |
+
)
|
277 |
+
except Exception as e:
|
278 |
+
return JSONResponse(
|
279 |
+
{"status": 500, "message": "Server is not working", "error": e},
|
280 |
+
)
|
281 |
+
|
282 |
+
@app.get("/")
|
283 |
+
def read():
|
284 |
+
return JSONResponse(
|
285 |
+
{"status": 200, "message": "Working Successfully"}, status_code=200
|
286 |
+
)
|
287 |
+
|
288 |
+
@app.post("/api/save-docs")
|
289 |
+
async def save_docs(file: UploadFile = File(...)):
|
290 |
+
try:
|
291 |
+
print(file.filename)
|
292 |
+
file_id, extracted_text, status = await push_file_db(service, file)
|
293 |
+
if not file_id:
|
294 |
+
return JSONResponse(
|
295 |
+
{"status": 500, "message": status, "data": None}, status_code=500
|
296 |
+
)
|
297 |
+
print(file_id)
|
298 |
+
return JSONResponse(
|
299 |
+
{
|
300 |
+
"status": 200,
|
301 |
+
"message": "Document saved successfully",
|
302 |
+
"data": {
|
303 |
+
"file_id": file_id,
|
304 |
+
"extracted_text": extracted_text,
|
305 |
+
"title": file.filename,
|
306 |
+
},
|
307 |
+
},
|
308 |
+
status_code=200,
|
309 |
+
)
|
310 |
+
except Exception as e:
|
311 |
+
print(f"Error: {e}")
|
312 |
+
return JSONResponse({"status": 500, "message": str(e)}, status_code=500)
|
313 |
+
|
314 |
+
|
315 |
+
@app.post("/api/get-abstract")
|
316 |
+
async def get_abstract(file: UploadFile = File(...)):
|
317 |
+
try:
|
318 |
+
print(file.filename)
|
319 |
+
extracted_text, status = await extract_text_url(file)
|
320 |
+
if not extracted_text:
|
321 |
+
return JSONResponse(
|
322 |
+
{"status": 500, "message": status, "data": None}, status_code=500
|
323 |
+
)
|
324 |
+
return JSONResponse(
|
325 |
+
{
|
326 |
+
"status": 200,
|
327 |
+
"message": "Document saved successfully",
|
328 |
+
"data": {"extracted_text": extracted_text, "title": file.filename},
|
329 |
+
},
|
330 |
+
status_code=200,
|
331 |
+
)
|
332 |
+
except Exception as e:
|
333 |
+
print(f"Error: {e}")
|
334 |
+
return JSONResponse({"status": 500, "message": str(e)}, status_code=500)
|
335 |
+
|
336 |
+
class DeleteRequest(BaseModel):
|
337 |
+
_id: List[str]
|
338 |
+
|
339 |
+
@app.post("/api/delete-report")
|
340 |
+
async def delete_report(req: DeleteRequest):
|
341 |
+
print(req._id)
|
342 |
+
try:
|
343 |
+
delete_result = delete_reports_by_ids(req._id)
|
344 |
+
return {"message": "Deleted successfully", "deleted_ids": req._id}
|
345 |
+
except Exception as e:
|
346 |
+
raise HTTPException(status_code=500, detail=f"Error deleting reports: {str(e)}")
|
347 |
+
|
348 |
+
def delete_reports_by_ids(ids: List[str]):
|
349 |
+
print(f"Deleting reports with IDs: {ids}")
|
350 |
+
return True
|
351 |
+
|
352 |
+
|
353 |
|