Raymond Weitekamp commited on
Commit
91dd296
·
1 Parent(s): 3263046

fix: simplify webcam handling to fix mirroring issue

Browse files
Files changed (2) hide show
  1. app.py +9 -0
  2. requirements.txt +2 -1
app.py CHANGED
@@ -12,6 +12,7 @@ if gr.NO_RELOAD:
12
  import datasets
13
  import numpy as np # Added to help handle numpy array images
14
  import pandas as pd # Added for pandas DataFrame
 
15
 
16
  # Load environment variables from .env if available.
17
  from dotenv import load_dotenv
@@ -198,6 +199,13 @@ def strip_metadata(image: Image.Image) -> Image.Image:
198
  stripped_image.putdata(data)
199
  return stripped_image
200
 
 
 
 
 
 
 
 
201
  class UserState:
202
  def __init__(self):
203
  self.username = None
@@ -306,6 +314,7 @@ def create_gradio_interface():
306
  type="pil",
307
  label="Upload Handwritten Image",
308
  sources=["upload", "webcam"],
 
309
  visible=False,
310
  elem_id="image_input"
311
  )
 
12
  import datasets
13
  import numpy as np # Added to help handle numpy array images
14
  import pandas as pd # Added for pandas DataFrame
15
+ import cv2 # Added for OpenCV
16
 
17
  # Load environment variables from .env if available.
18
  from dotenv import load_dotenv
 
199
  stripped_image.putdata(data)
200
  return stripped_image
201
 
202
+ def transform_webcam(image: np.ndarray) -> np.ndarray:
203
+ """Transform webcam input to ensure text is readable"""
204
+ if image is None:
205
+ return None
206
+ # Flip the image horizontally to un-mirror it
207
+ return cv2.flip(image, 1)
208
+
209
  class UserState:
210
  def __init__(self):
211
  self.username = None
 
314
  type="pil",
315
  label="Upload Handwritten Image",
316
  sources=["upload", "webcam"],
317
+ mirror_webcam=False, # Keep webcam feed unmirrored so text is readable
318
  visible=False,
319
  elem_id="image_input"
320
  )
requirements.txt CHANGED
@@ -8,4 +8,5 @@ playwright>=1.40.0
8
  datasets>=2.16.0
9
  pydantic>=2.6.1
10
  python-dotenv>=1.0.0
11
- pandas>=2.0.0
 
 
8
  datasets>=2.16.0
9
  pydantic>=2.6.1
10
  python-dotenv>=1.0.0
11
+ pandas>=2.0.0
12
+ opencv-python>=4.9.0