Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,42 +21,33 @@ def process_with_markitdown(input_path):
|
|
| 21 |
return f"Error processing input: {str(e)}"
|
| 22 |
|
| 23 |
def save_uploaded_file(file_data):
|
| 24 |
-
"""Saves a file uploaded with gardio to a temporary location.
|
| 25 |
-
|
| 26 |
-
Args:
|
| 27 |
-
file_data: The file data object returned by gardio.get_file().
|
| 28 |
-
|
| 29 |
-
Returns:
|
| 30 |
-
The path to the saved file, or an error message as a string.
|
| 31 |
-
"""
|
| 32 |
|
| 33 |
if file_data is None:
|
| 34 |
return "No file uploaded."
|
| 35 |
-
|
| 36 |
try:
|
| 37 |
-
#
|
| 38 |
-
|
|
|
|
|
|
|
| 39 |
temp_dir = tempfile.gettempdir()
|
| 40 |
-
temp_filename = tempfile.mkstemp(dir=temp_dir, suffix=os.path.splitext(filename)[1])[1]
|
| 41 |
|
| 42 |
with open(temp_filename, 'wb') as f:
|
| 43 |
try:
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
f.write(
|
| 49 |
-
else:
|
| 50 |
-
return "Error: Unsupported file-like object."
|
| 51 |
-
|
| 52 |
except Exception as e:
|
| 53 |
return f"Error writing to file: {str(e)}"
|
| 54 |
|
| 55 |
return temp_filename
|
| 56 |
-
|
| 57 |
except Exception as e:
|
| 58 |
-
return f"An error occurred during file saving: {str(e)}"
|
| 59 |
-
|
| 60 |
async def summarize_text(text):
|
| 61 |
"""Summarize the input text using Gemini AI"""
|
| 62 |
try:
|
|
|
|
| 21 |
return f"Error processing input: {str(e)}"
|
| 22 |
|
| 23 |
def save_uploaded_file(file_data):
|
| 24 |
+
"""Saves a file uploaded with gardio to a temporary location."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
if file_data is None:
|
| 27 |
return "No file uploaded."
|
| 28 |
+
|
| 29 |
try:
|
| 30 |
+
# Critical: Directly access the file data, not filename
|
| 31 |
+
if not hasattr(file_data, 'read'):
|
| 32 |
+
return "Error: File data object doesn't have a read method."
|
| 33 |
+
|
| 34 |
temp_dir = tempfile.gettempdir()
|
| 35 |
+
temp_filename = tempfile.mkstemp(dir=temp_dir, suffix=os.path.splitext(file_data.filename)[1])[1] # Use the filename
|
| 36 |
|
| 37 |
with open(temp_filename, 'wb') as f:
|
| 38 |
try:
|
| 39 |
+
while True:
|
| 40 |
+
chunk = file_data.read(8192) # Crucial: Chunk for potential large files
|
| 41 |
+
if not chunk:
|
| 42 |
+
break
|
| 43 |
+
f.write(chunk)
|
|
|
|
|
|
|
|
|
|
| 44 |
except Exception as e:
|
| 45 |
return f"Error writing to file: {str(e)}"
|
| 46 |
|
| 47 |
return temp_filename
|
|
|
|
| 48 |
except Exception as e:
|
| 49 |
+
return f"An error occurred during file saving: {str(e)}"
|
| 50 |
+
|
| 51 |
async def summarize_text(text):
|
| 52 |
"""Summarize the input text using Gemini AI"""
|
| 53 |
try:
|