Spaces:
Sleeping
Sleeping
Commit
·
3cc4808
1
Parent(s):
849cb9d
Implement first POC
Browse files
app.py
CHANGED
@@ -15,6 +15,7 @@ from utils import blob_service_client, upload_to_azure, download_from_azure, del
|
|
15 |
load_dotenv()
|
16 |
|
17 |
# Streamlit UI
|
|
|
18 |
st.title("Azure Translation Tools")
|
19 |
uploaded_files = st.file_uploader("Upload files to start the process", accept_multiple_files=True)
|
20 |
|
@@ -109,11 +110,12 @@ if uploaded_files and submit:
|
|
109 |
|
110 |
file_name = uploaded_file.name
|
111 |
file_content = uploaded_file.read()
|
|
|
112 |
|
113 |
# Check file extension to determine translation method
|
114 |
-
if
|
115 |
result, response = process_sync(file_name, file_content)
|
116 |
-
elif
|
117 |
result, response = process_async(file_name, file_content)
|
118 |
|
119 |
# Calculate duration
|
@@ -127,14 +129,28 @@ if uploaded_files and submit:
|
|
127 |
else:
|
128 |
st.error(f"Failed to translate {uploaded_file.name} with status code {response.status_code}: {response.text} (Time taken: {duration:.2f} seconds)")
|
129 |
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
138 |
|
139 |
# Update progress bar based on completed translations
|
140 |
progress = (idx + 1) / len(uploaded_files)
|
|
|
15 |
load_dotenv()
|
16 |
|
17 |
# Streamlit UI
|
18 |
+
st.set_page_config(layout="wide")
|
19 |
st.title("Azure Translation Tools")
|
20 |
uploaded_files = st.file_uploader("Upload files to start the process", accept_multiple_files=True)
|
21 |
|
|
|
110 |
|
111 |
file_name = uploaded_file.name
|
112 |
file_content = uploaded_file.read()
|
113 |
+
file_type = file_name.split('.')[-1]
|
114 |
|
115 |
# Check file extension to determine translation method
|
116 |
+
if file_type in ['txt', 'tsv', 'tab', 'csv', 'html', 'htm', 'mthml', 'mht', 'pptx', 'xlsx', 'docx', 'msg', 'xlf', 'xliff']:
|
117 |
result, response = process_sync(file_name, file_content)
|
118 |
+
elif file_type in ['pdf', 'odt', 'odp', 'ods', 'rtf']:
|
119 |
result, response = process_async(file_name, file_content)
|
120 |
|
121 |
# Calculate duration
|
|
|
129 |
else:
|
130 |
st.error(f"Failed to translate {uploaded_file.name} with status code {response.status_code}: {response.text} (Time taken: {duration:.2f} seconds)")
|
131 |
|
132 |
+
if file_type == 'pdf':
|
133 |
+
# Display the original and translated files side by side
|
134 |
+
col1, col2 = st.columns(2)
|
135 |
+
with col1:
|
136 |
+
st.write(f"Original File: {uploaded_file.name}")
|
137 |
+
pdf_viewer(file_content)
|
138 |
+
with col2:
|
139 |
+
st.write(f"Translated File: {lang_name}-translated-{uploaded_file.name}")
|
140 |
+
pdf_viewer(response)
|
141 |
+
elif file_type == 'docx':
|
142 |
+
pass
|
143 |
+
elif file_type == 'txt':
|
144 |
+
# Display the original and translated files side by side
|
145 |
+
col1, col2 = st.columns(2)
|
146 |
+
with col1:
|
147 |
+
st.write(f"Original File: {uploaded_file.name}")
|
148 |
+
st.divider()
|
149 |
+
st.write(file_content)
|
150 |
+
with col2:
|
151 |
+
st.write(f"Translated File: {lang_name}-translated-{uploaded_file.name}")
|
152 |
+
st.divider()
|
153 |
+
st.write(response)
|
154 |
|
155 |
# Update progress bar based on completed translations
|
156 |
progress = (idx + 1) / len(uploaded_files)
|