Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
GitHub Actions
commited on
Commit
·
e5d1272
1
Parent(s):
8259023
Sync from GitHub repo
Browse files- app.py +27 -0
- requirements.txt +2 -1
app.py
CHANGED
@@ -68,6 +68,29 @@ from flask_migrate import Migrate
|
|
68 |
import requests
|
69 |
import functools
|
70 |
import time # Added for potential retries
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
|
72 |
|
73 |
def get_client_ip():
|
@@ -572,6 +595,10 @@ def generate_tts():
|
|
572 |
if not text or len(text) > 1000:
|
573 |
return jsonify({"error": "Invalid or too long text"}), 400
|
574 |
|
|
|
|
|
|
|
|
|
575 |
# Check if sentence has already been consumed
|
576 |
if is_sentence_consumed(text):
|
577 |
remaining_count = len(get_unconsumed_sentences(all_harvard_sentences))
|
|
|
68 |
import requests
|
69 |
import functools
|
70 |
import time # Added for potential retries
|
71 |
+
from langdetect import detect, DetectorFactory
|
72 |
+
|
73 |
+
# Set random seed for consistent language detection results
|
74 |
+
DetectorFactory.seed = 0
|
75 |
+
|
76 |
+
|
77 |
+
def is_english_text(text):
|
78 |
+
"""
|
79 |
+
Detect if the given text is in English.
|
80 |
+
Returns True if English, False otherwise.
|
81 |
+
"""
|
82 |
+
try:
|
83 |
+
# Remove leading/trailing whitespace and check if text is not empty
|
84 |
+
text = text.strip()
|
85 |
+
if not text:
|
86 |
+
return False
|
87 |
+
|
88 |
+
# Detect language
|
89 |
+
detected_language = detect(text)
|
90 |
+
return detected_language == 'en'
|
91 |
+
except Exception:
|
92 |
+
# If detection fails, assume it's not English for safety
|
93 |
+
return False
|
94 |
|
95 |
|
96 |
def get_client_ip():
|
|
|
595 |
if not text or len(text) > 1000:
|
596 |
return jsonify({"error": "Invalid or too long text"}), 400
|
597 |
|
598 |
+
# Check if text is in English
|
599 |
+
if not is_english_text(text):
|
600 |
+
return jsonify({"error": "Only English language text is supported for now. Please provide text in English. A multilingual Arena is coming soon!"}), 400
|
601 |
+
|
602 |
# Check if sentence has already been consumed
|
603 |
if is_sentence_consumed(text):
|
604 |
remaining_count = len(get_unconsumed_sentences(all_harvard_sentences))
|
requirements.txt
CHANGED
@@ -12,4 +12,5 @@ gunicorn
|
|
12 |
waitress
|
13 |
fal-client
|
14 |
git+https://github.com/playht/pyht
|
15 |
-
datasets
|
|
|
|
12 |
waitress
|
13 |
fal-client
|
14 |
git+https://github.com/playht/pyht
|
15 |
+
datasets
|
16 |
+
langdetect
|