Skip to content
Open

Main #156

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions final_project/Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
Empty file.
36 changes: 36 additions & 0 deletions final_project/machinetranslation/tests/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""
This module tests the functions from translator.py
"""
from translator import french_to_english, english_to_french
import unittest


class TestFrenchToEnglish(unittest.TestCase):
"""
This class tests the french_to_english function fron translator.py
"""

def test1(self):
"""
This function runs the test for the correct and incorrect
outputs of the french_to_english function
"""
self.assertEqual(french_to_english("Bonjour"), "Hi")
self.assertNotEqual(french_to_english("Ce qui est en place"), "Hello")


class TestEnglishToFrench(unittest.TestCase):
"""
This class tests the english_to_french function fron translator.py
"""

def test2(self):
"""
This function runs the test for the correct and incorrect
outputs of the english_to_french function
"""
self.assertEqual(english_to_french("Hello"), "Bonjour")
self.assertNotEqual(english_to_french("Hi"), "What's up?")


unittest.main()
24 changes: 24 additions & 0 deletions final_project/machinetranslation/translator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
This module translate french and english strings
"""
from deep_translator import MyMemoryTranslator


def english_to_french(english_text):
"""
Translates an english string to french
"""
french_text = MyMemoryTranslator(source="en-US", target="fr-FR").translate(
english_text
)
return french_text


def french_to_english(french_text):
"""
Translates a french string into english
"""
english_text = MyMemoryTranslator(source="fr-FR", target="en-US").translate(
french_text
)
return english_text
10 changes: 4 additions & 6 deletions final_project/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
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
pyJWT
deep_translator
15 changes: 11 additions & 4 deletions final_project/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,28 @@

app = Flask("Web Translator")


@app.route("/englishToFrench")
def englishToFrench():
textToTranslate = request.args.get('textToTranslate')
textToTranslate = request.args.get("textToTranslate")
# Write your code here
return "Translated text to French"
translated = translator.english_to_french(textToTranslate)
return f"{textToTranslate} was translated text to {translated}"


@app.route("/frenchToEnglish")
def frenchToEnglish():
textToTranslate = request.args.get('textToTranslate')
textToTranslate = request.args.get("textToTranslate")
# Write your code here
return "Translated text to English"
translated = translator.french_to_english(textToTranslate)
return f"{textToTranslate} was translated text to {translated}"


@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)