{"id":20800690,"url":"https://github.com/whatheheckisthis/fast-api","last_synced_at":"2025-07-03T15:09:17.433Z","repository":{"id":246899767,"uuid":"823896488","full_name":"whatheheckisthis/Fast-API","owner":"whatheheckisthis","description":"In the realm of financial security, authenticating banknotes is crucial to combat fraud and ensure the integrity of monetary transactions. This project aims to leverage advanced machine learning techniques and the FastAPI framework to develop a robust API for predicting the authenticity of banknotes. analyzing features extracted from high res","archived":false,"fork":false,"pushed_at":"2024-07-04T03:31:29.000Z","size":137,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-12T02:44:33.158Z","etag":null,"topics":["cyber-security","data-structures","finance"],"latest_commit_sha":null,"homepage":"","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/whatheheckisthis.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-07-04T00:48:50.000Z","updated_at":"2024-07-04T09:30:38.000Z","dependencies_parsed_at":"2024-07-05T20:29:32.617Z","dependency_job_id":null,"html_url":"https://github.com/whatheheckisthis/Fast-API","commit_stats":null,"previous_names":["whatheheckisthis/fast-api"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/whatheheckisthis/Fast-API","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whatheheckisthis%2FFast-API","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whatheheckisthis%2FFast-API/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whatheheckisthis%2FFast-API/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whatheheckisthis%2FFast-API/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/whatheheckisthis","download_url":"https://codeload.github.com/whatheheckisthis/Fast-API/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whatheheckisthis%2FFast-API/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261390861,"owners_count":23151653,"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","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":["cyber-security","data-structures","finance"],"created_at":"2024-11-17T18:14:55.468Z","updated_at":"2025-06-23T00:34:52.943Z","avatar_url":"https://github.com/whatheheckisthis.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fast-API\n\n## Task Overview: Deploying a FastAPI Application for Financial Data Analysis\n\n### Objective\n\nDevelop and deploy a FastAPI application that utilizes a machine learning model to predict the authenticity of banknotes based on features extracted from images. This involves:\n\n1. **Data Extraction**: Preparing the data by extracting relevant features from banknote images.\n2. **Model Training**: Building a machine learning model to classify banknotes.\n3. **API Development**: Creating an API to serve predictions.\n\n### Context\n\n#### Data Extraction\n\n- **Source**: The images are taken from genuine and forged banknote-like specimens.\n- **Resolution and Format**: The final images are 400x400 pixels with a resolution of 660 dpi, usually in grayscale.\n- **Feature Extraction**: Wavelet Transform tools are used to derive statistical features such as variance, skewness, curtosis, and entropy from these images.\n\n#### Model Training\n\n- **Goal**: Use the extracted features to train a machine learning model that can distinguish between genuine and forged banknotes.\n- **Data Format**: Typically, the data is stored in a CSV file where each row represents a banknote and each column represents a feature (e.g., variance_wavelet, skewness_wavelet).\n- **Model**: Various models can be employed, but a Random Forest classifier is commonly used due to its robustness and accuracy.\n\n#### API Development\n\n- **Purpose**: The FastAPI application provides a RESTful interface for making predictions based on input features.\n- **Endpoints**:\n  - **Root Endpoint (`/`)**: A simple welcome message to verify the API is running.\n  - **Prediction Endpoint (`/predict`)**: Accepts feature inputs and returns a prediction on whether a banknote is genuine or forged.\n\n### Steps to Implement\n\n#### 1. Data Preparation\n\n1. **Collect Images**: Gather images of both genuine and forged banknotes.\n2. **Extract Features**: Apply wavelet transform and other image processing techniques to extract statistical features.\n3. **Store Data**: Save the extracted features in a structured format, typically CSV.\n\n**Example Feature Extraction:**\n```text\nvariance_wavelet, skewness_wavelet, curtosis_wavelet, entropy_image, label\n2.643, 5.085, -2.189, -0.123, 0\n4.525, 8.167, -3.876, 0.014, 1\n```\n\n#### 2. Model Training\n\n1. **Load Data**: Read the prepared data file.\n2. **Train Model**: Use a machine learning algorithm to train a model on the features.\n3. **Save Model**: Serialize the trained model using a tool like `pickle`.\n\n**Example Training Script (`train_model.py`):**\n```python\nimport pandas as pd\nfrom sklearn.ensemble import RandomForestClassifier\nimport pickle\n\ndef train_model(data_path='data/banknote_features.csv'):\n    df = pd.read_csv(data_path)\n    X = df.drop(columns=['label'])\n    y = df['label']\n    model = RandomForestClassifier(n_estimators=100, random_state=42)\n    model.fit(X, y)\n    with open('model.pkl', 'wb') as f:\n        pickle.dump(model, f)\n    print(\"Model trained and saved as model.pkl\")\n```\n\n#### 3. API Development\n\n1. **Setup FastAPI**: Install FastAPI and Uvicorn.\n2. **Load Model**: Load the trained model within the FastAPI app.\n3. **Create Endpoints**: Define the root and prediction endpoints.\n\n**Example FastAPI Script (`main.py`):**\n```python\nfrom fastapi import FastAPI\nfrom pydantic import BaseModel\nimport pandas as pd\nimport pickle\n\napp = FastAPI()\n\n# Load the model\nwith open('models/model.pkl', 'rb') as f:\n    model = pickle.load(f)\n\n# Define the request body schema\nclass BanknoteFeatures(BaseModel):\n    variance_wavelet: float\n    skewness_wavelet: float\n    curtosis_wavelet: float\n    entropy_image: float\n\n@app.get('/')\ndef read_root():\n    return {'message': 'Welcome to the Banknote Authentication API'}\n\n@app.post('/predict')\ndef predict(features: BanknoteFeatures):\n    data = pd.DataFrame([features.dict()])\n    prediction = model.predict(data)\n    result = 'Genuine' if prediction[0] == 0 else 'Forged'\n    return {'prediction': result}\n\nif __name__ == '__main__':\n    import uvicorn\n    uvicorn.run(app, host='localhost', port=8000)\n```\n\n### Project Structure\n\nOrganize the project into a directory structure for clarity and manageability:\n\n```\n/banknote-authentication\n│\n├── data\n│   └── banknote_features.csv\n│\n├── models\n│   └── model.pkl\n│\n├── scripts\n│   └── train_model.py\n│\n├── main.py\n├── README.md\n└── requirements.txt\n```\n\n### Example GitHub Repository\n\n- **Repository Name**: `banknote-authentication`\n- **Primary Branch**: `main`\n- **URL**: `https://github.com/username/banknote-authentication`\n\n### Steps to Deploy on GitHub\n\n1. **Initialize Repository**: Create a new GitHub repository named `banknote-authentication`.\n2. **Clone Repository**: Clone the repository to your local machine.\n3. **Add Files**: Add your project files (`data`, `models`, `scripts`, `main.py`, `README.md`, `requirements.txt`).\n4. **Commit and Push**: Commit your changes and push them to the GitHub repository.\n5. **Documentation**: Ensure the `README.md` contains detailed instructions on setting up and running the application.\n\n**README.md Example:**\n```markdown\n# Banknote Authentication API\n\nThis project uses FastAPI to create a machine learning API for authenticating banknotes based on extracted image features.\n\n## Features\n\n- **Model Training**: Uses Random Forest to classify banknotes.\n- **API Endpoints**:\n  - `/`: Welcome message.\n  - `/predict`: Predicts the authenticity of a banknote.\n\n## Setup\n\n1. Clone the repository.\n2. Install dependencies:\n   ```bash\n   pip install -r requirements.txt\n   ```\n3. Train the model:\n   ```bash\n   python scripts/train_model.py\n   ```\n4. Run the API:\n   ```bash\n   python main.py\n   \n## Usage\n\n- Access the API at `http://localhost:8000`.\n- Use `/predict` to submit banknote features and receive predictions.\n  \n### Benefits of FastAPI for This Task\n\n- **Performance**: FastAPI is designed for high performance and is built on standard Python type hints, making it fast and intuitive.\n- **Ease of Use**: Provides automatic generation of interactive API documentation (using Swagger and Redoc).\n- **Scalability**: Supports asynchronous programming, making it scalable and suitable for handling numerous concurrent requests.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhatheheckisthis%2Ffast-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwhatheheckisthis%2Ffast-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhatheheckisthis%2Ffast-api/lists"}