Spaces:
Sleeping
Sleeping
Commit
·
3a16696
1
Parent(s):
f2fd281
Fix: Upgrade to Gradio 4.44.1 to fix file upload compatibility
Browse files
app.py
CHANGED
|
@@ -69,16 +69,14 @@ def upload_file_analysis(file, api_url, progress=gr.Progress()):
|
|
| 69 |
progress(0, desc="Reading file...")
|
| 70 |
|
| 71 |
try:
|
| 72 |
-
#
|
| 73 |
-
if
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
file_content = file.decode('utf-8') if isinstance(file, bytes) else file
|
| 81 |
-
filename = "uploaded_file.txt"
|
| 82 |
|
| 83 |
progress(0.3, desc="Sending file to API...")
|
| 84 |
|
|
@@ -115,9 +113,11 @@ def upload_file_analysis(file, api_url, progress=gr.Progress()):
|
|
| 115 |
return f"❌ **Request Error**\n\n{str(e)}"
|
| 116 |
except UnicodeDecodeError:
|
| 117 |
return "❌ **File Encoding Error**\n\nPlease ensure the file is a valid TXT file with UTF-8 encoding."
|
|
|
|
|
|
|
| 118 |
except Exception as e:
|
| 119 |
return f"❌ **Unexpected Error**\n\n{str(e)}"
|
| 120 |
-
|
| 121 |
def format_file_upload_response(result):
|
| 122 |
"""Format file upload response"""
|
| 123 |
output = "---\n\n"
|
|
@@ -278,8 +278,8 @@ with gr.Blocks(css=load_css(), theme=gr.themes.Soft(), title="Medical Coding (IC
|
|
| 278 |
|
| 279 |
file_upload = gr.File(
|
| 280 |
label="Upload TXT File",
|
|
|
|
| 281 |
file_types=[".txt"],
|
| 282 |
-
type="filepath",
|
| 283 |
elem_classes="file-upload"
|
| 284 |
)
|
| 285 |
|
|
|
|
| 69 |
progress(0, desc="Reading file...")
|
| 70 |
|
| 71 |
try:
|
| 72 |
+
# Gradio 4.44+ returns file path as string
|
| 73 |
+
file_path = file.name if hasattr(file, 'name') else file
|
| 74 |
+
|
| 75 |
+
# Read file content
|
| 76 |
+
with open(file_path, 'r', encoding='utf-8') as f:
|
| 77 |
+
file_content = f.read()
|
| 78 |
+
|
| 79 |
+
filename = os.path.basename(file_path)
|
|
|
|
|
|
|
| 80 |
|
| 81 |
progress(0.3, desc="Sending file to API...")
|
| 82 |
|
|
|
|
| 113 |
return f"❌ **Request Error**\n\n{str(e)}"
|
| 114 |
except UnicodeDecodeError:
|
| 115 |
return "❌ **File Encoding Error**\n\nPlease ensure the file is a valid TXT file with UTF-8 encoding."
|
| 116 |
+
except FileNotFoundError:
|
| 117 |
+
return "❌ **File Not Found**\n\nThe uploaded file could not be found. Please try again."
|
| 118 |
except Exception as e:
|
| 119 |
return f"❌ **Unexpected Error**\n\n{str(e)}"
|
| 120 |
+
|
| 121 |
def format_file_upload_response(result):
|
| 122 |
"""Format file upload response"""
|
| 123 |
output = "---\n\n"
|
|
|
|
| 278 |
|
| 279 |
file_upload = gr.File(
|
| 280 |
label="Upload TXT File",
|
| 281 |
+
file_count="single",
|
| 282 |
file_types=[".txt"],
|
|
|
|
| 283 |
elem_classes="file-upload"
|
| 284 |
)
|
| 285 |
|