Spaces:
Sleeping
Sleeping
Commit
·
f79f681
1
Parent(s):
78ee242
Added app.py, Dockerfile and requirements files
Browse files- Dockerfile +13 -0
- app.py +60 -0
- requirements.txt +4 -0
Dockerfile
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
|
2 |
+
# you will also find guides on how best to write your Dockerfile
|
3 |
+
|
4 |
+
FROM python:3.10.9
|
5 |
+
WORKDIR /code
|
6 |
+
|
7 |
+
COPY ./requirements.txt /code/requirements.txt
|
8 |
+
|
9 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
10 |
+
|
11 |
+
COPY . .
|
12 |
+
|
13 |
+
CMD ["gunicorn", "-b", "0.0.0.0:7860", "-w", "4", "--threads", "2", "app:app"]
|
app.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import jsonify, Flask, request
|
2 |
+
from flasgger import Swagger
|
3 |
+
from llmware.models import ModelCatalog
|
4 |
+
|
5 |
+
app = Flask(__name__)
|
6 |
+
swagger = Swagger(app, config={'specs_route': '/swagger-ui'}, merge=True)
|
7 |
+
|
8 |
+
|
9 |
+
@app.route('/', methods=['GET'])
|
10 |
+
def test_concurrency():
|
11 |
+
import random
|
12 |
+
random_numbers = [random.randint(0, 100000) for _ in range(100)]
|
13 |
+
total_sum = sum(random_numbers)
|
14 |
+
print(f'Sum: {total_sum}')
|
15 |
+
return jsonify({'message': 'Welcome'}), 200
|
16 |
+
|
17 |
+
|
18 |
+
@app.route('/slim-ner', methods=['POST'])
|
19 |
+
def llmware_model():
|
20 |
+
"""
|
21 |
+
# llmware/slim-ner model to identify named entities such as people, organization, and place
|
22 |
+
---
|
23 |
+
description: llmware/slim-ner model to identify named entities such as people, organization, and places
|
24 |
+
produces:
|
25 |
+
- application/json
|
26 |
+
parameters:
|
27 |
+
- in: body
|
28 |
+
name: body
|
29 |
+
description: Input data
|
30 |
+
schema:
|
31 |
+
$ref: '#/definitions/model'
|
32 |
+
definitions:
|
33 |
+
model:
|
34 |
+
type: object
|
35 |
+
properties:
|
36 |
+
params:
|
37 |
+
type: array
|
38 |
+
items:
|
39 |
+
type: string
|
40 |
+
collectionFormat: multi
|
41 |
+
input:
|
42 |
+
type: string
|
43 |
+
example: {"params":["people","organization","place"],"input":"Yesterday, in Redmond, Satya Nadella announced that Microsoft would be launching a new AI strategy."}
|
44 |
+
responses:
|
45 |
+
'200':
|
46 |
+
description: Success
|
47 |
+
schema:
|
48 |
+
type: object
|
49 |
+
example: {"person": ["Satya Nadella"], "organization": ["Microsoft"], "place": ["Redmond"]}
|
50 |
+
"""
|
51 |
+
data = request.get_json()
|
52 |
+
text = data['input']
|
53 |
+
slim_model = ModelCatalog().load_model('llmware/slim-ner')
|
54 |
+
response = slim_model.function_call(text, function='classify', params=data['params'])
|
55 |
+
print(f'Input: {text} \nResponse: {response}')
|
56 |
+
return jsonify(response['llm_response']), 200
|
57 |
+
|
58 |
+
|
59 |
+
if __name__ == '__main__':
|
60 |
+
app.run(debug=True, host='0.0.0.0', port=7860)
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Flask~=3.0.3
|
2 |
+
flasgger~=0.9.7.1
|
3 |
+
gunicorn~=22.0.0
|
4 |
+
llmware==0.2.10
|