|
|
|
|
| from flask import Flask, request, jsonify, render_template
|
| from libqutrub.mosaref_main import do_sarf
|
|
|
| app = Flask(__name__, template_folder="templates")
|
|
|
|
|
| @app.route("/")
|
| def home():
|
| return render_template("index.html")
|
|
|
|
|
| @app.route("/conjugate", methods=["POST"])
|
| def conjugate():
|
| data = request.get_json()
|
|
|
| word = data.get("word", "").strip()
|
| future_type = data.get("future_type", "فتحة")
|
| tense = data.get("tense", "past")
|
|
|
| params = {
|
| "alltense": False,
|
| "past": False,
|
| "future": False,
|
| "imperative": False,
|
| "future_moode": False,
|
| "confirmed": False,
|
| "passive": False,
|
| "transitive": True
|
| }
|
|
|
| if tense == "past":
|
| params["past"] = True
|
| elif tense == "future":
|
| params["future"] = True
|
| elif tense == "jussive":
|
| params["future"] = True
|
| params["future_moode"] = True
|
| elif tense == "subjunctive":
|
| params["future"] = True
|
| params["future_moode"] = True
|
| elif tense == "confirmed":
|
| params["future"] = True
|
| params["confirmed"] = True
|
| elif tense == "imperative":
|
| params["imperative"] = True
|
| elif tense == "confirmed_imperative":
|
| params["imperative"] = True
|
| params["confirmed"] = True
|
|
|
| result = do_sarf(
|
| word=word,
|
| future_type=future_type,
|
| display_format="HTML",
|
| **params
|
| )
|
|
|
| if result is None:
|
| return jsonify({"result": "<p>تعذر تصريف الفعل. تأكد من صحة الإدخال.</p>"})
|
|
|
| return jsonify({"result": result})
|
|
|
|
|
| if __name__ == "__main__":
|
| app.run(host="0.0.0.0", port=7860, debug=False) |