Update main.py
Browse files
main.py
CHANGED
@@ -1,21 +1,26 @@
|
|
1 |
-
import
|
2 |
-
import
|
3 |
-
from
|
4 |
|
5 |
-
app =
|
6 |
|
7 |
-
@app.
|
8 |
-
def index():
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import aiohttp
|
2 |
+
from fastapi import FastAPI
|
3 |
+
from fastapi.responses import JSONResponse
|
4 |
|
5 |
+
app = FastAPI()
|
6 |
|
7 |
+
@app.get("/v1/models")
|
8 |
+
async def index():
|
9 |
+
url = 'https://huggingface.co/models-json?inference=warm&sort=trending&withCount=true'
|
10 |
+
async with aiohttp.ClientSession() as session:
|
11 |
+
async with session.get(url) as response:
|
12 |
+
models = await response.json()
|
13 |
+
|
14 |
+
output = [
|
15 |
+
{
|
16 |
+
"created": 0,
|
17 |
+
"id": key['id'],
|
18 |
+
"object": "model",
|
19 |
+
"owned_by": key['author'],
|
20 |
+
"pipeline": key['pipeline_tag']
|
21 |
+
}
|
22 |
+
for key in models['models']
|
23 |
+
if not key['private'] and not key['gated']
|
24 |
+
]
|
25 |
+
|
26 |
+
return JSONResponse(content=output)
|