Spaces:
Runtime error
Runtime error
Boghdady9
commited on
Commit
Β·
698e958
1
Parent(s):
bd04035
Fix Gradio compatibility issues
Browse filesπ§ FIXES:
- Upgrade gradio 4.16.0 β 4.44.1 (latest stable)
- Replace gr.Date with gr.Textbox for date inputs
- Fix matplotlib permission error with MPLCONFIGDIR
- Improve image handling for different input types
- Add proper date format placeholders (YYYY-MM-DD)
β
RESOLVED ERRORS:
- AttributeError: module 'gradio' has no attribute 'Date'
- Permission denied: /.config/matplotlib
- Better image upload compatibility
π― IMPROVEMENTS:
- More robust date handling with text input
- Cleaner error messages for unsupported formats
- Better Docker environment setup
- Dockerfile +5 -2
- requirements.txt +1 -1
- src/gradio_app.py +21 -8
Dockerfile
CHANGED
|
@@ -11,11 +11,14 @@ COPY src/ .
|
|
| 11 |
|
| 12 |
# Create necessary directories with proper permissions
|
| 13 |
RUN mkdir -p /app/pdf_reports && \
|
| 14 |
-
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
# Set environment variables for Gradio
|
| 17 |
ENV GRADIO_SERVER_PORT=7860
|
| 18 |
ENV GRADIO_SERVER_NAME=0.0.0.0
|
|
|
|
| 19 |
|
| 20 |
# Expose both ports (8001 for backend, 7860 for frontend)
|
| 21 |
EXPOSE 8001 7860
|
|
|
|
| 11 |
|
| 12 |
# Create necessary directories with proper permissions
|
| 13 |
RUN mkdir -p /app/pdf_reports && \
|
| 14 |
+
mkdir -p /tmp/matplotlib && \
|
| 15 |
+
chmod -R 755 /app && \
|
| 16 |
+
chmod -R 777 /tmp/matplotlib
|
| 17 |
|
| 18 |
+
# Set environment variables for Gradio and Matplotlib
|
| 19 |
ENV GRADIO_SERVER_PORT=7860
|
| 20 |
ENV GRADIO_SERVER_NAME=0.0.0.0
|
| 21 |
+
ENV MPLCONFIGDIR=/tmp/matplotlib
|
| 22 |
|
| 23 |
# Expose both ports (8001 for backend, 7860 for frontend)
|
| 24 |
EXPOSE 8001 7860
|
requirements.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
altair
|
| 2 |
pandas
|
| 3 |
-
gradio==4.
|
| 4 |
fastapi==0.104.1
|
| 5 |
uvicorn==0.24.0
|
| 6 |
python-multipart==0.0.6
|
|
|
|
| 1 |
altair
|
| 2 |
pandas
|
| 3 |
+
gradio==4.44.1
|
| 4 |
fastapi==0.104.1
|
| 5 |
uvicorn==0.24.0
|
| 6 |
python-multipart==0.0.6
|
src/gradio_app.py
CHANGED
|
@@ -189,16 +189,25 @@ def analyze_medical_image(image, patient_name, date_of_birth, gender, medical_re
|
|
| 189 |
return "β Please fill in all required patient information", "", "", "", ""
|
| 190 |
|
| 191 |
try:
|
| 192 |
-
#
|
| 193 |
if isinstance(image, str): # If it's a file path
|
| 194 |
with open(image, 'rb') as f:
|
| 195 |
image_bytes = f.read()
|
| 196 |
filename = os.path.basename(image)
|
| 197 |
-
else:
|
| 198 |
-
|
| 199 |
-
image
|
| 200 |
-
|
| 201 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
|
| 203 |
# Send to backend for analysis
|
| 204 |
files = {"file": (filename, image_bytes, "image/jpeg")}
|
|
@@ -362,7 +371,7 @@ def create_medivision_app():
|
|
| 362 |
patient_name = gr.Textbox(label="Patient Name *", placeholder="Enter full name")
|
| 363 |
|
| 364 |
with gr.Row():
|
| 365 |
-
date_of_birth = gr.
|
| 366 |
gender = gr.Dropdown(
|
| 367 |
choices=["Male", "Female", "Other"],
|
| 368 |
label="Gender *",
|
|
@@ -377,7 +386,11 @@ def create_medivision_app():
|
|
| 377 |
generate_mrn_btn = gr.Button("π― Generate MRN", variant="secondary")
|
| 378 |
|
| 379 |
referring_physician = gr.Textbox(label="Referring Physician *", placeholder="Dr. Name")
|
| 380 |
-
study_date = gr.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 381 |
|
| 382 |
# MRN Generation
|
| 383 |
generate_mrn_btn.click(
|
|
|
|
| 189 |
return "β Please fill in all required patient information", "", "", "", ""
|
| 190 |
|
| 191 |
try:
|
| 192 |
+
# Handle image file
|
| 193 |
if isinstance(image, str): # If it's a file path
|
| 194 |
with open(image, 'rb') as f:
|
| 195 |
image_bytes = f.read()
|
| 196 |
filename = os.path.basename(image)
|
| 197 |
+
else:
|
| 198 |
+
# If it's already bytes or a file-like object
|
| 199 |
+
if hasattr(image, 'read'):
|
| 200 |
+
image_bytes = image.read()
|
| 201 |
+
filename = getattr(image, 'name', 'uploaded_image.jpg')
|
| 202 |
+
else:
|
| 203 |
+
# Try to handle as PIL Image or other format
|
| 204 |
+
if hasattr(image, 'save'): # It's likely a PIL Image
|
| 205 |
+
buffer = io.BytesIO()
|
| 206 |
+
image.save(buffer, format='JPEG')
|
| 207 |
+
image_bytes = buffer.getvalue()
|
| 208 |
+
filename = "uploaded_image.jpg"
|
| 209 |
+
else:
|
| 210 |
+
return "β Unsupported image format", "", "", "", ""
|
| 211 |
|
| 212 |
# Send to backend for analysis
|
| 213 |
files = {"file": (filename, image_bytes, "image/jpeg")}
|
|
|
|
| 371 |
patient_name = gr.Textbox(label="Patient Name *", placeholder="Enter full name")
|
| 372 |
|
| 373 |
with gr.Row():
|
| 374 |
+
date_of_birth = gr.Textbox(label="Date of Birth * (YYYY-MM-DD)", placeholder="1990-01-01")
|
| 375 |
gender = gr.Dropdown(
|
| 376 |
choices=["Male", "Female", "Other"],
|
| 377 |
label="Gender *",
|
|
|
|
| 386 |
generate_mrn_btn = gr.Button("π― Generate MRN", variant="secondary")
|
| 387 |
|
| 388 |
referring_physician = gr.Textbox(label="Referring Physician *", placeholder="Dr. Name")
|
| 389 |
+
study_date = gr.Textbox(
|
| 390 |
+
label="Study Date * (YYYY-MM-DD)",
|
| 391 |
+
value=datetime.now().strftime("%Y-%m-%d"),
|
| 392 |
+
placeholder="2025-01-01"
|
| 393 |
+
)
|
| 394 |
|
| 395 |
# MRN Generation
|
| 396 |
generate_mrn_btn.click(
|