Spaces:
Runtime error
Runtime error
removed a bug in changeClueFormat
Browse files- extractpuzzle.py +1 -0
- main.py +11 -12
extractpuzzle.py
CHANGED
|
@@ -7,6 +7,7 @@ import re
|
|
| 7 |
|
| 8 |
|
| 9 |
pytesseract.pytesseract.tesseract_cmd = "/usr/bin/tesseract"
|
|
|
|
| 10 |
|
| 11 |
def first_preprocessing(image):
|
| 12 |
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
|
|
|
|
| 7 |
|
| 8 |
|
| 9 |
pytesseract.pytesseract.tesseract_cmd = "/usr/bin/tesseract"
|
| 10 |
+
pytesseract.pytesseract.tesseract_cmd = "C:/Program Files/Tesseract-OCR/tesseract.exe"
|
| 11 |
|
| 12 |
def first_preprocessing(image):
|
| 13 |
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
|
main.py
CHANGED
|
@@ -18,19 +18,17 @@ app.add_middleware(
|
|
| 18 |
allow_credentials=True,
|
| 19 |
)
|
| 20 |
|
| 21 |
-
def changeClueFormat(data):
|
| 22 |
-
returnArr = []
|
| 23 |
-
for key,value in data.items():
|
| 24 |
-
print(key[:-1]+" "+value[1])
|
| 25 |
-
|
| 26 |
-
return returnArr
|
| 27 |
-
|
| 28 |
-
|
| 29 |
@app.get("/")
|
| 30 |
async def index():
|
| 31 |
return {"message": "Hello World"}
|
| 32 |
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
@app.post("/parseImage/")
|
| 35 |
async def upload(file: UploadFile = File(...)):
|
| 36 |
|
|
@@ -50,9 +48,9 @@ async def upload(file: UploadFile = File(...)):
|
|
| 50 |
grid_data = {}
|
| 51 |
clue_data = {
|
| 52 |
'clues':{
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
}
|
| 57 |
|
| 58 |
try: # try extracting the grid from the image
|
|
@@ -65,9 +63,10 @@ async def upload(file: UploadFile = File(...)):
|
|
| 65 |
|
| 66 |
try: # try extracting clues
|
| 67 |
acrossClues, downClues = get_text(img_array) # { number : [column_of_projection_profile,extracted_text]}
|
|
|
|
| 68 |
clue_data['clues']['across'] = changeClueFormat(acrossClues)
|
| 69 |
clue_data['clues']['down'] = changeClueFormat(downClues)
|
| 70 |
-
|
| 71 |
except Exception as e:
|
| 72 |
grid_data['ClueExtractionStatus'] = "Failed"
|
| 73 |
|
|
|
|
| 18 |
allow_credentials=True,
|
| 19 |
)
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
@app.get("/")
|
| 22 |
async def index():
|
| 23 |
return {"message": "Hello World"}
|
| 24 |
|
| 25 |
|
| 26 |
+
def changeClueFormat(data):
|
| 27 |
+
returnArr = []
|
| 28 |
+
for key,value in data.items():
|
| 29 |
+
returnArr.append(str(key)[:-1]+" "+value[1])
|
| 30 |
+
return returnArr
|
| 31 |
+
|
| 32 |
@app.post("/parseImage/")
|
| 33 |
async def upload(file: UploadFile = File(...)):
|
| 34 |
|
|
|
|
| 48 |
grid_data = {}
|
| 49 |
clue_data = {
|
| 50 |
'clues':{
|
| 51 |
+
'across':[],
|
| 52 |
+
'down':[]
|
| 53 |
+
}
|
| 54 |
}
|
| 55 |
|
| 56 |
try: # try extracting the grid from the image
|
|
|
|
| 63 |
|
| 64 |
try: # try extracting clues
|
| 65 |
acrossClues, downClues = get_text(img_array) # { number : [column_of_projection_profile,extracted_text]}
|
| 66 |
+
print(changeClueFormat(acrossClues))
|
| 67 |
clue_data['clues']['across'] = changeClueFormat(acrossClues)
|
| 68 |
clue_data['clues']['down'] = changeClueFormat(downClues)
|
| 69 |
+
grid_data['ClueExtractionStatus'] = "Passed"
|
| 70 |
except Exception as e:
|
| 71 |
grid_data['ClueExtractionStatus'] = "Failed"
|
| 72 |
|