fix building
Browse files- app.py +6 -6
- csv_processor.py +47 -0
app.py
CHANGED
|
@@ -51,11 +51,11 @@ logger = logging.getLogger(__name__)
|
|
| 51 |
|
| 52 |
# Prepare language options for Dropdown
|
| 53 |
language_options = [f"{k} ({v})" for k, v in ASR_LANGUAGES.items()]
|
| 54 |
-
bam_index = 0
|
| 55 |
-
try:
|
| 56 |
-
|
| 57 |
-
except ValueError:
|
| 58 |
-
|
| 59 |
|
| 60 |
|
| 61 |
mms_transcribe = gr.Interface(
|
|
@@ -65,7 +65,7 @@ mms_transcribe = gr.Interface(
|
|
| 65 |
gr.Dropdown(
|
| 66 |
choices=language_options,
|
| 67 |
label="Language",
|
| 68 |
-
value=language_options[
|
| 69 |
),
|
| 70 |
gr.Textbox(label="Optional: Provide your own transcription"),
|
| 71 |
],
|
|
|
|
| 51 |
|
| 52 |
# Prepare language options for Dropdown
|
| 53 |
language_options = [f"{k} ({v})" for k, v in ASR_LANGUAGES.items()]
|
| 54 |
+
# bam_index = 0
|
| 55 |
+
# try:
|
| 56 |
+
# bam_index = language_options.index("bam")
|
| 57 |
+
# except ValueError:
|
| 58 |
+
# bam_index = 0
|
| 59 |
|
| 60 |
|
| 61 |
mms_transcribe = gr.Interface(
|
|
|
|
| 65 |
gr.Dropdown(
|
| 66 |
choices=language_options,
|
| 67 |
label="Language",
|
| 68 |
+
value=language_options[0] if language_options else None,
|
| 69 |
),
|
| 70 |
gr.Textbox(label="Optional: Provide your own transcription"),
|
| 71 |
],
|
csv_processor.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import hashlib
|
| 2 |
+
import csv
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def hash_md5(filepath):
|
| 6 |
+
md5_hash = hashlib.md5()
|
| 7 |
+
try:
|
| 8 |
+
with open(filepath, "rb") as file:
|
| 9 |
+
for chunk in iter(lambda: file.read(128 * md5_hash.block_size), b''):
|
| 10 |
+
md5_hash.update(chunk)
|
| 11 |
+
return md5_hash.hexdigest()
|
| 12 |
+
except Exception as e:
|
| 13 |
+
return str(e)
|
| 14 |
+
|
| 15 |
+
import csv
|
| 16 |
+
|
| 17 |
+
def update_csv(file_path, search_hash, new_path, new_transcription):
|
| 18 |
+
# Use read/write mode to modify the relevant line or append if not found
|
| 19 |
+
with open(file_path, mode='r+', newline='', encoding='utf-8') as file:
|
| 20 |
+
reader = csv.DictReader(file)
|
| 21 |
+
fieldnames = reader.fieldnames
|
| 22 |
+
rows = list(reader)
|
| 23 |
+
found = False
|
| 24 |
+
|
| 25 |
+
# Locate the row with the matching hash
|
| 26 |
+
for i, row in enumerate(rows):
|
| 27 |
+
if row['hash'] == search_hash:
|
| 28 |
+
rows[i]['filepath'] = new_path
|
| 29 |
+
rows[i]['transcription'] = new_transcription
|
| 30 |
+
found = True
|
| 31 |
+
break
|
| 32 |
+
|
| 33 |
+
if found:
|
| 34 |
+
# Move file pointer to the beginning and write only the updated row
|
| 35 |
+
file.seek(0) # Go to the beginning of the file
|
| 36 |
+
writer = csv.DictWriter(file, fieldnames=fieldnames)
|
| 37 |
+
writer.writeheader() # Ensure the header is written
|
| 38 |
+
writer.writerows(rows) # Write all rows back, with the updated one
|
| 39 |
+
return
|
| 40 |
+
# Append a new row if the hash is not found
|
| 41 |
+
with open(file_path, mode='a', newline='', encoding='utf-8') as append_file:
|
| 42 |
+
writer = csv.DictWriter(append_file, fieldnames=fieldnames)
|
| 43 |
+
writer.writerow({
|
| 44 |
+
'hash': search_hash,
|
| 45 |
+
'filepath': new_path,
|
| 46 |
+
'transcription': new_transcription
|
| 47 |
+
})
|