Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -27,26 +27,27 @@ def save_uploaded_file(file_data):
|
|
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 |
-
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
while True:
|
40 |
-
chunk = file_data.read(8192) # Crucial: Chunk
|
41 |
if not chunk:
|
42 |
break
|
43 |
f.write(chunk)
|
44 |
-
|
45 |
-
|
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"""
|
|
|
27 |
return "No file uploaded."
|
28 |
|
29 |
try:
|
|
|
|
|
|
|
|
|
30 |
temp_dir = tempfile.gettempdir()
|
|
|
31 |
|
32 |
+
# Critical: Handle the different types from gardio
|
33 |
+
if hasattr(file_data, 'filename') and hasattr(file_data, 'content'):
|
34 |
+
temp_filename = tempfile.mkstemp(dir=temp_dir, suffix=os.path.splitext(file_data.filename)[1])[1]
|
35 |
+
with open(temp_filename, 'wb') as f:
|
36 |
+
f.write(file_data.content)
|
37 |
+
return temp_filename
|
38 |
+
elif hasattr(file_data, 'read'):
|
39 |
+
temp_filename = tempfile.mkstemp(dir=temp_dir, suffix=os.path.splitext(file_data.filename)[1])[1] if hasattr(file_data, 'filename') else tempfile.mkstemp(dir=temp_dir)
|
40 |
+
with open(temp_filename, 'wb') as f:
|
41 |
while True:
|
42 |
+
chunk = file_data.read(8192) # Crucial: Chunk
|
43 |
if not chunk:
|
44 |
break
|
45 |
f.write(chunk)
|
46 |
+
return temp_filename
|
47 |
+
else:
|
48 |
+
return "Error: Invalid file data object."
|
|
|
49 |
except Exception as e:
|
50 |
+
return f"An error occurred during file saving: {str(e)}"
|
51 |
|
52 |
async def summarize_text(text):
|
53 |
"""Summarize the input text using Gemini AI"""
|