From be9cfc70c696c0047137cce61c5cd1df1195764a Mon Sep 17 00:00:00 2001 From: Ridoy sheikh <111294017+ridoysheikh@users.noreply.github.com> Date: Sat, 24 Jun 2023 22:15:02 +0600 Subject: [PATCH 1/3] Final changes --- .../machinetranslation/tests/tests.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 final_project/machinetranslation/tests/tests.py diff --git a/final_project/machinetranslation/tests/tests.py b/final_project/machinetranslation/tests/tests.py new file mode 100644 index 000000000..c1b023647 --- /dev/null +++ b/final_project/machinetranslation/tests/tests.py @@ -0,0 +1,19 @@ +import unittest +from translator import * + +class TranslationTest(unittest.TestCase): + + def test_englishToFrench(self): + english_text = "Hello" + expected_result = "Bonjour" + french_text=english_to_french(english_text) + self.assertEqual(french_text, expected_result) + + def french_to_english(self): + french_text = "Bonjour" + expected_result = "Hello" + english_text=frenchToEnglish(french_text) + self.assertEqual(english_text, expected_result) + +if __name__ == '__main__': + unittest.main() From 6a0c53d7346b92e41ec194e59cb16a70935523d8 Mon Sep 17 00:00:00 2001 From: Ridoy sheikh <111294017+ridoysheikh@users.noreply.github.com> Date: Sat, 24 Jun 2023 22:16:23 +0600 Subject: [PATCH 2/3] Final changes --- final_project/machinetranslation/__init__.py | 1 + final_project/machinetranslation/translator.py | 12 ++++++++++++ final_project/server.py | 8 ++++++-- 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 final_project/machinetranslation/__init__.py create mode 100644 final_project/machinetranslation/translator.py diff --git a/final_project/machinetranslation/__init__.py b/final_project/machinetranslation/__init__.py new file mode 100644 index 000000000..faac15605 --- /dev/null +++ b/final_project/machinetranslation/__init__.py @@ -0,0 +1 @@ +from .translator import * \ No newline at end of file diff --git a/final_project/machinetranslation/translator.py b/final_project/machinetranslation/translator.py new file mode 100644 index 000000000..17bc92cfc --- /dev/null +++ b/final_project/machinetranslation/translator.py @@ -0,0 +1,12 @@ +''' this code for building translator ''' +from deep_translator import MyMemoryTranslator + +def english_to_french(english_text): + ''' This function takes an english text and translates it to french ''' + french_text = MyMemoryTranslator(source='en', target='fr').translate(english_text) + return french_text + +def french_to_english(french_text): + ''' This function takes a french text and translates it to english ''' + english_text = MyMemoryTranslator(source='fr', target='en').translate(french_text) + return english_text diff --git a/final_project/server.py b/final_project/server.py index a776f7ae3..ea307c34f 100755 --- a/final_project/server.py +++ b/final_project/server.py @@ -1,6 +1,7 @@ from machinetranslation import translator from flask import Flask, render_template, request import json +from machinetranslation import * app = Flask("Web Translator") @@ -8,17 +9,20 @@ def englishToFrench(): textToTranslate = request.args.get('textToTranslate') # Write your code here - return "Translated text to French" + french_text=english_to_french(textToTranslate) + return french_text @app.route("/frenchToEnglish") def frenchToEnglish(): textToTranslate = request.args.get('textToTranslate') # Write your code here - return "Translated text to English" + english_text=french_to_english(textToTranslate) + return english_text @app.route("/") def renderIndexPage(): # Write the code to render template + return render_template("index.html") if __name__ == "__main__": app.run(host="0.0.0.0", port=8080) From e8209d76615fed67853f52780f180ce6649649d7 Mon Sep 17 00:00:00 2001 From: Ridoy sheikh <111294017+ridoysheikh@users.noreply.github.com> Date: Sat, 24 Jun 2023 22:30:27 +0600 Subject: [PATCH 3/3] Final Changes --- final_project/Dockerfile | 7 +++++++ final_project/requirements.txt | 12 ++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 final_project/Dockerfile diff --git a/final_project/Dockerfile b/final_project/Dockerfile new file mode 100644 index 000000000..9d0d53b8d --- /dev/null +++ b/final_project/Dockerfile @@ -0,0 +1,7 @@ +FROM python:alpine3.7 +COPY . /app +WORKDIR /app +RUN pip install -r requirements.txt +EXPOSE 8080 +ENTRYPOINT [ "python" ] +CMD [ "server.py" ] \ No newline at end of file diff --git a/final_project/requirements.txt b/final_project/requirements.txt index f341673c2..caed67c0a 100755 --- a/final_project/requirements.txt +++ b/final_project/requirements.txt @@ -1,6 +1,6 @@ -Flask==1.1.2 -Flask-WTF==0.14.3 -ibm-watson==4.4.1 -python-dotenv==0.13.0 -pyJWT==1.7.1 -deep_translator==1.11.1 +Flask +Flask-WTF +ibm-watson +python-dotenv +pyJWT +deep_translator