Spaces:
Build error
Build error
Commit
·
67c8829
1
Parent(s):
970c817
Update app.py
Browse files
app.py
CHANGED
|
@@ -336,40 +336,43 @@ async def test_concurrent_download():
|
|
| 336 |
]
|
| 337 |
await asyncio.gather(*downloads)
|
| 338 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 339 |
|
| 340 |
@app.route('/list_models', methods=['GET'])
|
| 341 |
def list_models():
|
| 342 |
-
include_remote = request.args.get('include_remote',
|
| 343 |
-
loop = asyncio.new_event_loop()
|
| 344 |
-
asyncio.set_event_loop(loop)
|
| 345 |
-
result = loop.run_until_complete(get_build().list_models(include_remote=include_remote))
|
| 346 |
-
return jsonify(result)
|
| 347 |
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
src = data.get('src')
|
| 353 |
-
trg = data.get('trg')
|
| 354 |
-
model = data.get('model')
|
| 355 |
-
pivot = data.get('pivot')
|
| 356 |
-
html = data.get('html', False)
|
| 357 |
|
| 358 |
-
|
| 359 |
-
asyncio.set_event_loop(loop)
|
| 360 |
-
result = loop.run_until_complete(get_build().translate(text, src, trg, model=model, pivot=pivot, html=html))
|
| 361 |
return jsonify(result)
|
| 362 |
|
| 363 |
-
@app.route('/
|
| 364 |
-
def
|
| 365 |
data = request.get_json()
|
| 366 |
-
model_id = data.get('model_id')
|
| 367 |
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 371 |
return jsonify(result)
|
| 372 |
|
|
|
|
| 373 |
if __name__ == "__main__":
|
| 374 |
config = Config()
|
| 375 |
config.bind = ["0.0.0.0:7860"] # You can specify the host and port here
|
|
|
|
| 336 |
]
|
| 337 |
await asyncio.gather(*downloads)
|
| 338 |
|
| 339 |
+
def run_async_function(func):
|
| 340 |
+
loop = asyncio.new_event_loop()
|
| 341 |
+
asyncio.set_event_loop(loop)
|
| 342 |
+
return loop.run_until_complete(func)
|
| 343 |
|
| 344 |
@app.route('/list_models', methods=['GET'])
|
| 345 |
def list_models():
|
| 346 |
+
include_remote = request.args.get('include_remote', 'false').lower() == 'true'
|
|
|
|
|
|
|
|
|
|
|
|
|
| 347 |
|
| 348 |
+
async def async_func():
|
| 349 |
+
async with get_build() as tl:
|
| 350 |
+
models = await tl.list_models(include_remote=include_remote)
|
| 351 |
+
return models
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 352 |
|
| 353 |
+
result = run_async_function(async_func())
|
|
|
|
|
|
|
| 354 |
return jsonify(result)
|
| 355 |
|
| 356 |
+
@app.route('/translate', methods=['POST'])
|
| 357 |
+
def translate():
|
| 358 |
data = request.get_json()
|
|
|
|
| 359 |
|
| 360 |
+
async def async_func():
|
| 361 |
+
async with get_build() as tl:
|
| 362 |
+
result = await tl.translate(
|
| 363 |
+
data['text'],
|
| 364 |
+
src=data.get('src'),
|
| 365 |
+
trg=data.get('trg'),
|
| 366 |
+
model=data.get('model'),
|
| 367 |
+
pivot=data.get('pivot'),
|
| 368 |
+
html=data.get('html', False)
|
| 369 |
+
)
|
| 370 |
+
return result
|
| 371 |
+
|
| 372 |
+
result = run_async_function(async_func())
|
| 373 |
return jsonify(result)
|
| 374 |
|
| 375 |
+
# Define more routes for other operations like download_model, etc.
|
| 376 |
if __name__ == "__main__":
|
| 377 |
config = Config()
|
| 378 |
config.bind = ["0.0.0.0:7860"] # You can specify the host and port here
|