-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathspeech.py
More file actions
49 lines (38 loc) · 1.64 KB
/
speech.py
File metadata and controls
49 lines (38 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from flask import Flask, render_template, request, url_for, Blueprint
import os
lts = Blueprint('lts', __name__,
template_folder='templates', static_folder='static')
# Paths for ASL and ISL image folders
ASL_PATH = "static/ASL"
ISL_PATH = "static/ISL"
# Function to translate text into sign language images
def get_sign_language_images(text, language):
folder_path = ASL_PATH if language == "ASL" else ISL_PATH
images = []
for letter in text.lower():
if letter.isalpha() or letter.isdigit():
image_filename = f"{letter}.jpg"
image_path = os.path.join(folder_path, image_filename)
print(image_path)
if os.path.exists(image_path):
image_url = url_for('static', filename=f"{language.upper()}/{image_filename}")
images.append(image_url)
else:
images.append(url_for('static', filename="placeholder.jpg"))
return images
@lts.route('/')
def home():
return render_template('index.html')
@lts.route('/translate', methods=['POST'])
def translate():
# Get input values from the user
text_input = request.form.get("text_input")
speech_input = request.form.get("speech_input")
language_choice = request.form.get("language")
input_text = text_input if text_input else speech_input
if input_text:
images = get_sign_language_images(input_text, language_choice)
return render_template('index.html', images=images, input_text=input_text, language=language_choice)
return render_template('index.html', images=None)
if __name__ == '__main__':
app.run(debug=True)