File size: 895 Bytes
78b9a14
 
7011d6a
1dab2e6
78b9a14
1dab2e6
7011d6a
4f88cb7
 
 
78b9a14
4f88cb7
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
28
29
30
31
import aiohttp
from fastapi import FastAPI
from fastapi.responses import JSONResponse, PlainTextResponse

app = FastAPI()

@app.get('/', response_class=PlainTextResponse)
async def homepage():
    return "Request or go to /v1/models to use the space, make sure its a GET"

@app.get("/v1/models")
async def main():
    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)