import aiohttp from fastapi import FastAPI from fastapi.responses import JSONResponse app = FastAPI() @app.get("/v1/models") async def index(): url = 'https://huggingface.co/models-json?inference=warm&sort=trending&withCount=true' async with aiohttp.ClientSession() as session: async with session.get(url) as response: models = await response.json() output = [ { "created": 0, "id": key['id'], "object": "model", "owned_by": key['author'], "pipeline": key['pipeline_tag'] } for key in models['models'] if not key['private'] and not key['gated'] ] return JSONResponse(content=output)