CoolFace
Apppublic

Coder19/interview_system

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
summarization.py43 linesDownload Raw Back to api
1from fastapi import APIRouter2from fastapi import APIRouter, UploadFile, File, HTTPException3from interview_prep.summarization import *4from fastapi.responses import JSONResponse5from fastapi import FastAPI6import io7router = APIRouter()8 9# 10    11@router.post("/process_pdf")12async def process_pdf(file: UploadFile = File(...)):13    try:14        # Read the uploaded file as bytes15        pdf_bytes = await file.read()16        pdf_path = io.BytesIO(pdf_bytes)  # Convert bytes to file-like object17        18        # Extract text from the PDF19        extract_result = extract_text_from_pdf(pdf_path)20        if extract_result["error"]:21            return JSONResponse(22                status_code=400, 23                content={"error": extract_result["error"]}24            )25        26        # Summarize the extracted text27        summary_result = summarize_text(extract_result["text"])28        if summary_result["error"]:29            return JSONResponse(30                status_code=400, 31                content={"error": summary_result["error"]}32            )33            34        # Return the successful summary35        return JSONResponse(content={"summary": summary_result["summary"]})36        37    except Exception as e:38        error_msg = f"An unexpected error occurred: {str(e)}"39        logger.error(error_msg)40        return JSONResponse(41            status_code=500, 42            content={"error": error_msg}43        )