Update app.py
Browse files
app.py
CHANGED
@@ -58,7 +58,6 @@ def unzip_and_find_jpgs(file_path):
|
|
58 |
|
59 |
def process_images(uploaded_file):
|
60 |
global results_df
|
61 |
-
# Check if a file is actually uploaded
|
62 |
if uploaded_file is None:
|
63 |
results_df = pd.DataFrame(columns=["Filename", "Extracted Text", "Translated Text"]) # Clear DataFrame
|
64 |
return "", "" # Return empty outputs if no file is uploaded
|
@@ -66,7 +65,7 @@ def process_images(uploaded_file):
|
|
66 |
# Reinitialize the DataFrame every time a new file is uploaded
|
67 |
results_df = pd.DataFrame(columns=["Filename", "Extracted Text", "Translated Text"])
|
68 |
|
69 |
-
file_path = uploaded_file.name
|
70 |
try:
|
71 |
image_files = unzip_and_find_jpgs(file_path)
|
72 |
if not image_files:
|
@@ -84,13 +83,10 @@ def process_images(uploaded_file):
|
|
84 |
return f"An error occurred: {str(e)}", ""
|
85 |
|
86 |
html_output = results_df.to_html()
|
87 |
-
temp_file = tempfile.NamedTemporaryFile(delete=
|
88 |
results_df.to_csv(temp_file.name, index=False)
|
89 |
-
|
90 |
-
temp_file.
|
91 |
-
|
92 |
-
return html_output, temp_file_path
|
93 |
-
|
94 |
|
95 |
with gr.Blocks() as interface:
|
96 |
with gr.Row():
|
|
|
58 |
|
59 |
def process_images(uploaded_file):
|
60 |
global results_df
|
|
|
61 |
if uploaded_file is None:
|
62 |
results_df = pd.DataFrame(columns=["Filename", "Extracted Text", "Translated Text"]) # Clear DataFrame
|
63 |
return "", "" # Return empty outputs if no file is uploaded
|
|
|
65 |
# Reinitialize the DataFrame every time a new file is uploaded
|
66 |
results_df = pd.DataFrame(columns=["Filename", "Extracted Text", "Translated Text"])
|
67 |
|
68 |
+
file_path = uploaded_file.name
|
69 |
try:
|
70 |
image_files = unzip_and_find_jpgs(file_path)
|
71 |
if not image_files:
|
|
|
83 |
return f"An error occurred: {str(e)}", ""
|
84 |
|
85 |
html_output = results_df.to_html()
|
86 |
+
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".csv")
|
87 |
results_df.to_csv(temp_file.name, index=False)
|
88 |
+
temp_file.close() # File is closed but not deleted
|
89 |
+
return html_output, temp_file.name
|
|
|
|
|
|
|
90 |
|
91 |
with gr.Blocks() as interface:
|
92 |
with gr.Row():
|