CaioXapelaum commited on
Commit
78b9a14
·
verified ·
1 Parent(s): 738e6ba

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +24 -19
main.py CHANGED
@@ -1,21 +1,26 @@
1
- import json
2
- import httpx
3
- from flask import Flask, jsonify
4
 
5
- app = Flask(__name__)
6
 
7
- @app.route('/v1/models')
8
- def index():
9
- modelsraw = httpx.get('https://huggingface.co/models-json?inference=warm&sort=trending&withCount=true')
10
- models = json.loads(modelsraw.text)
11
- output = []
12
- for key in models['models']:
13
- if key['private'] == False and key['gated'] == False:
14
- output.append({
15
- "created": 0,
16
- "id": key['id'],
17
- "object": "model",
18
- "owned_by": key['author'],
19
- "pipeline": key['pipeline_tag']
20
- })
21
- return jsonify(output)
 
 
 
 
 
 
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)