Spaces:
Sleeping
Sleeping
File size: 1,935 Bytes
f79f681 |
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
from flask import jsonify, Flask, request
from flasgger import Swagger
from llmware.models import ModelCatalog
app = Flask(__name__)
swagger = Swagger(app, config={'specs_route': '/swagger-ui'}, merge=True)
@app.route('/', methods=['GET'])
def test_concurrency():
import random
random_numbers = [random.randint(0, 100000) for _ in range(100)]
total_sum = sum(random_numbers)
print(f'Sum: {total_sum}')
return jsonify({'message': 'Welcome'}), 200
@app.route('/slim-ner', methods=['POST'])
def llmware_model():
"""
# llmware/slim-ner model to identify named entities such as people, organization, and place
---
description: llmware/slim-ner model to identify named entities such as people, organization, and places
produces:
- application/json
parameters:
- in: body
name: body
description: Input data
schema:
$ref: '#/definitions/model'
definitions:
model:
type: object
properties:
params:
type: array
items:
type: string
collectionFormat: multi
input:
type: string
example: {"params":["people","organization","place"],"input":"Yesterday, in Redmond, Satya Nadella announced that Microsoft would be launching a new AI strategy."}
responses:
'200':
description: Success
schema:
type: object
example: {"person": ["Satya Nadella"], "organization": ["Microsoft"], "place": ["Redmond"]}
"""
data = request.get_json()
text = data['input']
slim_model = ModelCatalog().load_model('llmware/slim-ner')
response = slim_model.function_call(text, function='classify', params=data['params'])
print(f'Input: {text} \nResponse: {response}')
return jsonify(response['llm_response']), 200
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=7860)
|