Spaces:
Runtime error
Runtime error
Download app.py from Taghrid/Translator: direct link, hf CLI and curl.
- Browser
- Download file 888 Bytes
-
https://huggingface.co/spaces/Taghrid/Translator/resolve/main/app.py
- Command line
-
hf download hf://spaces/Taghrid/Translator/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Taghrid/Translator/resolve/main/app.py
888 Bytes
| import os | |
| import logging | |
| from flask import Flask, request, jsonify | |
| from final import Translator | |
| app = Flask(_name_) | |
| model_path = 'model.h5' | |
| model = Translator(model_path) | |
| logging.basicConfig(level=logging.INFO) | |
| def index(): | |
| """Provide a simple health check route.""" | |
| return "Hello world!" | |
| def predict(): | |
| """Provide the main prediction API route. Responds to both GET and POST requests.""" | |
| logging.info("Predict request received!") | |
| question_text = request.args.get("question_text") | |
| predicted_answer = model.predict(question_text) | |
| logging.info("Predicted answer: {}".format(predicted_answer)) | |
| return jsonify({"predicted_answer": predicted_answer}) | |
| def main(): | |
| """Run the Flask app.""" | |
| app.run(host="0.0.0.0", port=8000, debug=False) | |
| if _name_ == "_main_": | |
| main() |