yuwarasu commited on
Commit
fa5e405
·
1 Parent(s): 63300c8
Dockerfile CHANGED
@@ -8,18 +8,10 @@ WORKDIR /app
8
  # Copy the current directory contents into the container
9
  COPY . /app
10
 
11
- # Install necessary dependencies
12
- RUN apt-get update && apt-get install -y \
13
- ffmpeg \
14
- libsm6 \
15
- libxext6 \
16
- git
17
 
18
- # Clone the YOLOv5 repository
19
  RUN git clone https://github.com/ultralytics/yolov5.git
20
-
21
- # Install Python packages specified in requirements.txt
22
  RUN pip install -r requirements.txt
23
 
24
-
25
- CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
 
8
  # Copy the current directory contents into the container
9
  COPY . /app
10
 
11
+ RUN apt-get update && apt-get install ffmpeg libsm6 libxext6 git -y
 
 
 
 
 
12
 
 
13
  RUN git clone https://github.com/ultralytics/yolov5.git
14
+ # Install any needed packages specified in requirements.txt
 
15
  RUN pip install -r requirements.txt
16
 
17
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
 
README.md CHANGED
@@ -1,10 +1,11 @@
1
  ---
2
- title: Pipecountapp
3
- emoji: ⚡
4
  colorFrom: pink
5
- colorTo: purple
6
  sdk: docker
7
  pinned: false
 
8
  ---
9
 
10
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: Pipecounting
3
+ emoji: 🐢
4
  colorFrom: pink
5
+ colorTo: yellow
6
  sdk: docker
7
  pinned: false
8
+ license: mit
9
  ---
10
 
11
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
main.py CHANGED
@@ -1,21 +1,21 @@
1
  from model import get_yolov5
2
  from fastapi import FastAPI, File, UploadFile
3
  from io import BytesIO
4
- from fastapi.responses import Response
5
- from fastapi.responses import FileResponse
6
- from fastapi.staticfiles import StaticFiles
7
-
8
  import cv2
9
  import json
10
  import numpy as np
11
  import io
 
12
  import base64
13
  from fastapi import FastAPI, HTTPException, Request, Depends
14
  from fastapi.responses import JSONResponse
15
  from fastapi.encoders import jsonable_encoder
16
  from fastapi.middleware.cors import CORSMiddleware
17
-
18
-
 
 
 
19
 
20
 
