fadliaulawi commited on
Commit
c52dbb5
·
1 Parent(s): 6ce9ced

Add time tracking

Browse files
Files changed (1) hide show
  1. app.py +8 -2
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import io
2
  import os
 
3
  import streamlit as st
4
  import requests
5
  import zipfile
@@ -100,6 +101,8 @@ if uploaded_files and submit:
100
  # Add progress bar for translation status
101
  progress_bar = st.progress(0)
102
  for idx, uploaded_file in enumerate(uploaded_files):
 
 
103
 
104
  # Check file extension to determine translation method
105
  if uploaded_file.name.split('.')[-1] in ['txt', 'tsv', 'tab', 'csv', 'html', 'htm', 'mthml', 'mht', 'pptx', 'xlsx', 'docx', 'msg', 'xlf', 'xliff']:
@@ -107,13 +110,16 @@ if uploaded_files and submit:
107
  elif uploaded_file.name.split('.')[-1] in ['pdf', 'odt', 'odp', 'ods', 'rtf']:
108
  result, response = process_async(uploaded_file)
109
 
 
 
 
110
  # Check if translation was successful
111
  if result:
112
  # Add successfully translated file to zip archive
113
  zip_file.writestr(f"{lang_name}-translated-{uploaded_file.name}", response)
114
- st.success(f"Successfully translated: {uploaded_file.name}")
115
  else:
116
- st.error(f"Failed to translate {uploaded_file.name} with status code {response.status_code}: {response.text}")
117
 
118
  # Update progress bar based on completed translations
119
  progress = (idx + 1) / len(uploaded_files)
 
1
  import io
2
  import os
3
+ import time
4
  import streamlit as st
5
  import requests
6
  import zipfile
 
101
  # Add progress bar for translation status
102
  progress_bar = st.progress(0)
103
  for idx, uploaded_file in enumerate(uploaded_files):
104
+ # Start timing
105
+ start_time = time.time()
106
 
107
  # Check file extension to determine translation method
108
  if uploaded_file.name.split('.')[-1] in ['txt', 'tsv', 'tab', 'csv', 'html', 'htm', 'mthml', 'mht', 'pptx', 'xlsx', 'docx', 'msg', 'xlf', 'xliff']:
 
110
  elif uploaded_file.name.split('.')[-1] in ['pdf', 'odt', 'odp', 'ods', 'rtf']:
111
  result, response = process_async(uploaded_file)
112
 
113
+ # Calculate duration
114
+ duration = time.time() - start_time
115
+
116
  # Check if translation was successful
117
  if result:
118
  # Add successfully translated file to zip archive
119
  zip_file.writestr(f"{lang_name}-translated-{uploaded_file.name}", response)
120
+ st.success(f"Successfully translated: {uploaded_file.name} (Time taken: {duration:.2f} seconds)")
121
  else:
122
+ st.error(f"Failed to translate {uploaded_file.name} with status code {response.status_code}: {response.text} (Time taken: {duration:.2f} seconds)")
123
 
124
  # Update progress bar based on completed translations
125
  progress = (idx + 1) / len(uploaded_files)