broadfield-dev commited on
Commit
17a8ae1
·
verified ·
1 Parent(s): dc24da7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -6,7 +6,7 @@ import pytesseract
6
  from PIL import Image
7
  import io
8
  import os
9
- from huggingface_hub import HfApi, create_repo
10
  import re
11
  from datetime import datetime
12
  import urllib.parse
@@ -36,6 +36,7 @@ def ensure_hf_dataset():
36
  """Create or get Hugging Face dataset repository."""
37
  try:
38
  repo_id = create_repo(repo_id=REPO_NAME, token=HF_TOKEN, repo_type="dataset", exist_ok=True)
 
39
  return repo_id
40
  except Exception as e:
41
  logger.error(f"Error creating dataset repo: {str(e)}")
@@ -61,6 +62,7 @@ def upload_image_to_hf(image, filename):
61
  token=HF_TOKEN
62
  )
63
  os.remove(temp_path)
 
64
  return file_url
65
  except Exception as e:
66
  logger.error(f"Error uploading image: {str(e)}")
@@ -187,4 +189,5 @@ iface = gr.Interface(
187
  )
188
 
189
  if __name__ == "__main__":
190
- iface.launch()
 
 
6
  from PIL import Image
7
  import io
8
  import os
9
+ from huggingface_hub import HfApi, create_repo, RepositoryNotFoundError
10
  import re
11
  from datetime import datetime
12
  import urllib.parse
 
36
  """Create or get Hugging Face dataset repository."""
37
  try:
38
  repo_id = create_repo(repo_id=REPO_NAME, token=HF_TOKEN, repo_type="dataset", exist_ok=True)
39
+ logger.info(f"Using dataset repo: {repo_id}")
40
  return repo_id
41
  except Exception as e:
42
  logger.error(f"Error creating dataset repo: {str(e)}")
 
62
  token=HF_TOKEN
63
  )
64
  os.remove(temp_path)
65
+ logger.info(f"Uploaded image to: {file_url}")
66
  return file_url
67
  except Exception as e:
68
  logger.error(f"Error uploading image: {str(e)}")
 
189
  )
190
 
191
  if __name__ == "__main__":
192
+ # In Hugging Face Spaces, share=False is sufficient as Spaces handles the server
193
+ iface.launch(share=False)