mussie1212 commited on
Commit
5d3eaef
·
1 Parent(s): c53b292

fix:first commit on the ocr

Browse files
Files changed (2) hide show
  1. Dockerfile +4 -4
  2. app/main.py +3 -6
Dockerfile CHANGED
@@ -13,8 +13,8 @@ RUN pip install --no-cache-dir -r requirements.txt
13
  # Copy the application code from the 'app' directory
14
  COPY app/ .
15
 
16
- # Expose the port the app runs on (change if necessary)
17
- EXPOSE 5000
18
 
19
- # Command to run the application (adjust as needed)
20
- CMD ["python", "main.py"]
 
13
  # Copy the application code from the 'app' directory
14
  COPY app/ .
15
 
16
+ # Expose the port Hugging Face requires
17
+ EXPOSE 7860
18
 
19
+ # Run the FastAPI app with uvicorn on the correct port
20
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
app/main.py CHANGED
@@ -25,21 +25,18 @@ app = FastAPI()
25
 
26
  @app.post("/process-pdf/")
27
  async def process_pdf(file: UploadFile = File(...)):
28
- # Save uploaded file to a temporary location
29
  with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp:
30
  shutil.copyfileobj(file.file, tmp)
31
  tmp_path = tmp.name
32
 
33
- # Await the async processing function
34
  result = process_document(tmp_path, api_key=ConfigStaticFiles.gemini_api_key)
35
 
36
- # Check if result is a string and parse it
37
  if isinstance(result, str):
38
- result = json.loads(result) # Convert the JSON string to a dictionary
39
 
40
- # Return the result as a JSON response
41
  return JSONResponse(content=result)
42
 
43
 
44
  if __name__ == "__main__":
45
- uvicorn.run("main:app", host="0.0.0.0", port=5000, reload=False)
 
 
25
 
26
  @app.post("/process-pdf/")
27
  async def process_pdf(file: UploadFile = File(...)):
 
28
  with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp:
29
  shutil.copyfileobj(file.file, tmp)
30
  tmp_path = tmp.name
31
 
 
32
  result = process_document(tmp_path, api_key=ConfigStaticFiles.gemini_api_key)
33
 
 
34
  if isinstance(result, str):
35
+ result = json.loads(result)
36
 
 
37
  return JSONResponse(content=result)
38
 
39
 
40
  if __name__ == "__main__":
41
+ # IMPORTANT: Hugging Face requires port 7860
42
+ uvicorn.run("main:app", host="0.0.0.0", port=7860, reload=False)