from pydantic import BaseModel from fastapi.middleware.cors import CORSMiddleware from fastapi import FastAPI, HTTPException from linkedin_api import Linkedin app = FastAPI() # Enable CORS # app.add_middleware( # CORSMiddleware, # allow_origins=["*"], # allow_credentials=True, # allow_methods=["*"], # allow_headers=["*"], # ) # Authenticate using any Linkedin account credentials class GenerateInput(BaseModel): prompt: str def fetch_profile(prompt: str): if not prompt.strip(): raise HTTPException(status_code=400, detail="Please provide a non-empty prompt.") api = Linkedin('suma.shree59@gmail.com', '#845524509suma') c = api.get_profile(prompt) return c @app.head("/") async def head_root(): return {"message": "This is a HEAD request to the root URL."} @app.get("/", tags=["Home"]) def api_home(): return {'detail': 'Welcome to FastAPI LinkedIn Crawler by Knowde!'} @app.post("/api/fetch", tags=["Fetch"]) def inference(data: GenerateInput): return fetch_profile(data.prompt)