{"id":15442601,"url":"https://github.com/ajay-dhangar/nothotdog","last_synced_at":"2025-03-28T07:13:44.906Z","repository":{"id":257729995,"uuid":"859138613","full_name":"ajay-dhangar/nothotdog","owner":"ajay-dhangar","description":"This project uses the Hugging Face API to detect whether an image contains a hot dog or not.","archived":false,"fork":false,"pushed_at":"2024-09-18T07:36:49.000Z","size":130,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-28T05:41:42.765Z","etag":null,"topics":["ai","not-hot-dog","not-hotdog","project","python3"],"latest_commit_sha":null,"homepage":"","language":"HTML","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/ajay-dhangar.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},"funding":{"github":"Ajay-Dhangar","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2024-09-18T06:42:29.000Z","updated_at":"2024-09-26T06:58:04.000Z","dependencies_parsed_at":"2024-09-18T10:08:36.483Z","dependency_job_id":null,"html_url":"https://github.com/ajay-dhangar/nothotdog","commit_stats":null,"previous_names":["ajay-dhangar/nothotdog"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajay-dhangar%2Fnothotdog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajay-dhangar%2Fnothotdog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajay-dhangar%2Fnothotdog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajay-dhangar%2Fnothotdog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ajay-dhangar","download_url":"https://codeload.github.com/ajay-dhangar/nothotdog/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245984590,"owners_count":20704798,"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":["ai","not-hot-dog","not-hotdog","project","python3"],"created_at":"2024-10-01T19:28:50.538Z","updated_at":"2025-03-28T07:13:44.885Z","avatar_url":"https://github.com/ajay-dhangar.png","language":"HTML","funding_links":["https://github.com/sponsors/Ajay-Dhangar"],"categories":[],"sub_categories":[],"readme":"# Not Hot Dog\n\n![alt text](image.png)\n\n## Detect \"Not Hot Dogs\" with hugging face API.\n\n**Prerequisites:** *[Hugging Face](https://huggingface.co/), HTML, Python Fundamentals*\n\n**Project Description:** This project uses the Hugging Face API to detect whether an image contains a hot dog or not. The API uses a pre-trained model to classify the image as either a hot dog or not a hot dog. The project also includes a simple HTML interface to upload an image and display the results.\n\n**Let's get started! 🌭**\n\n### Setting Up\n\n1. Create a new directory named nothotdog. This is where our project will live.\n\n   for example:\n\n    ```bash\n    mkdir nothotdog\n    ```\n\n2. Change into the nothotdog directory.\n\n    ```bash\n    cd nothotdog\n    ```\n\n3. Create a new Python virtual environment.\n\n    \u003e *Let's create a virtual environment or venv, which is an isolated environment that contains a Python installation in addition to other packages. If you want to learn more check out this [link](https://docs.python.org/3/tutorial/venv.html).*\n\n    ```bash\n    python3 -m venv .venv\n    ```\n\n4. Activate the virtual environment.\n\n    ```bash\n    source venv/bin/activate\n    ```\n\n5. Install Flask\n\n   \u003e *Now we are going to install Flask, which is a web framework in Python that makes it easy create to web applications and APIs. You can read more about it [here](https://flask.palletsprojects.com/en/2.2.x/).*\n\n    ```bash\n    python -m pip install flask\n    ```\n\n6.  Install Dotenv\n    \n    \u003e *Dotenv is a Python module that reads key-value pairs from a .env file and can set them as environment variables. You can read more about it [here](https://pypi.org/project/python-dotenv/).*\n\n    ```bash\n    python -m pip install python-dotenv\n    ```\n\n7. Install Requests\n\n    \u003e *Requests is a Python module that allows you to send HTTP requests using Python. You can read more about it [here](https://pypi.org/project/requests/).*\n\n    ```bash\n    python -m pip install requests\n    ```\n\n8. Create a templates folder for our HTML\n\n    ```bash\n    mkdir templates\n    ```\n  \n   \u003e *In Flask, if we are going to have HTML files we typically store them in a folder called templates so Flask is able to find them. Create a folder called templates, which should end up looking like this:*\n\n    ```bash\n    nothotdog\n    ├── templates\n    └── venv\n    ```\n\n9. Create a file called `index.html`\n\n    ```bash\n    touch templates/index.html\n    ```\n\n10. Add the HTML code\n\n    ```html\n    \u003c!DOCTYPE html\u003e\n    \u003chtml lang=\"en\"\u003e\n      \u003chead\u003e\n        \u003cmeta charset=\"UTF-8\" /\u003e\n        \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" /\u003e\n        \u003cmeta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" /\u003e\n        \u003ctitle\u003eHot dog or Not Hot dog?\u003c/title\u003e\n\n        \u003cstyle\u003e\n          body {\n            font-family: Arial, sans-serif;\n            text-align: center;\n            background-color: #f0f0f0;\n            margin: 0;\n            padding: 0;\n          }\n\n          h1 {\n            margin-top: 50px;\n            color: #333;\n            font-size: 2.5rem;\n          }\n\n          form {\n            background-color: #fff;\n            padding: 20px;\n            border-radius: 8px;\n            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);\n            width: 100%;\n            max-width: 400px;\n            margin: 20px auto;\n          }\n\n          input[type=\"file\"] {\n            margin-bottom: 20px;\n            padding: 10px;\n            border-radius: 4px;\n            border: 1px solid #ccc;\n            width: 100%;\n          }\n\n          input[type=\"submit\"] {\n            background-color: #4caf50;\n            color: white;\n            padding: 14px 20px;\n            margin: 8px 0;\n            border: none;\n            cursor: pointer;\n            border-radius: 4px;\n            width: 100%;\n            font-size: 1rem;\n          }\n\n          input[type=\"submit\"]:hover {\n            background-color: #45a049;\n          }\n        \u003c/style\u003e\n      \u003c/head\u003e\n      \u003cbody\u003e\n        \u003ch1\u003eHot dog or Not Hot dog?\u003c/h1\u003e\n\n        \u003cform method=\"post\" action=\"{{ url_for('upload') }}\" enctype=\"multipart/form-data\"\u003e\n          \u003clabel for=\"file1\"\u003eUpload an image:\u003c/label\u003e\n          \u003cinput type=\"file\" name=\"file1\" id=\"file1\" accept=\"image/*\" required /\u003e\n          \u003cinput type=\"submit\" value=\"Submit\" /\u003e\n        \u003c/form\u003e\n      \u003c/body\u003e\n    \u003c/html\u003e\n    ```\n\n11. Create a file called `web.py`\n\n    ```bash\n    touch web.py\n    ```\n\n12. Add the Python code\n\n    ```python\n    from flask import Flask, render_template, request, jsonify\n    import requests\n    import json\n    import os\n    from dotenv import load_dotenv\n\n    load_dotenv()\n\n    API_URL = os.getenv(\"HUGGING_FACE_API_URL\")\n    headers = {'Authorization': f'Bearer {os.getenv(\"HUGGING_FACE_API_KEY\")}'}\n\n    app = Flask(__name__)\n\n    def query(data):\n        response = requests.request('POST', API_URL, headers=headers, data=data)\n        return json.loads(response.content.decode('utf-8'))\n\n    @app.route('/')\n    def index():\n        return render_template('./index.html')\n\n    @app.route('/upload', methods=['POST'])\n    def upload():\n        file = request.files['file1']\n        modeldata = query(file)\n        return jsonify(modeldata)\n\n    app.run(host='0.0.0.0', port=81)\n    ```\n\n13. Create a `.env` file\n\n    ```bash\n    touch .env\n    ```\n\n14. Add the API URL and API Key to the `.env` file\n\n    ```bash\n    HUGGING_FACE_API_URL=https://api-inference.huggingface.co/models/simon-mooney/not-hot-dog\n    HUGGING_FACE_API_KEY=\n    ```\n\n    \u003e ***Note:** HUGGING_FACE_API_KEY=, ading in your API key and URL. This is where we place the hugging face data to allow us to use hugging face's models.*\n    \u003e \n    \u003e *You can get your API key by signing up for a free account at [Hugging Face](https://huggingface.co/). and create a token https://huggingface.co/settings/tokens.*\n\n\n15. Now run the project.\n\n    ```bash\n    python web.py\n    ```\n\n16. Open your browser\n\n    ```bash\n     * Running on all addresses (0.0.0.0)\n     * Running on http://127.0.0.1:81\n     * Running on http://192.168.71.231:81\n    ```\n\n    \u003e *Open your browser and go to http://127.0.0.1:81 or http://192.168.71.231:81.\n\n17. Upload an image\n\n    \u003e *You can now upload an image and see if it is a hot dog or not a hot dog.*\n    \u003e *You should see the results displayed on the screen.*\n\n### Conclusion\n\nCongratulations! You have successfully created a project that uses the Hugging Face API to detect whether an image contains a hot dog or not. You have also created a simple HTML interface to upload an image and display the results. You can now use this project to classify images as hot dogs or not hot dogs. 🌭 ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajay-dhangar%2Fnothotdog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fajay-dhangar%2Fnothotdog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajay-dhangar%2Fnothotdog/lists"}