Added the function for inputting tier name. Updated the guidance related to tier name.

#3
by ylmmhf - opened
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -12,7 +12,7 @@ import re
12
  def create_interval_data_dict(xmin, xmax, sentence):
13
  return {'xmin': float(xmin), 'xmax': float(xmax), 'text': sentence}
14
 
15
- def write_textgrid_file(intervals, output_file_path, total_xmax):
16
  with open(output_file_path, 'w') as f:
17
  f.write('File type = "ooTextFile"\n')
18
  f.write('Object class = "TextGrid"\n\n')
@@ -23,7 +23,7 @@ def write_textgrid_file(intervals, output_file_path, total_xmax):
23
  f.write('item []:\n')
24
  f.write(' item [1]:\n')
25
  f.write(' class = "IntervalTier"\n')
26
- f.write(' name = "Intonational Unit"\n')
27
  f.write(' xmin = 0\n')
28
  f.write(f' xmax = {str(float(total_xmax))}\n')
29
  f.write(f' intervals: size = {len(intervals) + 1}\n')
@@ -150,7 +150,7 @@ def csv_to_textgrid(file):
150
 
151
  if intervals:
152
  textgrid_path = os.path.join(output_directory, f"{prev_filename}.TextGrid")
153
- write_textgrid_file(intervals, textgrid_path, intervals[-1]['xmax'])
154
  processed_files.append(prev_filename)
155
  print(f"Wrote file: {prev_filename}.TextGrid with {len(intervals)} intervals")
156
 
@@ -182,7 +182,7 @@ def csv_to_textgrid(file):
182
 
183
  if intervals:
184
  textgrid_path = os.path.join(output_directory, f"{prev_filename}.TextGrid")
185
- write_textgrid_file(intervals, textgrid_path, intervals[-1]['xmax'])
186
  processed_files.append(prev_filename)
187
  print(f"Wrote last file: {prev_filename}.TextGrid with {len(intervals)} intervals")
188
 
@@ -221,6 +221,8 @@ Each row represents a word or segment in an audio file.
221
  - `text`: The actual spoken word or phrase.
222
  - `is_unit_start_pred`: Marks the beginning of a new unit (TRUE/FALSE).
223
 
 
 
224
  Example:\n
225
  | file_name | xmin | xmax | text | is_unit_start_pred |
226
  |-----------|--------|--------|-------|---------------------|
@@ -232,7 +234,10 @@ Example:\n
232
 
233
  iface = gr.Interface(
234
  fn=csv_to_textgrid,
235
- inputs=gr.File(label="πŸ“ Upload CSV File", file_types=[".csv"]),
 
 
 
236
  outputs=[
237
  gr.File(label="πŸ“¦ Download TextGrid ZIP"),
238
  gr.Textbox(label="βœ… Status")
 
12
  def create_interval_data_dict(xmin, xmax, sentence):
13
  return {'xmin': float(xmin), 'xmax': float(xmax), 'text': sentence}
14
 
15
+ def write_textgrid_file(intervals, output_file_path, total_xmax, tier_name):
16
  with open(output_file_path, 'w') as f:
17
  f.write('File type = "ooTextFile"\n')
18
  f.write('Object class = "TextGrid"\n\n')
 
23
  f.write('item []:\n')
24
  f.write(' item [1]:\n')
25
  f.write(' class = "IntervalTier"\n')
26
+ f.write(f' name = "{tier_name}"\n')
27
  f.write(' xmin = 0\n')
28
  f.write(f' xmax = {str(float(total_xmax))}\n')
29
  f.write(f' intervals: size = {len(intervals) + 1}\n')
 
150
 
151
  if intervals:
152
  textgrid_path = os.path.join(output_directory, f"{prev_filename}.TextGrid")
153
+ write_textgrid_file(intervals, textgrid_path, intervals[-1]['xmax'], tier_name)
154
  processed_files.append(prev_filename)
155
  print(f"Wrote file: {prev_filename}.TextGrid with {len(intervals)} intervals")
156
 
 
182
 
183
  if intervals:
184
  textgrid_path = os.path.join(output_directory, f"{prev_filename}.TextGrid")
185
+ write_textgrid_file(intervals, textgrid_path, intervals[-1]['xmax'], tier_name)
186
  processed_files.append(prev_filename)
187
  print(f"Wrote last file: {prev_filename}.TextGrid with {len(intervals)} intervals")
188
 
 
221
  - `text`: The actual spoken word or phrase.
222
  - `is_unit_start_pred`: Marks the beginning of a new unit (TRUE/FALSE).
223
 
224
+ **Please enter the tier name according to your preference or as deemed appropriate for the data.**
225
+
226
  Example:\n
227
  | file_name | xmin | xmax | text | is_unit_start_pred |
228
  |-----------|--------|--------|-------|---------------------|
 
234
 
235
  iface = gr.Interface(
236
  fn=csv_to_textgrid,
237
+ inputs=[
238
+ gr.File(label="πŸ“ Upload CSV File", file_types=[".csv"]),
239
+ gr.Textbox(label="πŸ“ Enter Tier Name", placeholder="Enter the name of the tier") # New input for tier name
240
+ ],
241
  outputs=[
242
  gr.File(label="πŸ“¦ Download TextGrid ZIP"),
243
  gr.Textbox(label="βœ… Status")