CaioXapelaum's picture
Update main.py
7011d6a verified
raw
history blame contribute delete
895 Bytes
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)