harshith1411 commited on
Commit
8527aef
·
verified ·
1 Parent(s): 4f7121d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -2
app.py CHANGED
@@ -1,9 +1,11 @@
1
  from flask import Flask, request, jsonify
 
2
  import cv2
3
  import numpy as np
4
  from sign_language_model import predict_sign_language
5
 
6
  app = Flask(__name__)
 
7
 
8
  @app.route('/')
9
  def home():
@@ -15,8 +17,12 @@ def convert_sign_to_text():
15
  Accepts an image of a sign language gesture and converts it to text.
16
  """
17
  try:
 
 
 
 
18
  file = request.files['image']
19
- image = cv2.imdecode(np.fromstring(file.read(), np.uint8), cv2.IMREAD_COLOR)
20
  text = predict_sign_language(image)
21
  return jsonify({"text": text, "status": "success"}), 200
22
  except Exception as e:
@@ -39,4 +45,4 @@ def learning_module():
39
  return jsonify(content), 200
40
 
41
  if __name__ == "__main__":
42
- app.run(debug=True, use_reloader=False)
 
1
  from flask import Flask, request, jsonify
2
+ from flask_cors import CORS
3
  import cv2
4
  import numpy as np
5
  from sign_language_model import predict_sign_language
6
 
7
  app = Flask(__name__)
8
+ CORS(app) # Allow cross-origin requests for Hugging Face or other external integrations
9
 
10
  @app.route('/')
11
  def home():
 
17
  Accepts an image of a sign language gesture and converts it to text.
18
  """
19
  try:
20
+ # Check if an image file is provided in the request
21
+ if 'image' not in request.files:
22
+ return jsonify({"error": "No image file provided", "status": "failure"}), 400
23
+
24
  file = request.files['image']
25
+ image = cv2.imdecode(np.frombuffer(file.read(), np.uint8), cv2.IMREAD_COLOR)
26
  text = predict_sign_language(image)
27
  return jsonify({"text": text, "status": "success"}), 200
28
  except Exception as e:
 
45
  return jsonify(content), 200
46
 
47
  if __name__ == "__main__":
48
+ app.run(host="0.0.0.0", port=5000, debug=True, use_reloader=False)