j10sanders commited on
Commit
f2cca47
1 Parent(s): 2b71cfb

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from http import HTTPStatus
3
+ from flask import Flask, request
4
+ from flask_caching import Cache
5
+ from flask_cors import CORS
6
+ from rubber_duck import codegen
7
+
8
+
9
+ codgen_model = os.environ.get('MODEL', 'Salesforce/codegen-350M-mono')
10
+ print(f'Attempting to setup codegen with the model {codgen_model}')
11
+ codegen.setup(
12
+ os.environ.get('MODEL', 'Salesforce/codegen-350M-mono'),
13
+ setup_torch=os.environ.get("SETUP_TORCH") == 'true',
14
+ )
15
+
16
+
17
+ app = Flask(__name__)
18
+ CORS(app)
19
+ cache = Cache(app, config={'CACHE_TYPE': 'simple'})
20
+
21
+
22
+ @app.route('/generate', methods=['GET'])
23
+ @cache.cached(timeout=1440) # Cache for 24 hours
24
+ def generate():
25
+ user_input = request.args.get('input', '', type=str)
26
+ if not user_input:
27
+ return 'Missing input', HTTPStatus.BAD_REQUEST
28
+
29
+ return {
30
+ 'result': codegen.generate(user_input)
31
+ }, HTTPStatus.OK
32
+
33
+
34
+ @app.route('/status', methods=['GET'])
35
+ def status():
36
+ return {'status': 'OK'}