senel commited on
Commit
246aeff
·
verified ·
1 Parent(s): 7dbb852

Update api.py

Browse files
Files changed (1) hide show
  1. api.py +3 -28
api.py CHANGED
@@ -1,42 +1,17 @@
1
- import os
2
- import numpy as np
3
- import cv2
4
- from io import BytesIO
5
- from PIL import Image
6
- import base64
7
  from fastapi import FastAPI, HTTPException
8
 
9
  app = FastAPI()
10
 
11
- def perform_ocr(file_content, file_name):
12
- # Base64 kodlu veriyi geri çöz ve resmi işle
13
- image_bytes = base64.b64decode(file_content)
14
- nparr = np.frombuffer(image_bytes, np.uint8)
15
- image = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
16
-
17
- # Burada OCR işlemini yapacak fonksiyonu çağırabilirsiniz, örneğin:
18
- # result = your_ocr_function(image)
19
-
20
- return {"filename": file_name, "size": len(file_content), "message": "OCR applied successfully"} # Burayı kendi işleminizle değiştirin
21
-
22
  @app.post("/uploadfile/")
23
- async def create_upload_file(base64_data: str):
24
  try:
25
  # Base64 veriyi bytes'a decode et
26
- file_content = base64.b64decode(base64_data)
27
 
28
  # OCR işlemini gerçekleştir
29
- result = "BAŞARILI"
30
 
31
  return result
32
  except Exception as e:
33
  raise HTTPException(status_code=500, detail=str(e))
34
 
35
- def is_image_file(file_content):
36
- # Gelen verinin bir resim dosyası olup olmadığını kontrol et
37
- try:
38
- image = Image.open(BytesIO(file_content))
39
- image.verify() # Resmi kontrol et
40
- return True
41
- except Exception:
42
- return False
 
 
 
 
 
 
 
1
  from fastapi import FastAPI, HTTPException
2
 
3
  app = FastAPI()
4
 
 
 
 
 
 
 
 
 
 
 
 
5
  @app.post("/uploadfile/")
6
+ async def create_upload_file(base64_data: dict):
7
  try:
8
  # Base64 veriyi bytes'a decode et
9
+ file_content = base64.b64decode(base64_data['base64_data'])
10
 
11
  # OCR işlemini gerçekleştir
12
+ result = "SUCCESS"
13
 
14
  return result
15
  except Exception as e:
16
  raise HTTPException(status_code=500, detail=str(e))
17