from flask import Flask, request, jsonify from flask_cors import CORS import cv2 import numpy as np from sign_language_model import predict_sign_language app = Flask(__name__) CORS(app) # Allow cross-origin requests for Hugging Face or other external integrations @app.route('/') def home(): return "Welcome to the Learning App for Deaf and Mute" @app.route('/convert', methods=['POST']) def convert_sign_to_text(): """ Accepts an image of a sign language gesture and converts it to text. """ try: # Check if an image file is provided in the request if 'image' not in request.files: return jsonify({"error": "No image file provided", "status": "failure"}), 400 file = request.files['image'] image = cv2.imdecode(np.frombuffer(file.read(), np.uint8), cv2.IMREAD_COLOR) text = predict_sign_language(image) return jsonify({"text": text, "status": "success"}), 200 except Exception as e: return jsonify({"error": str(e), "status": "failure"}), 500 @app.route('/learn', methods=['GET']) def learning_module(): """ Provides learning content for deaf and mute individuals. """ # Example learning content (can be extended) content = { "title": "Learn Sign Language", "lessons": [ {"id": 1, "title": "Alphabet A-Z"}, {"id": 2, "title": "Common Words and Phrases"}, {"id": 3, "title": "Numbers 1-10"} ] } return jsonify(content), 200 if __name__ == "__main__": app.run(host="0.0.0.0", port=5000, debug=True, use_reloader=False)