Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,44 +1,66 @@
|
|
| 1 |
-
import
|
| 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
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
| 13 |
Client.clear_cache()
|
| 14 |
|
| 15 |
-
#
|
|
|
|
|
|
|
| 16 |
logging.basicConfig(
|
| 17 |
level=logging.DEBUG,
|
| 18 |
-
format=
|
| 19 |
handlers=[
|
| 20 |
-
logging.FileHandler("debug.log"),
|
| 21 |
logging.StreamHandler()
|
| 22 |
]
|
| 23 |
)
|
| 24 |
|
|
|
|
| 25 |
# Roboflow configuration
|
| 26 |
-
|
|
|
|
| 27 |
PROJECT_NAME = "model_verification_project"
|
| 28 |
VERSION_NUMBER = 2
|
| 29 |
|
| 30 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
HANDWRITING_MODEL_ENDPOINT = "3morrrrr/Handwriting_Model_Inf"
|
| 32 |
|
| 33 |
-
#
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
#
|
|
|
|
|
|
|
| 38 |
DEBUG = True
|
| 39 |
-
DEBUG_DIR = "
|
| 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 |
"""
|