File size: 727 Bytes
78b9a14
 
 
1dab2e6
78b9a14
1dab2e6
78b9a14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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)