Knightmovies commited on
Commit
94f0e33
·
verified ·
1 Parent(s): e41384c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -1
app.py CHANGED
@@ -48,4 +48,27 @@ def process_image_with_doctr(input_image_pil):
48
  final_image_bgr = cv2.cvtColor(final_image_rgb, cv2.COLOR_RGB_BGR)
49
 
50
  # Save to a temporary file for the download button
51
- with tempfile.NamedTemporaryFile(suffix=".jpg", delete=False) as
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  final_image_bgr = cv2.cvtColor(final_image_rgb, cv2.COLOR_RGB_BGR)
49
 
50
  # Save to a temporary file for the download button
51
+ with tempfile.NamedTemporaryFile(suffix=".jpg", delete=False) as tmp_file:
52
+ cv2.imwrite(tmp_file.name, final_image_bgr)
53
+ # Return the RGB image for Gradio display and the file path for download
54
+ return final_image_rgb, tmp_file.name
55
+
56
+ # ==============================================================================
57
+ # Gradio Interface
58
+ # ==============================================================================
59
+ demo = gr.Interface(
60
+ fn=process_image_with_doctr,
61
+ inputs=gr.Image(type="pil", label="Upload Document Photo"),
62
+ outputs=[
63
+ gr.Image(type="numpy", label="Corrected Document"),
64
+ gr.File(label="Download as JPG")
65
+ ],
66
+ title="📄 AI-Powered Document Scanner",
67
+ description="A robust, universal document scanner powered by the Doctr deep learning library. This tool correctly handles complex photos with skew, rotation, and varied backgrounds.",
68
+ # The `allow_flagging` parameter is deprecated. Using `flagging_options=None` is the modern equivalent.
69
+ # We remove the examples to prevent startup errors from network issues.
70
+ flagging_options=None
71
+ )
72
+
73
+ if __name__ == "__main__":
74
+ demo.launch()