{"id":14970757,"url":"https://github.com/islam-hady9/braintumordetection-api","last_synced_at":"2026-02-11T22:45:47.145Z","repository":{"id":254068657,"uuid":"845237834","full_name":"Islam-hady9/BrainTumorDetection-API","owner":"Islam-hady9","description":"Brain Tumor Detection using CNN \u0026 FastAPI.","archived":false,"fork":false,"pushed_at":"2024-10-12T07:46:29.000Z","size":64813,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-07T20:05:52.675Z","etag":null,"topics":["apidevelopment","brain-tumor-detection","cnn","deep-learning","fastapi","imageclassification","machine-learning","medicalimaging","python","tensorflow"],"latest_commit_sha":null,"homepage":"https://www.kaggle.com/datasets/navoneel/brain-mri-images-for-brain-tumor-detection?resource=download","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Islam-hady9.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-20T21:27:49.000Z","updated_at":"2024-12-19T20:43:55.000Z","dependencies_parsed_at":null,"dependency_job_id":"92e6b8eb-e9d0-4291-8b13-fa9141983cfa","html_url":"https://github.com/Islam-hady9/BrainTumorDetection-API","commit_stats":{"total_commits":22,"total_committers":2,"mean_commits":11.0,"dds":0.2272727272727273,"last_synced_commit":"5e6757acaf7bf05dd5e7451d2101a8248f83ac6f"},"previous_names":["islam-hady9/braintumordetection-api"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Islam-hady9/BrainTumorDetection-API","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Islam-hady9%2FBrainTumorDetection-API","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Islam-hady9%2FBrainTumorDetection-API/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Islam-hady9%2FBrainTumorDetection-API/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Islam-hady9%2FBrainTumorDetection-API/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Islam-hady9","download_url":"https://codeload.github.com/Islam-hady9/BrainTumorDetection-API/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Islam-hady9%2FBrainTumorDetection-API/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274113635,"owners_count":25224450,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-07T02:00:09.463Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apidevelopment","brain-tumor-detection","cnn","deep-learning","fastapi","imageclassification","machine-learning","medicalimaging","python","tensorflow"],"created_at":"2024-09-24T13:44:06.015Z","updated_at":"2026-02-11T22:45:47.117Z","avatar_url":"https://github.com/Islam-hady9.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Brain Tumor Detection API\n\n\u003cdiv align=\"center\"\u003e\n  \u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://github.com/Islam-hady9/BrainTumorDetection-API/blob/main/project_icon.jpg?raw=true\" alt=\"brain\" /\u003e\n  \u003c/p\u003e\n\u003cp align=\"center\"\u003e\n\u003cstrong\u003eBrain Tumor Detection using CNN \u0026 FastAPI\u003c/strong\u003e\u003c/p\u003e\n\u003c/div\u003e\n\n---\n\nThis repository contains a FastAPI-based API for detecting brain tumors using a Convolutional Neural Network (CNN) model. The model is trained on a dataset of MRI images labeled as either \"tumor\" or \"no tumor.\" The API allows users to upload an MRI image and receive a prediction indicating whether the image contains a brain tumor.\n\n## Project Overview\n\nBrain tumor detection is a critical task in medical imaging, as early and accurate detection can significantly impact patient outcomes. This project leverages deep learning techniques to build a CNN model capable of classifying MRI images into two categories: \"tumor\" or \"no tumor.\" The trained model is then deployed as an API using FastAPI, providing an accessible interface for users to interact with the model and make predictions.\n\n## Features\n\n- **Image Upload:** Users can upload MRI images directly through the web interface provided by the `index.html` page. The `static/styles.css` file ensures that the page is styled for a better user experience.\n- **Prediction:** The FastAPI API endpoint `/predict/` processes the uploaded image and returns a prediction indicating whether the image contains a brain tumor. Predictions are displayed on the web interface below the uploaded image.\n- **Model Summary:** A Convolutional Neural Network (CNN) is used for prediction. The model includes layers for convolution, pooling, flattening, and dense connections, and has been trained to achieve a high accuracy rate.\n- **Data Augmentation:** The model utilizes data augmentation techniques to enhance generalization and robustness. This helps in improving the model's performance by exposing it to a wider variety of training examples.\n- **Visualization:** Scripts are available for visualizing training results, including loss curves and confusion matrices, which help in evaluating the model's performance and understanding its learning progress.\n- **User Interface:** A simple and user-friendly web interface allows users to upload images and view predictions. The interface is styled using a separate `styles.css` file for a clean and professional look.\n\n## Installation\n\n### Prerequisites\n\n- Anaconda or Miniconda\n- Python 3.8 (included in the Conda environment)\n\n### Clone the Repository\n\n```bash\ngit clone https://github.com/Islam-hady9/BrainTumorDetection-API.git\ncd BrainTumorDetection-API\n```\n\n### Create a Conda Virtual Environment\n\nIt's recommended to create a Conda virtual environment to manage dependencies.\n\n```bash\nconda create -n brain-tumor-detection python=3.8\nconda activate brain-tumor-detection\n```\n\n### Install Dependencies\n\nInstall the required Python packages using the `requirements.txt` file:\n\n```bash\npip install -r requirements.txt\n```\n\n## Usage\n\n### 1. **Train the Model Or Use the Pre-trained Model directly**\n\nIf you haven’t trained the model yet, use the Jupyter Notebook `brain_tumor_detection_using_cnn.ipynb` provided in the repository. Ensure you have the MRI images in the `Dataset/` directory and in the correct format before running the notebook or use the pre-trained model `brain_tumor_cnn_model.h5` directly that I trained.\n\n### 2. **Run the FastAPI Server**\n\nStart the FastAPI server to expose the API:\n\n```bash\nuvicorn app:app --reload\n```\n\nThe server will start running at `http://127.0.0.1:8000/`.\n\n### 3. **Access the Web Interface**\n\nOpen your browser and navigate to `http://127.0.0.1:8000` to access the HTML interface. You can upload images through this interface and receive predictions.\n\n### 4. **Make Predictions via API**\n\nYou can make predictions by sending a POST request to the `/predict/` endpoint with an image file. \n\nExample using `curl`:\n\n```bash\ncurl -X POST \"http://127.0.0.1:8000/predict/\" -F \"file=@path_to_your_image.jpg\"\n```\n\nReplace `path_to_your_image.jpg` with the actual path to your MRI image file.\n\n### 5. **Test the API**\n\nYou can test the API using the `test_api.py` script provided in the repository:\n\n```bash\npython test_api.py\n```\n\nThis script will send a sample image to the API and print the prediction result. Make sure to modify the script if necessary to use the correct path to your test image.\n\n## Project Structure\n\n- **`app.py`:** The FastAPI application script that defines the API endpoints and handles image uploads and predictions.\n- **`test_api.py`:** A script for testing the API by sending a sample image and printing the prediction result.\n- **`requirements.txt`:** A file listing all Python dependencies required for the project.\n- **`brain_tumor_detection_using_cnn.ipynb`:** Jupyter Notebook used for training the CNN model (Accuracy: 92.16%).\n- **`brain_tumor_model.h5`:** The trained Keras model file (to be generated after training).\n- **`Dataset/`:** Directory containing MRI images used for training and testing the model.\n- **`templates/`:** Directory containing HTML templates.\n  - **`index.html`:** The main HTML file providing the user interface for image uploads and predictions.\n- **`static/`:** Directory containing static files such as CSS.\n  - **`styles.css`:** The CSS file used for styling the `index.html` page.\n- **`Project Presentation.pptx`:** Project presentation file.\n- **`README.md`:** This file, providing an overview and instructions for the project.\n\n## Dataset\n\nThe dataset used for training the model should be placed in the `Dataset/brain_tumor_dataset` directory, with subdirectories `yes` and `no` for images containing tumors and images without tumors, respectively.\n\n- **Yes Tumor Directory:** `Dataset/brain_tumor_dataset/yes`\n- **No Tumor Directory:** `Dataset/brain_tumor_dataset/no`\n\nEnsure that all images are in a compatible format (e.g., `.jpg`, `.png`).\n\n## Model Details\n\nThe CNN model used in this project has the following architecture:\n\n- **Conv2D Layers:** For feature extraction from the input images.\n- **MaxPooling2D Layers:** For downsampling the feature maps.\n- **Flatten Layer:** To convert 2D feature maps into 1D feature vectors.\n- **Dense Layers:** Fully connected layers for classification.\n- **Output Layer:** A softmax layer with 2 units (tumor, no tumor).\n\n## Visualization\n\nThe repository includes code for visualizing the training process, such as loss curves and confusion matrices. These visualizations can help in understanding the model's performance and diagnosing potential issues.\n\n## Web Interface Screens\n\n### Screen 1: Upload Image\n![Screen_1-Upload image](https://github.com/Islam-hady9/BrainTumorDetection-API/blob/main/Web%20Interface%20Screens/Screen_1-Upload%20image.png)\n\n### Screen 2: Show Prediction\n![Screen_2-Show prediction](https://github.com/Islam-hady9/BrainTumorDetection-API/blob/main/Web%20Interface%20Screens/Screen_2-Show%20prediction.png)\n\n## Contributing\n\nContributions to the project are welcome. If you encounter any issues or have suggestions for improvements, feel free to open an issue or submit a pull request.\n\n## License\n\nThis project is licensed under the MIT License.\n\n## Contact\n\nFor questions or inquiries, please contact [Islam Abd_Elhady] at [eslamabdo71239@gmail.com].\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fislam-hady9%2Fbraintumordetection-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fislam-hady9%2Fbraintumordetection-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fislam-hady9%2Fbraintumordetection-api/lists"}