21
  app = FastAPI(title="PIPE COUNTING API",
@@ -29,12 +29,23 @@ app.add_middleware(
29
  allow_headers=["*"],
30
  )
31
  # Mount the "static" folder to serve static files (like your index.html)
32
- app.mount("/static", StaticFiles(directory="static"), name="static")
 
 
 
 
 
 
 
 
 
 
33
 
34
- # Define a route to serve the index.html file
35
- @app.get("/")
36
- async def get_index():
37
- return FileResponse("static/index.html")
 
38
 
39
 
40
  @app.post("/detectImage")
 
1
  from model import get_yolov5
2
  from fastapi import FastAPI, File, UploadFile
3
  from io import BytesIO
 
 
 
 
4
  import cv2
5
  import json
6
  import numpy as np
7
  import io
8
+ import os
9
  import base64
10
  from fastapi import FastAPI, HTTPException, Request, Depends
11
  from fastapi.responses import JSONResponse
12
  from fastapi.encoders import jsonable_encoder
13
  from fastapi.middleware.cors import CORSMiddleware
14
+ from fastapi.responses import Response
15
+ from fastapi.responses import FileResponse
16
+ from fastapi.staticfiles import StaticFiles
17
+ from fastapi.templating import Jinja2Templates
18
+ from pathlib import Path
19
 
20
 
21
  app = FastAPI(title="PIPE COUNTING API",
 
29
  allow_headers=["*"],
30
  )
31
  # Mount the "static" folder to serve static files (like your index.html)
32
+ app = FastAPI()
33
+
34
+
35
+ # Define the path to your "static" directory
36
+ static_path = Path(__file__).resolve().parent / "static"
37
+
38
+ # Route to serve files dynamically based on the filename parameter
39
+ @app.get("/{filename:path}")
40
+ async def serve_file(filename: str):
41
+ if not filename:
42
+ filename = "index.html"
43
 
44
+ file_path = static_path / filename
45
+ if file_path.is_file():
46
+ return FileResponse(file_path)
47
+ else:
48
+ return {"error": "File not found"}
49
 
50
 
51
  @app.post("/detectImage")
static/index.html CHANGED
@@ -1 +1 @@
1
- <!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>NPI Pipe Counting</title><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="description" content="QR Code Scanner is the fastest and most user-friendly web application."><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-title" content="QR Scanner"><meta name="apple-mobile-web-app-status-bar-style" content="#e4e4e4"><meta name="apple-mobile-web-app-capable" content="yes"><meta name="application-name" content="QR Scanner"><meta name="msapplication-TileColor" content="#e4e4e4"><meta name="msapplication-TileImage" content="/images/touch/mstile-150x150.png"><meta name="theme-color" content="#fff"><link rel="apple-touch-icon" href="/images/touch/apple-touch-icon.jpg"><link rel="icon" type="image/png" href="/images/touch/favicon-32x32.png" sizes="32x32"><link rel="icon" type="image/png" href="/images/touch/favicon-16x16.png" sizes="16x16"><link rel="shortcut icon" href="/images/touch/favicon.ico"><link rel="manifest" href="/manifest.json"><link href="styles.css" rel="stylesheet"></head><body><div class="app__layout"><!-- Header --><header class="app__header"><span class="app__header-icon" onclick="alert('โปรแกรมนับจำนวนท่อPVCจากรูปภาพ\nบริษัท นวพลาสติก อุตสาหกรรม จำกัด\nสร้างโดย Digital Infrastructure\nเวอร์ชั่น 1.0 12-ตุลาคม-2023');"><svg fill="#FFFFFF" height="27" viewBox="0 0 24 24" width="27" xmlns="http://www.w3.org/2000/svg"><path d="M0 0h24v24H0z" fill="none"/><path d="M11 17h2v-6h-2v6zm1-15C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8zM11 9h2V7h-2v2z"/></svg></span></header><!-- <img id="image" src="/images/bg.png"> --><main class="app__layout-content"></main></div><div class="app__overlay"><div class="app__overlay-frame"></div><!-- Scanner animation --><div class="custom-scanner"></div><div class="app__help-text"></div></div><input type="file" id="fileInput" style="display: none;" accept="image/*"><div class="app__counting"></div><div class="app__select-photos"></div><div class="credit"></div><script async src="https://cdn.jsdelivr.net/npm/pwacompat@2.0.6/pwacompat.min.js" integrity="sha384-GOaSLecPIMCJksN83HLuYf9FToOiQ2Df0+0ntv7ey8zjUHESXhthwvq9hXAZTifA" crossorigin="anonymous"></script><script type="text/javascript" src="main.43948d610709eccbdd40.bundle.js"></script></body></html>
 
1
+ <!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>NPI Pipe Counting</title><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="description" content="QR Code Scanner is the fastest and most user-friendly web application."><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-title" content="QR Scanner"><meta name="apple-mobile-web-app-status-bar-style" content="#e4e4e4"><meta name="apple-mobile-web-app-capable" content="yes"><meta name="application-name" content="QR Scanner"><meta name="msapplication-TileColor" content="#e4e4e4"><meta name="msapplication-TileImage" content="/images/touch/mstile-150x150.png"><meta name="theme-color" content="#fff"><link rel="apple-touch-icon" href="/images/touch/apple-touch-icon.jpg"><link rel="icon" type="image/png" href="/images/touch/favicon-32x32.png" sizes="32x32"><link rel="icon" type="image/png" href="/images/touch/favicon-16x16.png" sizes="16x16"><link rel="shortcut icon" href="/images/touch/favicon.ico"><link rel="manifest" href="/manifest.json"><link href="styles.css" rel="stylesheet"></head><body><div class="app__layout"><!-- Header --><header class="app__header"><span class="app__header-icon" onclick="alert('โปรแกรมนับจำนวนท่อPVCจากรูปภาพ\nบริษัท นวพลาสติก อุตสาหกรรม จำกัด\nสร้างโดย Digital Infrastructure\nเวอร์ชั่น 1.0 12-ตุลาคม-2023');"><svg fill="#FFFFFF" height="27" viewBox="0 0 24 24" width="27" xmlns="http://www.w3.org/2000/svg"><path d="M0 0h24v24H0z" fill="none"/><path d="M11 17h2v-6h-2v6zm1-15C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8zM11 9h2V7h-2v2z"/></svg></span></header><!-- <img id="image" src="/images/bg.png"> --><main class="app__layout-content"></main></div><div class="app__overlay"><div class="app__overlay-frame"></div><!-- Scanner animation --><div class="custom-scanner"></div><div class="app__help-text"></div></div><input type="file" id="fileInput" style="display: none;" accept="image/*"><div class="app__counting"></div><div class="app__select-photos"></div><div class="credit"></div><script async src="https://cdn.jsdelivr.net/npm/pwacompat@2.0.6/pwacompat.min.js" integrity="sha384-GOaSLecPIMCJksN83HLuYf9FToOiQ2Df0+0ntv7ey8zjUHESXhthwvq9hXAZTifA" crossorigin="anonymous"></script><script type="text/javascript" src="main.913afb6ef2e3fe3c72d9.bundle.js"></script></body></html>
static/{main.43948d610709eccbdd40.bundle.js → main.913afb6ef2e3fe3c72d9.bundle.js} RENAMED
The diff for this file is too large to render. See raw diff
 
static/{precache-manifest.13f6c4bca25d2fb2a1e4dc88873e0c37.js → precache-manifest.e10a6a5bbb8d3bb5c8bc2643129f2f16.js} RENAMED
@@ -1,9 +1,9 @@
1
  self.__precacheManifest = [
2
  {
3
- "url": "main.43948d610709eccbdd40.bundle.js"
4
  },
5
  {
6
- "revision": "41482ec88e7142e25338",
7
  "url": "styles.css"
8
  }
9
  ];
 
1
  self.__precacheManifest = [
2
  {
3
+ "url": "main.913afb6ef2e3fe3c72d9.bundle.js"
4
  },
5
  {
6
+ "revision": "a3cbd1c58c09b0f89bc3",
7
  "url": "styles.css"
8
  }
9
  ];
static/service-worker.js CHANGED
@@ -14,7 +14,7 @@
14
  importScripts("https://storage.googleapis.com/workbox-cdn/releases/3.6.3/workbox-sw.js");
15
 
16
  importScripts(
17
- "precache-manifest.13f6c4bca25d2fb2a1e4dc88873e0c37.js"
18
  );
19
 
20
  workbox.skipWaiting();
 
14
  importScripts("https://storage.googleapis.com/workbox-cdn/releases/3.6.3/workbox-sw.js");
15
 
16
  importScripts(
17
+ "precache-manifest.e10a6a5bbb8d3bb5c8bc2643129f2f16.js"
18
  );
19
 
20
  workbox.skipWaiting();