-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
123 lines (94 loc) · 2.98 KB
/
app.py
File metadata and controls
123 lines (94 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import json
from flask import Flask, render_template, request
import book
import data
from data_types import IJMESProfile, NameProfile, Profile, profile_descriptions
from trans import transliterate, transliterate_ijmes, transliterate_llm
from vocalization import vocalize
app = Flask(__name__)
# Pages
@app.route("/")
def index():
# name, value, type, title, description
profile = [
(
name,
field.default,
field.type.__name__,
*profile_descriptions.get(
name, (" ".join(name.split("_")).capitalize(), "", "", "")
),
)
for (name, field) in Profile.__dataclass_fields__.items()
]
return render_template(
"index.html", profile=profile, input_map=data.input_conversion_map
)
@app.route("/names")
def names():
profile = [
(
name,
field.default,
field.type.__name__,
*profile_descriptions.get(
name, (" ".join(name.split("_")).capitalize(), "", "", "")
),
)
for (name, field) in NameProfile.__dataclass_fields__.items()
]
return render_template(
"names.html", profile=profile, input_map=data.input_conversion_map
)
@app.route("/ijmes")
def ijmes():
return render_template("ijmes.html", input_map=data.input_conversion_map)
@app.route("/ijmes/llm")
def ijmes_llm():
return render_template("ijmes-llm.html", input_map=data.input_conversion_map)
@app.route("/book")
def _book():
return render_template(
"book.html", toc=book.toc_html, content=book.content, input_map=book.input_map
)
# API endpoints
@app.route("/transliterate", methods=["POST"])
def trans():
"""
Takes a string of Arabic text and settings and returns a transliteration
"""
data = json.loads(request.data)
text = data["text"]
profile = Profile(**data["profile"])
return transliterate(text, profile)
@app.route("/transliterate/names", methods=["POST"])
def trans_names():
data = json.loads(request.data)
text = data["text"]
profile = NameProfile(**data["profile"])
return transliterate(text, profile)
@app.route("/transliterate/ijmes", methods=["POST"])
def trans_ijmes():
data = json.loads(request.data)
text = data["text"]
profile = IJMESProfile(**data["profile"])
return transliterate_ijmes(text, profile)
@app.route("/transliterate/ijmes/llm", methods=["POST"])
def trans_ijmes_llm():
data = json.loads(request.data)
text = data["text"]
return transliterate_llm(text)
@app.route("/vocalize", methods=["POST"])
def vocalization():
"""
Takes a string of Arabic text and returns a vocalized version
"""
text = request.data.decode("utf-8")
return vocalize(text)
@app.route("/feedback", methods=["POST"])
def feedback():
with open("feedback.jsonl", "ab") as f:
f.write(request.data + b"\n")
return ""
if __name__ == "__main__":
app.run(host="0.0.0.0", port="5000", debug=True)