Spaces:
Runtime error
Runtime error
File size: 3,050 Bytes
05b45a5 |
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
from typing import Tuple
import gradio as gr
from .. import files
def create_input_column(disable_local_saving: bool = False) -> Tuple[gr.Column, dict]:
"""Create the input column with text input and file handling."""
with gr.Column(scale=1) as col:
text_input = gr.Textbox(
label="Text to speak", placeholder="Enter text here...", lines=4
)
# Always show file upload but handle differently based on disable_local_saving
file_upload = gr.File(label="Upload Text File (.txt)", file_types=[".txt"])
if not disable_local_saving:
# Show full interface with tabs when saving is enabled
with gr.Tabs() as tabs:
# Set first tab as selected by default
tabs.selected = 0
# Direct Input Tab
with gr.TabItem("Direct Input"):
text_submit_direct = gr.Button(
"Generate Speech", variant="primary", size="lg"
)
# File Input Tab
with gr.TabItem("From File"):
# Existing files dropdown
input_files_list = gr.Dropdown(
label="Select Existing File",
choices=files.list_input_files(),
value=None,
)
file_preview = gr.Textbox(
label="File Content Preview", interactive=False, lines=4
)
with gr.Row():
file_submit = gr.Button(
"Generate Speech", variant="primary", size="lg"
)
clear_files = gr.Button(
"Clear Files", variant="secondary", size="lg"
)
else:
# Just show the generate button when saving is disabled
text_submit_direct = gr.Button(
"Generate Speech", variant="primary", size="lg"
)
tabs = None
input_files_list = None
file_preview = None
file_submit = None
clear_files = None
# Initialize components based on disable_local_saving
if disable_local_saving:
components = {
"tabs": None,
"text_input": text_input,
"text_submit": text_submit_direct,
"file_select": None,
"file_upload": file_upload, # Keep file upload even when saving is disabled
"file_preview": None,
"file_submit": None,
"clear_files": None,
}
else:
components = {
"tabs": tabs,
"text_input": text_input,
"text_submit": text_submit_direct,
"file_select": input_files_list,
"file_upload": file_upload,
"file_preview": file_preview,
"file_submit": file_submit,
"clear_files": clear_files,
}
return col, components
|