Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -42,13 +42,13 @@ FONT_STYLES = {
|
|
42 |
},
|
43 |
"nastaliq": {
|
44 |
"name": "Nastaliq",
|
45 |
-
"family": "
|
46 |
-
"css": "font-family: '
|
47 |
},
|
48 |
"naskh": {
|
49 |
"name": "Naskh",
|
50 |
-
"family": "
|
51 |
-
"css": "font-family: '
|
52 |
}
|
53 |
}
|
54 |
|
@@ -216,9 +216,13 @@ class TTSDatasetCollector:
|
|
216 |
font_filename = font_family + '.ttf'
|
217 |
font_dest = self.fonts_path / font_filename
|
218 |
|
|
|
|
|
|
|
|
|
219 |
# Save the font file
|
220 |
with open(font_dest, 'wb') as f:
|
221 |
-
f.write(
|
222 |
|
223 |
# Add to custom fonts
|
224 |
self.custom_fonts[font_family] = {
|
@@ -516,33 +520,24 @@ def create_interface():
|
|
516 |
}
|
517 |
"""
|
518 |
|
519 |
-
#
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
if os.path.exists(font_path):
|
525 |
-
font_face_css += f"""
|
526 |
-
@font-face {{
|
527 |
-
font-family: '{font_info["family"]}';
|
528 |
-
src: url('file/{font_path}') format('truetype');
|
529 |
-
}}
|
530 |
-
"""
|
531 |
-
else:
|
532 |
-
# For system fonts like 'Arial' and 'Times New Roman', no need to specify src
|
533 |
-
pass
|
534 |
|
535 |
-
custom_css
|
536 |
|
537 |
with gr.Blocks(title="TTS Dataset Collection Tool", css=custom_css) as interface:
|
|
|
|
|
538 |
status = gr.Textbox(
|
539 |
label="Status",
|
540 |
interactive=False,
|
541 |
-
max_lines=3
|
|
|
542 |
)
|
543 |
|
544 |
-
gr.Markdown("# TTS Dataset Collection Tool")
|
545 |
-
|
546 |
with gr.Row():
|
547 |
# Left column - Configuration and Input
|
548 |
with gr.Column(scale=1):
|
@@ -550,7 +545,8 @@ def create_interface():
|
|
550 |
label="Paste Text",
|
551 |
placeholder="Paste your text here...",
|
552 |
lines=5,
|
553 |
-
elem_classes=["small-input"]
|
|
|
554 |
)
|
555 |
file_input = gr.File(
|
556 |
label="Or Upload Text File (.txt)",
|
@@ -568,18 +564,20 @@ def create_interface():
|
|
568 |
elem_classes=["small-input"]
|
569 |
)
|
570 |
font_select = gr.Dropdown(
|
571 |
-
choices=list(FONT_STYLES.keys())
|
572 |
value="english_serif",
|
573 |
label="Select Font Style",
|
574 |
elem_classes=["small-input"]
|
575 |
)
|
576 |
# Custom font upload
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
|
|
|
|
583 |
|
584 |
# Dataset Info
|
585 |
with gr.Accordion("Dataset Statistics", open=False):
|
@@ -750,21 +748,6 @@ def create_interface():
|
|
750 |
# Update font dropdown
|
751 |
font_choices = list(FONT_STYLES.keys()) + list(collector.custom_fonts.keys())
|
752 |
font_select.update(choices=font_choices)
|
753 |
-
# Rebuild CSS to include new font
|
754 |
-
font_face_css = ""
|
755 |
-
for font_style, font_info in FONT_STYLES.items():
|
756 |
-
if font_style in collector.custom_fonts:
|
757 |
-
font_file_name = font_info['family'] + '.ttf'
|
758 |
-
font_path = collector.fonts_path / font_file_name
|
759 |
-
if os.path.exists(font_path):
|
760 |
-
font_face_css += f"""
|
761 |
-
@font-face {{
|
762 |
-
font-family: '{font_info["family"]}';
|
763 |
-
src: url('file/{font_path}') format('truetype');
|
764 |
-
}}
|
765 |
-
"""
|
766 |
-
# Update the interface CSS
|
767 |
-
interface.set_css(custom_css + font_face_css)
|
768 |
return {status: f"✅ {msg}"}
|
769 |
|
770 |
# Event handlers
|
|
|
42 |
},
|
43 |
"nastaliq": {
|
44 |
"name": "Nastaliq",
|
45 |
+
"family": "Noto Nastaliq Urdu",
|
46 |
+
"css": "font-family: 'Noto Nastaliq Urdu', serif;"
|
47 |
},
|
48 |
"naskh": {
|
49 |
"name": "Naskh",
|
50 |
+
"family": "Scheherazade New",
|
51 |
+
"css": "font-family: 'Scheherazade New', serif;"
|
52 |
}
|
53 |
}
|
54 |
|
|
|
216 |
font_filename = font_family + '.ttf'
|
217 |
font_dest = self.fonts_path / font_filename
|
218 |
|
219 |
+
# Read the font file content
|
220 |
+
font_file.seek(0)
|
221 |
+
font_content = font_file.read()
|
222 |
+
|
223 |
# Save the font file
|
224 |
with open(font_dest, 'wb') as f:
|
225 |
+
f.write(font_content)
|
226 |
|
227 |
# Add to custom fonts
|
228 |
self.custom_fonts[font_family] = {
|
|
|
520 |
}
|
521 |
"""
|
522 |
|
523 |
+
# Include Google Fonts for Nastaliq and Naskh
|
524 |
+
google_fonts_css = """
|
525 |
+
@import url('https://fonts.googleapis.com/earlyaccess/notonastaliqurdu.css');
|
526 |
+
@import url('https://fonts.googleapis.com/css2?family=Scheherazade+New&display=swap');
|
527 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
528 |
|
529 |
+
custom_css = google_fonts_css + custom_css
|
530 |
|
531 |
with gr.Blocks(title="TTS Dataset Collection Tool", css=custom_css) as interface:
|
532 |
+
gr.Markdown("# TTS Dataset Collection Tool")
|
533 |
+
|
534 |
status = gr.Textbox(
|
535 |
label="Status",
|
536 |
interactive=False,
|
537 |
+
max_lines=3,
|
538 |
+
elem_classes=["small-input"]
|
539 |
)
|
540 |
|
|
|
|
|
541 |
with gr.Row():
|
542 |
# Left column - Configuration and Input
|
543 |
with gr.Column(scale=1):
|
|
|
545 |
label="Paste Text",
|
546 |
placeholder="Paste your text here...",
|
547 |
lines=5,
|
548 |
+
elem_classes=["small-input"],
|
549 |
+
interactive=True
|
550 |
)
|
551 |
file_input = gr.File(
|
552 |
label="Or Upload Text File (.txt)",
|
|
|
564 |
elem_classes=["small-input"]
|
565 |
)
|
566 |
font_select = gr.Dropdown(
|
567 |
+
choices=list(FONT_STYLES.keys()),
|
568 |
value="english_serif",
|
569 |
label="Select Font Style",
|
570 |
elem_classes=["small-input"]
|
571 |
)
|
572 |
# Custom font upload
|
573 |
+
with gr.Accordion("Custom Font Upload", open=False):
|
574 |
+
font_file_input = gr.File(
|
575 |
+
label="Upload Custom Font (.ttf)",
|
576 |
+
file_types=[".ttf"],
|
577 |
+
elem_classes=["small-input"],
|
578 |
+
type="file" # Ensure we get a file-like object
|
579 |
+
)
|
580 |
+
add_font_btn = gr.Button("Add Custom Font")
|
581 |
|
582 |
# Dataset Info
|
583 |
with gr.Accordion("Dataset Statistics", open=False):
|
|
|
748 |
# Update font dropdown
|
749 |
font_choices = list(FONT_STYLES.keys()) + list(collector.custom_fonts.keys())
|
750 |
font_select.update(choices=font_choices)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
751 |
return {status: f"✅ {msg}"}
|
752 |
|
753 |
# Event handlers
|