MikkoLipsanen commited on
Commit
df891fc
·
verified ·
1 Parent(s): 0ac1412

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -10
app.py CHANGED
@@ -19,6 +19,9 @@ REGION_MODEL_PATH = "Kansallisarkisto/court-records-region-detection"
19
  TROCR_PROCESSOR_PATH = "Kansallisarkisto/multicentury-htr-model-onnx"
20
  TROCR_MODEL_PATH = "Kansallisarkisto/multicentury-htr-model-onnx"
21
 
 
 
 
22
  login(token=os.getenv("HF_TOKEN"), add_to_git_credential=True)
23
 
24
  print(f"Is CUDA available: {torch.cuda.is_available()}")
@@ -85,12 +88,10 @@ def is_allowed_source(file_path):
85
  """
86
  Filter function to determine if a file source is allowed.
87
  """
88
- # Allowed paths for input images
89
- allowed_sources = ('https://astia.narc.fi', '/tmp/gradio')
90
  # Check allowed paths
91
- if file_path.startswith(allowed_sources):
92
  return True
93
- print(f"File path not explicitly allowed: {file_path}")
94
  return False
95
 
96
  async def get_filepath(request):
@@ -158,12 +159,12 @@ with gr.Blocks(theme=gr.themes.Monochrome(), title="Multicentury HTR Demo") as d
158
 
159
  async def run_pipeline(image, request: gr.Request):
160
  if request:
161
- print("=== Request Information ===")
162
- print(f"Request URL: {request.url}")
163
- print(f"Request method: {request.method}")
164
- print(f"Client host: {request.client.host}")
165
- print(f"Headers: {dict(request.headers)}")
166
- print(f"Query params: {dict(request.query_params)}")
167
  file_path = await get_filepath(request)
168
  # Only files from allowed sources are processed
169
  if not is_allowed_source(file_path):
 
19
  TROCR_PROCESSOR_PATH = "Kansallisarkisto/multicentury-htr-model-onnx"
20
  TROCR_MODEL_PATH = "Kansallisarkisto/multicentury-htr-model-onnx"
21
 
22
+ # Allowed source paths for input images
23
+ ALLOWED_SOURCES = ('https://astia.narc.fi', '/tmp/gradio')
24
+
25
  login(token=os.getenv("HF_TOKEN"), add_to_git_credential=True)
26
 
27
  print(f"Is CUDA available: {torch.cuda.is_available()}")
 
88
  """
89
  Filter function to determine if a file source is allowed.
90
  """
 
 
91
  # Check allowed paths
92
+ if file_path.startswith(ALLOWED_SOURCES):
93
  return True
94
+ print(f"File path not allowed: {file_path}")
95
  return False
96
 
97
  async def get_filepath(request):
 
159
 
160
  async def run_pipeline(image, request: gr.Request):
161
  if request:
162
+ #print("=== Request Information ===")
163
+ #print(f"Request URL: {request.url}")
164
+ #print(f"Request method: {request.method}")
165
+ #print(f"Client host: {request.client.host}")
166
+ #print(f"Headers: {dict(request.headers)}")
167
+ #print(f"Query params: {dict(request.query_params)}")
168
  file_path = await get_filepath(request)
169
  # Only files from allowed sources are processed
170
  if not is_allowed_source(file_path):