Spaces:
Sleeping
Sleeping
Commit
·
5563747
1
Parent(s):
cfd9f30
DATA BYTES CONVESRION FOR GRADIO
Browse files
app.py
CHANGED
@@ -816,12 +816,30 @@ def create_output_file(df, uploaded_file):
|
|
816 |
|
817 |
|
818 |
@spaces.GPU(duration=90)
|
819 |
-
def process_and_download(
|
820 |
"""Synchronous wrapper for async processing"""
|
821 |
-
|
|
|
822 |
gr.Warning("Пожалуйста, загрузите файл")
|
823 |
return pd.DataFrame(), None, None, None, "Ожидание файла...", ""
|
824 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
825 |
if control is None:
|
826 |
control = ProcessControl()
|
827 |
|
|
|
816 |
|
817 |
|
818 |
@spaces.GPU(duration=90)
|
819 |
+
def process_and_download(file_input, control=None):
|
820 |
"""Synchronous wrapper for async processing"""
|
821 |
+
# Handle different file input types
|
822 |
+
if file_input is None:
|
823 |
gr.Warning("Пожалуйста, загрузите файл")
|
824 |
return pd.DataFrame(), None, None, None, "Ожидание файла...", ""
|
825 |
|
826 |
+
# Convert file input to bytes
|
827 |
+
try:
|
828 |
+
if hasattr(file_input, 'name'): # Gradio 4+ NamedString object
|
829 |
+
file_bytes = file_input.read() # Get bytes directly
|
830 |
+
elif isinstance(file_input, (str, bytes)):
|
831 |
+
# Either bytes or file path
|
832 |
+
if isinstance(file_input, str):
|
833 |
+
with open(file_input, 'rb') as f:
|
834 |
+
file_bytes = f.read()
|
835 |
+
else:
|
836 |
+
file_bytes = file_input
|
837 |
+
else:
|
838 |
+
raise ValueError(f"Unexpected file input type: {type(file_input)}")
|
839 |
+
except Exception as e:
|
840 |
+
gr.Warning(f"Ошибка чтения файла: {str(e)}")
|
841 |
+
return pd.DataFrame(), None, None, None, f"Ошибка чтения файла: {str(e)}", ""
|
842 |
+
|
843 |
if control is None:
|
844 |
control = ProcessControl()
|
845 |
|