-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
46 lines (35 loc) · 957 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import cloudinary
import cloudinary.uploader
import cloudinary.api
import os
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from dotenv import load_dotenv
load_dotenv()
cloudinary.config(
cloud_name = "dwxlnnou1",
api_key = "978228329273535",
api_secret = os.getenv('API_SECRET'),
)
def up_image(url,name):
try:
response = cloudinary.uploader.upload(url, public_id=name, overwrite=True, ocr = "adv_ocr")
return response["info"]["ocr"]["adv_ocr"]["data"][0]["fullTextAnnotation"]["text"]
except Exception as error:
print("Error",error)
app = FastAPI()
origins = ["*"]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/")
def initial():
return { 'hello wold' }
@app.get("/api/cloudinary")
def read_root(url,name):
response = up_image(url,name)
return response