Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple #159

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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" ]
1 change: 1 addition & 0 deletions final_project/machinetranslation/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .translator import *
19 changes: 19 additions & 0 deletions final_project/machinetranslation/tests/tests.py
Original file line number Diff line number Diff line change
@@ -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()
12 changes: 12 additions & 0 deletions final_project/machinetranslation/translator.py
Original file line number Diff line number Diff line change
@@ -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
12 changes: 6 additions & 6 deletions final_project/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
8 changes: 6 additions & 2 deletions final_project/server.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
from machinetranslation import translator
from flask import Flask, render_template, request
import json
from machinetranslation import *

app = Flask("Web Translator")

@app.route("/englishToFrench")
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)