Soumik Bose commited on
Commit
8607b18
·
1 Parent(s): b76793f

Initial commit

Browse files
Files changed (3) hide show
  1. Dockerfile +16 -5
  2. README.md +8 -0
  3. main.py +1 -5
Dockerfile CHANGED
@@ -37,9 +37,20 @@ COPY . .
37
  RUN useradd -m appuser && chown -R appuser /app
38
  USER appuser
39
 
40
- # Healthcheck as requested
41
- HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
42
- CMD python -c "import requests; requests.get('http://localhost:8000/api/v1/ping', timeout=5)" || exit 1
43
 
44
- # Run the application
45
- CMD ["python", "main.py"]
 
 
 
 
 
 
 
 
 
 
 
 
37
  RUN useradd -m appuser && chown -R appuser /app
38
  USER appuser
39
 
40
+ # Set environment variables
41
+ ENV HF_HOME=/tmp/cache
42
+ ENV PORT=7860
43
 
44
+ # Create cache directory (if still needed)
45
+ RUN mkdir -p ${HF_HOME} && chmod 777 ${HF_HOME}
46
+
47
+ # Expose port
48
+ EXPOSE $PORT
49
+
50
+ # Run FastAPI with Uvicorn
51
+ CMD bash -c "\
52
+ while true; do \
53
+ curl -s https://xce009-inference-test.hf.space/ping >/dev/null; \
54
+ sleep 300; \
55
+ done & \
56
+ uvicorn main:app --host 0.0.0.0 --port ${PORT} --workers 4"
README.md ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: My OCR API
3
+ emoji: ⚡
4
+ colorFrom: blue
5
+ colorTo: fuchsia
6
+ sdk: docker
7
+ pinned: false
8
+ ---
main.py CHANGED
@@ -315,8 +315,4 @@ async def extract_data(
315
  os.remove(tmp_file_path)
316
  logger.info("Temp file deleted.")
317
  except OSError:
318
- pass
319
-
320
- if __name__ == "__main__":
321
- # Production: Workers should be handled by Gunicorn or Docker orchestration
322
- uvicorn.run("main:app", host="0.0.0.0", port=8000, workers=1)
 
315
  os.remove(tmp_file_path)
316
  logger.info("Temp file deleted.")
317
  except OSError:
318
+ pass