tahirmuhammadcs commited on
Commit
12b825b
1 Parent(s): 6328e66

Create app.py

Browse files

testing.. Beta

Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify
2
+ from transformers import pipeline
3
+ from flask_cors import CORS
4
+
5
+ app = Flask(__name__)
6
+ CORS(app)
7
+ # Load the pipeline
8
+ pipe = pipeline("token-classification", model="mirfan899/uner-bert-ner")
9
+
10
+ def convert_to_native_types(result):
11
+ for item in result:
12
+ item['score'] = float(item['score'])
13
+ return result
14
+
15
+ @app.route('/classify', methods=['POST'])
16
+ def classify():
17
+ # Get the text from the request
18
+ data = request.json
19
+ text = data.get('text', '')
20
+
21
+ # Perform token classification
22
+ results = pipe(text)
23
+ results = convert_to_native_types(results)
24
+
25
+ return jsonify(results)
26
+
27
+ if __name__ == '__main__':
28
+ app.run(host='0.0.0.0', port=5000)