Spaces:
Running
Running
drewThomasson
commited on
Commit
•
3271f83
1
Parent(s):
66ccdd7
Now the user doesn't have to wait for the que to know if their input was too long :)
Browse files
app.py
CHANGED
@@ -13,10 +13,10 @@ def generate_tts(text, temperature=0.1, repetition_penalty=1.1, max_length=4096)
|
|
13 |
# Set a character limit for the text input
|
14 |
max_characters = 30 # adjust as needed
|
15 |
|
16 |
-
# Check if input text exceeds character limit
|
17 |
if is_cpu and len(text) > max_characters:
|
18 |
raise gr.Error(
|
19 |
-
f"Text input is too long! Please limit to {max_characters} characters.\
|
20 |
)
|
21 |
|
22 |
# Log user input and parameters in the terminal
|
@@ -53,8 +53,22 @@ with gr.Blocks() as demo:
|
|
53 |
def on_max_length_change(val):
|
54 |
print(f"Max Length slider adjusted to: {val}")
|
55 |
|
56 |
-
#
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
text_input.change(on_text_input, inputs=text_input)
|
59 |
|
60 |
# Sliders with change events for tracking
|
|
|
13 |
# Set a character limit for the text input
|
14 |
max_characters = 30 # adjust as needed
|
15 |
|
16 |
+
# Check if input text exceeds character limit when on CPU
|
17 |
if is_cpu and len(text) > max_characters:
|
18 |
raise gr.Error(
|
19 |
+
f"Text input is too long! Please limit to {max_characters} characters.\nThis limit is in place to prevent long processing times as this interface is running on a free CPU tier."
|
20 |
)
|
21 |
|
22 |
# Log user input and parameters in the terminal
|
|
|
53 |
def on_max_length_change(val):
|
54 |
print(f"Max Length slider adjusted to: {val}")
|
55 |
|
56 |
+
# Dynamically set max_chars for text input based on whether it's CPU or GPU
|
57 |
+
if is_cpu:
|
58 |
+
text_input = gr.Textbox(
|
59 |
+
lines=2,
|
60 |
+
placeholder="Enter text to convert to speech (30 character limit on CPU)",
|
61 |
+
label="Text",
|
62 |
+
max_length=30 # Enforce character limit only on CPU
|
63 |
+
)
|
64 |
+
else:
|
65 |
+
text_input = gr.Textbox(
|
66 |
+
lines=2,
|
67 |
+
placeholder="Enter text to convert to speech",
|
68 |
+
label="Text"
|
69 |
+
)
|
70 |
+
|
71 |
+
# Track changes for debugging
|
72 |
text_input.change(on_text_input, inputs=text_input)
|
73 |
|
74 |
# Sliders with change events for tracking
|