Skip to content

fix(detection): Fix missing import os, static folder path, and stream read error in Brain Tumor Detection Web App #1732

Open

Description

@bobby404-K

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

The Flask web application for Brain Tumor Detection in projects/detection/Brain Tumor Detection/Web App/app.py has several runtime and design issues that prevent it from running properly:

  1. Missing import os (NameError):
    Line 10 calls:

    dir_path = os.path.dirname(os.path.realpath(__file__))

    However, import os is never imported anywhere in app.py, immediately crashing the app upon launch with NameError: name 'os' is not defined.

  2. CSS 404 / Missing Static Folder Configuration:
    The templates (index.html and result.html) reference CSS via {{ url_for('static', filename='styles.css') }} and {{ url_for('static', filename='styles1.css') }}. However, the directory in Web App/ is named styles/ rather than static/, resulting in 404 HTTP errors for styling unless static_folder='styles' is configured in the Flask application.

  3. Double Stream Read / RGBA Crash on Upload:
    In predict():

    img = Image.open(image.stream)
    ...
    img_base64 = image_to_base64(Image.open(image.stream))

    Reading image.stream twice without image.stream.seek(0) causes PIL.UnidentifiedImageError. Additionally, uploading RGBA/PNG files crashes img.save(buffered, format="JPEG") with OSError: cannot write mode RGBA as JPEG.

  4. Missing Graceful Model Fallback:
    If best_model.h5 is not yet placed in the folder, the entire Flask server crashes immediately on startup rather than launching and providing informative status.

  5. Non-Portable Requirements (tensorflow_intel):
    requirements.txt pins tensorflow_intel==2.12.0, which causes dependency resolution failures on non-Windows environments.

Expected behavior

  1. app.py should import os and run without NameError.
  2. Flask should configure static_folder='styles' so url_for('static', ...) serves styles.css and styles1.css properly.
  3. Uploaded images should be opened and converted to RGB once, avoiding stream exhaustion and RGBA JPEG errors.
  4. If best_model.h5 is absent, the app should start and inform the user cleanly on prediction instead of failing startup.
  5. requirements.txt should specify portable dependencies.

Proposed Changes

  1. Add import os to app.py.
  2. Initialize Flask with app = Flask(__name__, static_folder='styles').
  3. Read the uploaded image once, convert to RGB, and pass to both preprocessing and base64 encoding.
  4. Add safe model loading with friendly fallback when best_model.h5 is missing.
  5. Update requirements.txt with portable dependencies.

Record

  • I have read the Contributing Guidelines
  • I want to work on this issue

Activity

  1. github-actions commented on Nov 9, 2026

    @github-actions

    Thank you for creating this issue! 🎉 We'll look into it as soon as possible. In the meantime, please make sure to provide all the necessary details and context. If you have any questions reach out to LinkedIn. Your contributions are highly appreciated! 😊

    Note: I Maintain the repo issue twice a day, or ideally 1 day, If your issue goes stale for more than one day you can tag and comment on this same issue.

    You can also check our CONTRIBUTING.md for guidelines on contributing to this project.
    We are here to help you on this journey of opensource, any help feel free to tag me or book an appointment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions