fix
Browse files- app.py +24 -5
- requirements.txt +32 -10
app.py
CHANGED
@@ -1,7 +1,26 @@
|
|
1 |
-
from
|
|
|
2 |
|
3 |
-
app =
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, request, jsonify
|
2 |
+
from transformers import pipeline
|
3 |
|
4 |
+
app = Flask(__name__)
|
5 |
|
6 |
+
translator = pipeline("translation", model="Bildad/Swahili-English_Translation")
|
7 |
+
|
8 |
+
|
9 |
+
@app.route("/translate", methods=["POST"])
|
10 |
+
def translate():
|
11 |
+
data = request.get_json()
|
12 |
+
|
13 |
+
if "text" not in data:
|
14 |
+
return jsonify({"error": "No text provided"}), 400
|
15 |
+
|
16 |
+
text_to_translate = data["text"]
|
17 |
+
translation = translator(text_to_translate)[0]
|
18 |
+
translated_text = translation["translation_text"]
|
19 |
+
|
20 |
+
return jsonify({"translated_text": translated_text})
|
21 |
+
|
22 |
+
|
23 |
+
if __name__ == "__main__":
|
24 |
+
from waitress import serve
|
25 |
+
|
26 |
+
serve(app, host="0.0.0.0", port=10000)
|
requirements.txt
CHANGED
@@ -1,13 +1,35 @@
|
|
1 |
-
|
2 |
-
|
|
|
3 |
click==8.1.7
|
4 |
-
|
5 |
-
|
6 |
-
|
|
|
7 |
idna==3.8
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
typing_extensions==4.12.2
|
13 |
-
|
|
|
|
|
|
1 |
+
blinker==1.8.2
|
2 |
+
certifi==2024.7.4
|
3 |
+
charset-normalizer==3.3.2
|
4 |
click==8.1.7
|
5 |
+
filelock==3.15.4
|
6 |
+
Flask==3.0.3
|
7 |
+
fsspec==2024.6.1
|
8 |
+
huggingface-hub==0.24.6
|
9 |
idna==3.8
|
10 |
+
itsdangerous==2.2.0
|
11 |
+
Jinja2==3.1.3
|
12 |
+
joblib==1.4.2
|
13 |
+
MarkupSafe==2.1.5
|
14 |
+
mpmath==1.3.0
|
15 |
+
networkx==3.2.1
|
16 |
+
numpy==2.1.0
|
17 |
+
packaging==24.1
|
18 |
+
pillow==10.2.0
|
19 |
+
PyYAML==6.0.2
|
20 |
+
regex==2024.7.24
|
21 |
+
requests==2.32.3
|
22 |
+
sacremoses==0.1.1
|
23 |
+
safetensors==0.4.4
|
24 |
+
sentencepiece==0.2.0
|
25 |
+
sympy==1.12
|
26 |
+
tokenizers==0.19.1
|
27 |
+
torch==2.4.0
|
28 |
+
torchaudio==2.4.0
|
29 |
+
torchvision==0.19.0
|
30 |
+
tqdm==4.66.5
|
31 |
+
transformers==4.44.2
|
32 |
typing_extensions==4.12.2
|
33 |
+
urllib3==2.2.2
|
34 |
+
waitress==3.0.0
|
35 |
+
Werkzeug==3.0.4%
|