ikraamkb commited on
Commit
6be72e5
·
verified ·
1 Parent(s): 6b4645b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -16
app.py CHANGED
@@ -1,19 +1,18 @@
1
  @app.post("/summarize/")
2
  async def summarize_api(file: UploadFile = File(...), length: str = Form("medium")):
3
- with tempfile.NamedTemporaryFile(delete=False, suffix=os.path.splitext(file.filename)[1]) as temp:
4
- shutil.copyfileobj(file.file, temp)
5
- temp.flush()
6
- class FileObj: name = temp.name
7
- text, error = extract_text(FileObj.name, os.path.splitext(file.filename)[1][1:].lower())
8
- if error:
9
- return JSONResponse({"error": error}, status_code=400)
10
 
11
- summary = generate_summary(text, length)
12
- audio_path = text_to_speech(summary)
13
- pdf_path = create_pdf(summary, file.filename)
14
-
15
- return JSONResponse({
16
- "summary": summary,
17
- "audio_url": f"/files/{os.path.basename(audio_path)}" if audio_path else None,
18
- "pdf_url": f"/files/{os.path.basename(pdf_path)}" if pdf_path else None
19
- })
 
 
1
  @app.post("/summarize/")
2
  async def summarize_api(file: UploadFile = File(...), length: str = Form("medium")):
3
+ try:
4
+ # Process document and generate summary
5
+ summary = "This would be your generated summary text"
6
+ audio_url = "/files/summary_audio.mp3" # Generated audio path
7
+ pdf_url = "/files/summary.pdf" # Generated PDF path
 
 
8
 
9
+ return {
10
+ "summary": summary,
11
+ "audio_url": audio_url,
12
+ "pdf_url": pdf_url
13
+ }
14
+ except Exception as e:
15
+ return JSONResponse(
16
+ {"detail": str(e)},
17
+ status_code=500
18
+ )