generated from ibm-developer-skills-network/coding-project-template
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
414e0d1
commit 0086204
Showing
7 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: python3 server.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
applications: | ||
- name: ibmlearner_translation_app | ||
random-random: true | ||
memory: 64M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Flask==1.1.2 | ||
Flask-WTF==0.14.3 | ||
ibm-watson==4.4.1 | ||
python-dotenv==0.13.0 | ||
pyJWT==1.7.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
python-3.9.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from machinetranslation import translator | ||
from flask import Flask, render_template, request | ||
import json | ||
|
||
app = Flask("Web Translator") | ||
|
||
@app.route("/englishToFrench") | ||
def englishToSpanish(): | ||
textToTranslate = request.args.get('textToTranslate') | ||
# Write your code here | ||
return "Translated text to French" | ||
|
||
@app.route("/frenchToEnglish") | ||
def frenchToEnglish(): | ||
textToTranslate = request.args.get('textToTranslate') | ||
# Write your code here | ||
return "Translated text to English" | ||
|
||
@app.route("/") | ||
def renderIndexPage(): | ||
# Write the code to render template | ||
|
||
if __name__ == "__main__": | ||
app.run(host="0.0.0.0", port=8080) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
let translateToFrench = ()=>{ | ||
textToTranslate = document.getElementById("textToTranslate").value; | ||
|
||
let xhttp = new XMLHttpRequest(); | ||
xhttp.onreadystatechange = function() { | ||
if (this.readyState == 4 && this.status == 200) { | ||
document.getElementById("translated_text").innerHTML = xhttp.responseText; | ||
} | ||
}; | ||
xhttp.open("GET", "englishToFrench?textToTranslate"+"="+textToTranslate, true); | ||
xhttp.send(); | ||
} | ||
|
||
let translateToEnglish = ()=>{ | ||
textToTranslate = document.getElementById("textToTranslate").value; | ||
|
||
let xhttp = new XMLHttpRequest(); | ||
xhttp.onreadystatechange = function() { | ||
if (this.readyState == 4 && this.status == 200) { | ||
document.getElementById("translated_text").innerHTML = xhttp.responseText; | ||
} | ||
}; | ||
xhttp.open("GET", "frenchToEnglish?textToTranslate"+"="+textToTranslate, true); | ||
xhttp.send(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<html> | ||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> | ||
<script src="./static/mywebscript.js"></script> | ||
<div class="card"> | ||
<div class="card-body"> | ||
<div class="mb-3"> | ||
<label class="form-label">Text to be translated</label> | ||
<input type="textarea" class="form-control" id="textToTranslate"> | ||
</div> | ||
|
||
<div style="padding: 25px 25px 25px 25px;"> | ||
<button onclick="translateToFrench()" class="btn btn-secondary">Translate to French</button> | ||
<button onclick="translateToEnglish()" class="btn btn-secondary">Translate to English</button> | ||
</div> | ||
|
||
<div id="translated_text" style="padding: 25px 25px 25px 25px;"></div> | ||
</div> | ||
</div> | ||
</html> |