Skip to content

Commit

Permalink
Added skelteon structure
Browse files Browse the repository at this point in the history
  • Loading branch information
lavskillup committed Jun 14, 2021
1 parent 414e0d1 commit 0086204
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 0 deletions.
1 change: 1 addition & 0 deletions final_project/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: python3 server.py
5 changes: 5 additions & 0 deletions final_project/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
applications:
- name: ibmlearner_translation_app
random-random: true
memory: 64M
5 changes: 5 additions & 0 deletions final_project/requirements.txt
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
1 change: 1 addition & 0 deletions final_project/runtime.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python-3.9.4
24 changes: 24 additions & 0 deletions final_project/server.py
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)
26 changes: 26 additions & 0 deletions final_project/static/mywebscript.js
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();
}

19 changes: 19 additions & 0 deletions final_project/templates/index.html
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>

0 comments on commit 0086204

Please sign in to comment.