3morrrrr commited on
Commit
3c6ea42
·
verified ·
1 Parent(s): a5e2048

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -18
app.py CHANGED
@@ -1,44 +1,66 @@
1
- import gradio as gr
2
- import logging
3
- from roboflow import Roboflow
4
- from PIL import Image, ImageOps, ImageDraw
5
  import cv2
 
 
 
 
6
  import numpy as np
7
- import os
8
  from math import atan2, degrees
 
 
9
  from gradio_client import Client
10
- import tempfile
11
- import shutil
12
- import time
 
 
13
  Client.clear_cache()
14
 
15
- # Configure logging
 
 
16
  logging.basicConfig(
17
  level=logging.DEBUG,
18
- format='%(asctime)s - %(levelname)s - %(message)s',
19
  handlers=[
20
- logging.FileHandler("debug.log"),
21
  logging.StreamHandler()
22
  ]
23
  )
24
 
 
25
  # Roboflow configuration
26
- ROBOFLOW_API_KEY = "JKuvVbqDgv4mBdVM0fUE"
 
27
  PROJECT_NAME = "model_verification_project"
28
  VERSION_NUMBER = 2
29
 
30
- # Handwriting model configuration
 
 
 
 
 
31
  HANDWRITING_MODEL_ENDPOINT = "3morrrrr/Handwriting_Model_Inf"
32
 
33
- # Text sizing configuration
34
- MIN_WIDTH_PERCENTAGE = 0.8 # Increased from 0.7 to 0.8
35
- TEXT_SCALE_FACTOR = 1.2 # Increased from 1.2 to 1.5
 
 
36
 
37
- # Debug flag
 
 
38
  DEBUG = True
39
- DEBUG_DIR = "/tmp/debug_images"
40
  os.makedirs(DEBUG_DIR, exist_ok=True)
41
 
 
 
 
 
 
42
  # Function to format text to fit within paper boundaries
43
  def format_text_for_paper(text, paper_width, char_limit=None):
44
  """
 
1
+ import os
 
 
 
2
  import cv2
3
+ import time
4
+ import shutil
5
+ import logging
6
+ import tempfile
7
  import numpy as np
 
8
  from math import atan2, degrees
9
+ from PIL import Image, ImageOps, ImageDraw
10
+ from roboflow import Roboflow
11
  from gradio_client import Client
12
+ import gradio as gr
13
+
14
+ # -------------------------------------------------------------------------
15
+ # Clear old Gradio client cache (prevents "No API found" errors)
16
+ # -------------------------------------------------------------------------
17
  Client.clear_cache()
18
 
19
+ # -------------------------------------------------------------------------
20
+ # Logging configuration
21
+ # -------------------------------------------------------------------------
22
  logging.basicConfig(
23
  level=logging.DEBUG,
24
+ format="%(asctime)s - %(levelname)s - %(message)s",
25
  handlers=[
26
+ logging.FileHandler("debug.log", mode="a", encoding="utf-8"),
27
  logging.StreamHandler()
28
  ]
29
  )
30
 
31
+ # -------------------------------------------------------------------------
32
  # Roboflow configuration
33
+ # -------------------------------------------------------------------------
34
+ ROBOFLOW_API_KEY = "JKuvVbqDgv4mBdVM0fUE" # ✅ your correct key
35
  PROJECT_NAME = "model_verification_project"
36
  VERSION_NUMBER = 2
37
 
38
+ # Optional: force environment variable to override cached API key
39
+ os.environ["ROBOFLOW_API_KEY"] = ROBOFLOW_API_KEY
40
+
41
+ # -------------------------------------------------------------------------
42
+ # Handwriting model (Hugging Face Space) configuration
43
+ # -------------------------------------------------------------------------
44
  HANDWRITING_MODEL_ENDPOINT = "3morrrrr/Handwriting_Model_Inf"
45
 
46
+ # -------------------------------------------------------------------------
47
+ # Text and sizing configuration
48
+ # -------------------------------------------------------------------------
49
+ MIN_WIDTH_PERCENTAGE = 0.8 # minimum scaling for text width
50
+ TEXT_SCALE_FACTOR = 1.2 # base scale factor for text resizing
51
 
52
+ # -------------------------------------------------------------------------
53
+ # Debugging setup
54
+ # -------------------------------------------------------------------------
55
  DEBUG = True
56
+ DEBUG_DIR = os.path.join(tempfile.gettempdir(), "debug_images")
57
  os.makedirs(DEBUG_DIR, exist_ok=True)
58
 
59
+ logging.info(f"Debug images will be stored in: {DEBUG_DIR}")
60
+ logging.info(f"Using Roboflow project '{PROJECT_NAME}' (v{VERSION_NUMBER}) with API key ending in {ROBOFLOW_API_KEY[-4:]}")
61
+ logging.info(f"Using handwriting model endpoint: {HANDWRITING_MODEL_ENDPOINT}")
62
+
63
+
64
  # Function to format text to fit within paper boundaries
65
  def format_text_for_paper(text, paper_width, char_limit=None):
66
  """