-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Project updated
- Loading branch information
Showing
1,582 changed files
with
288,591 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,3 @@ | ||
KEY=94a5ad7bbedd4e6f833ec571c6d4b8a3 | ||
ENDPOINT=https://api.cognitive.microsofttranslator.com/ | ||
LOCATION=eastus |
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,69 @@ | ||
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy | ||
# More GitHub Actions for Azure: https://github.com/Azure/actions | ||
# More info on Python, GitHub Actions, and Azure App Service: https://aka.ms/python-webapps-actions | ||
|
||
name: Build and deploy Python app to Azure Web App - aiwebappazure | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Python version | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: '3.12' | ||
|
||
- name: Create and start virtual environment | ||
run: | | ||
python -m venv venv | ||
source venv/bin/activate | ||
- name: Install dependencies | ||
run: pip install -r requirements.txt | ||
|
||
# Optional: Add step to run tests here (PyTest, Django test suites, etc.) | ||
|
||
- name: Zip artifact for deployment | ||
run: zip release.zip ./* -r | ||
|
||
- name: Upload artifact for deployment jobs | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: python-app | ||
path: | | ||
release.zip | ||
!venv/ | ||
deploy: | ||
runs-on: ubuntu-latest | ||
needs: build | ||
environment: | ||
name: 'Production' | ||
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} | ||
|
||
steps: | ||
- name: Download artifact from build job | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: python-app | ||
|
||
- name: Unzip artifact for deployment | ||
run: unzip release.zip | ||
|
||
|
||
- name: 'Deploy to Azure Web App' | ||
uses: azure/webapps-deploy@v2 | ||
id: deploy-to-webapp | ||
with: | ||
app-name: 'aiwebappazure' | ||
slot-name: 'Production' | ||
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_3C21292972934716B3F17F6773A02077 }} |
Binary file not shown.
Binary file not shown.
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,83 @@ | ||
import requests, os, uuid, json | ||
from dotenv import load_dotenv | ||
import mysql.connector | ||
|
||
load_dotenv() | ||
|
||
from flask import Flask, redirect, url_for, request, render_template, session | ||
|
||
app = Flask(__name__) | ||
|
||
mydb = mysql.connector.connect( | ||
host="ai-db.mysql.database.azure.com", | ||
user="redblack", | ||
password="Password@123", | ||
database="ai" | ||
) | ||
|
||
mycursor = mydb.cursor() | ||
|
||
|
||
@app.route('/', methods=['GET']) | ||
def index(): | ||
mycursor.execute("SELECT * FROM histroy") | ||
|
||
myresult = mycursor.fetchall() | ||
|
||
return render_template('index.html', myresult=myresult) | ||
|
||
@app.route('/', methods=['POST']) | ||
def index_post(): | ||
# Read the values from the form | ||
original_text = request.form['text'] | ||
target_language = request.form['language'] | ||
|
||
# Load the values from .env | ||
#key = os.environ['KEY'] | ||
#endpoint = os.environ['ENDPOINT'] | ||
#location = os.environ['LOCATION'] | ||
|
||
key="94a5ad7bbedd4e6f833ec571c6d4b8a3" | ||
endpoint="https://api.cognitive.microsofttranslator.com/" | ||
location="eastus" | ||
|
||
# Indicate that we want to translate and the API version (3.0) and the target language | ||
path = '/translate?api-version=3.0' | ||
# Add the target language parameter | ||
target_language_parameter = '&to=' + target_language | ||
# Create the full URL | ||
constructed_url = endpoint + path + target_language_parameter | ||
|
||
# Set up the header information, which includes our subscription key | ||
headers = { | ||
'Ocp-Apim-Subscription-Key': key, | ||
'Ocp-Apim-Subscription-Region': location, | ||
'Content-type': 'application/json', | ||
'X-ClientTraceId': str(uuid.uuid4()) | ||
} | ||
|
||
# Create the body of the request with the text to be translated | ||
body = [{ 'text': original_text }] | ||
|
||
# Make the call using post | ||
translator_request = requests.post(constructed_url, headers=headers, json=body) | ||
# Retrieve the JSON response | ||
translator_response = translator_request.json() | ||
# Retrieve the translation | ||
translated_text = translator_response[0]['translations'][0]['text'] | ||
|
||
# store in the Database | ||
sql = "INSERT INTO histroy (transated_text, original_text, target_language) VALUES (%s, %s, %s)" | ||
val = (translated_text, original_text, target_language) | ||
mycursor.execute(sql, val) | ||
|
||
mydb.commit() | ||
|
||
# Call render template, passing the translated text, | ||
# original text, and target language to the template | ||
return render_template( | ||
'results.html', | ||
translated_text=translated_text, | ||
original_text=original_text, | ||
target_language=target_language | ||
) |
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,4 @@ | ||
flask | ||
python-dotenv | ||
requests | ||
mysql-connector-python |
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,83 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous"> | ||
<link rel="preconnect" href="https://fonts.googleapis.com"> | ||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> | ||
<link href="https://fonts.googleapis.com/css2?family=Oswald:wght@200;300;400;500;600;700&display=swap" rel="stylesheet"> | ||
<style> | ||
body { | ||
font-family: 'Oswald', sans-serif; | ||
} | ||
|
||
.form-group { | ||
padding: 0.5rem 0rem; | ||
} | ||
|
||
.form-control { | ||
border: 2px solid #ddd; | ||
border-radius: 0rem; | ||
} | ||
|
||
.btn, .btn-success { | ||
border-radius: 0rem; | ||
font-weight: bold; | ||
width: 100%; | ||
margin: 0.5rem 0rem; | ||
font-family: 'Oswald', sans-serif; | ||
} | ||
</style> | ||
<title>Translator</title> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<h1>Vox</h1> | ||
<div>A short and powerful name that means voice in Latin. It conveys the message of giving voice to different languages and cultures</div> | ||
<div> | ||
<form method="POST"> | ||
<div class="form-group"> | ||
<textarea name="text" cols="20" rows="10" class="form-control" placeholder="Enter some text"></textarea> | ||
</div> | ||
<div class="form-group"> | ||
<label for="language">Language:</label> | ||
<select name="language" class="form-control"> | ||
<option value="en">English</option> | ||
<option value="it">Italian</option> | ||
<option value="ja">Japanese</option> | ||
<option value="ru">Russian</option> | ||
<option value="de">German</option> | ||
<option value="hi">Hindi</option> | ||
</select> | ||
</div> | ||
<div> | ||
<button type="submit" class="btn btn-success">Translate!</button> | ||
</div> | ||
</form> | ||
</div> | ||
<div> | ||
<h2>Recent Search</h2> | ||
<table class="table"> | ||
<thead> | ||
<tr> | ||
<th scope="col">Translated Text</th> | ||
<th scope="col">Original Text</th> | ||
<th scope="col">Language Code</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for x in myresult %} | ||
<tr> | ||
<td>{{ x[0] }}</td> | ||
<td>{{ x[1] }}</td> | ||
<td>{{ x[2] }}</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
|
||
</div> | ||
</div> | ||
</body> | ||
</html> |
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,27 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" | ||
integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous"> | ||
<title>Result</title> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<h2>Results</h2> | ||
<div> | ||
<strong>Original text:</strong> {{ original_text }} | ||
</div> | ||
<div> | ||
<strong>Translated text:</strong> {{ translated_text }} | ||
</div> | ||
<div> | ||
<strong>Target language code:</strong> {{ target_language }} | ||
</div> | ||
<div> | ||
<a href="{{ url_for('index') }}">Try another one!</a> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
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 @@ | ||
pip |
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,28 @@ | ||
Copyright 2007 Pallets | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are | ||
met: | ||
|
||
1. Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
|
||
3. Neither the name of the copyright holder nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | ||
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED | ||
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Oops, something went wrong.