fast microservice to accompany n8n workflow
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Update main.py

authored by

Jasper Mayone and committed by
GitHub
dad15da2 8fd6fdb3

+44 -9
+44 -9
main.py
··· 176 176 return schedule 177 177 178 178 @app.post("/ocr") 179 - async def ocr_endpoint(file: UploadFile = File(...)): 180 - image_bytes = await file.read() 181 - text = process_image(image_bytes) 182 - schedule = parse_schedule(text) 183 - 184 - return { 185 - "raw_text": text, 186 - "schedule": schedule 187 - } 179 + async def ocr_endpoint(file: Union[UploadFile, bytes] = File(...)): 180 + try: 181 + # If we got raw bytes 182 + if isinstance(file, bytes): 183 + image_bytes = file 184 + # If we got an UploadFile 185 + else: 186 + image_bytes = await file.read() 187 + 188 + # Process the image and get text 189 + text = process_image(image_bytes) 190 + 191 + # Parse the schedule 192 + schedule = parse_schedule(text) 193 + 194 + return { 195 + "raw_text": text, 196 + "schedule": schedule 197 + } 198 + except Exception as e: 199 + return {"error": str(e)}, 422 188 200 201 + @app.post("/ocr") 202 + async def ocr_endpoint(file: Union[UploadFile, bytes] = File(...)): 203 + try: 204 + # If we got raw bytes 205 + if isinstance(file, bytes): 206 + image_bytes = file 207 + # If we got an UploadFile 208 + else: 209 + image_bytes = await file.read() 210 + 211 + # Process the image and get text 212 + text = process_image(image_bytes) 213 + 214 + # Parse the schedule 215 + schedule = parse_schedule(text) 216 + 217 + return { 218 + "raw_text": text, 219 + "schedule": schedule 220 + } 221 + except Exception as e: 222 + return {"error": str(e)}, 422 223 + 189 224 if __name__ == "__main__": 190 225 import uvicorn 191 226 uvicorn.run(app, host="0.0.0.0", port=8000)