try: from pip._internal.operations import freeze except ImportError: # pip < 10.0 from pip.operations import freeze pkgs = freeze.freeze() for pkg in pkgs: print(pkg) import os from fastapi import FastAPI, HTTPException, File, UploadFile from fastapi.middleware.cors import CORSMiddleware from PyPDF2 import PdfReader import google.generativeai as genai import json secret = os.environ["key"] genai.configure(api_key=secret) model_vision = genai.GenerativeModel('gemini-pro-vision') model_text = genai.GenerativeModel('gemini-pro') app = FastAPI() app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) @app.post("/get_ocr_data/") async def get_data(pdf: UploadFile = File(...)): try: # Read PDF file using PyPDF2 pdf_reader = PdfReader(pdf.file) text = "" # Extract text from each page for page in pdf_reader.pages: text += page.extract_text() # call gemini to get required data extracted text prompt = f"""this is cv data : {text.strip()} i want only fisrtname,lastname,contact number,total years of experince,linkdn link,experinece,skils in json format only""" response = model_text.generate_content(prompt) data = json.loads(response.text.replace("```json","").replace("```","")) return {"data":data} except Exception as e: raise HTTPException(status_code=500, detail=f"Error processing PDF: {str(e)}")