File size: 885 Bytes
0d83986
 
 
 
 
 
094c949
 
 
 
 
 
 
 
 
0d83986
 
 
094c949
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
@app.post("/summarize/")
async def summarize_api(file: UploadFile = File(...), length: str = Form("medium")):
    with tempfile.NamedTemporaryFile(delete=False, suffix=os.path.splitext(file.filename)[1]) as temp:
        shutil.copyfileobj(file.file, temp)
        temp.flush()
        class FileObj: name = temp.name
        text, error = extract_text(FileObj.name, os.path.splitext(file.filename)[1][1:].lower())
        if error:
            return JSONResponse({"error": error}, status_code=400)
        
        summary = generate_summary(text, length)
        audio_path = text_to_speech(summary)
        pdf_path = create_pdf(summary, file.filename)

    return JSONResponse({
        "summary": summary,
        "audio_url": f"/files/{os.path.basename(audio_path)}" if audio_path else None,
        "pdf_url": f"/files/{os.path.basename(pdf_path)}" if pdf_path else None
    })