3morrrrr commited on
Commit
2889c49
·
verified ·
1 Parent(s): 777152b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -8
app.py CHANGED
@@ -11,18 +11,34 @@ from roboflow import Roboflow
11
  from gradio_client import Client
12
  import gradio as gr
13
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
- # --- Safely clear Gradio client cache (for older/newer versions) ---
 
 
 
 
16
  try:
17
  cache_dir = os.path.expanduser("~/.cache/gradio")
18
  if os.path.exists(cache_dir):
19
  shutil.rmtree(cache_dir)
20
  print("🧹 Cleared Gradio client cache manually.")
21
  except Exception as e:
22
- print(f"Warning: Could not clear Gradio cache ({e})")
23
 
24
  # -------------------------------------------------------------------------
25
- # Logging configuration
26
  # -------------------------------------------------------------------------
27
  logging.basicConfig(
28
  level=logging.DEBUG,
@@ -34,19 +50,19 @@ logging.basicConfig(
34
  )
35
 
36
  # -------------------------------------------------------------------------
37
- # Roboflow configuration
38
  # -------------------------------------------------------------------------
39
- ROBOFLOW_API_KEY = "JKuvVbqDgv4mBdVM0fUE" # ✅ your correct key
40
  PROJECT_NAME = "model_verification_project"
41
  VERSION_NUMBER = 2
42
 
43
- # Optional: force environment variable to override cached API key
44
  os.environ["ROBOFLOW_API_KEY"] = ROBOFLOW_API_KEY
45
 
46
  # -------------------------------------------------------------------------
47
- # Handwriting model (Hugging Face Space) configuration
48
  # -------------------------------------------------------------------------
49
- HANDWRITING_MODEL_ENDPOINT = "3morrrrr/Handwriting_Model_Inf"
50
 
51
  # -------------------------------------------------------------------------
52
  # Text and sizing configuration
 
11
  from gradio_client import Client
12
  import gradio as gr
13
 
14
+ # -------------------------------------------------------------------------
15
+ # 🧠 Fix for Gradio schema bug ("TypeError: argument of type 'bool' is not iterable")
16
+ # -------------------------------------------------------------------------
17
+ import gradio_client.utils as gu
18
+
19
+ def safe_get_type(schema):
20
+ """Patch Gradio internal schema handling to prevent bool-type crash."""
21
+ if not isinstance(schema, dict):
22
+ return type(schema).__name__
23
+ if "const" in schema:
24
+ return f"Literal[{schema['const']}]"
25
+ return schema.get("type", "any")
26
 
27
+ gu.get_type = safe_get_type
28
+
29
+ # -------------------------------------------------------------------------
30
+ # 🧹 Safely clear Gradio client cache (for all versions)
31
+ # -------------------------------------------------------------------------
32
  try:
33
  cache_dir = os.path.expanduser("~/.cache/gradio")
34
  if os.path.exists(cache_dir):
35
  shutil.rmtree(cache_dir)
36
  print("🧹 Cleared Gradio client cache manually.")
37
  except Exception as e:
38
+ print(f"⚠️ Warning: Could not clear Gradio cache ({e})")
39
 
40
  # -------------------------------------------------------------------------
41
+ # 🪵 Logging configuration
42
  # -------------------------------------------------------------------------
43
  logging.basicConfig(
44
  level=logging.DEBUG,
 
50
  )
51
 
52
  # -------------------------------------------------------------------------
53
+ # 🤖 Roboflow configuration
54
  # -------------------------------------------------------------------------
55
+ ROBOFLOW_API_KEY = "JKuvVbqDgv4mBdVM0fUE" # ✅ correct key
56
  PROJECT_NAME = "model_verification_project"
57
  VERSION_NUMBER = 2
58
 
59
+ # Force environment variable to override cached API key
60
  os.environ["ROBOFLOW_API_KEY"] = ROBOFLOW_API_KEY
61
 
62
  # -------------------------------------------------------------------------
63
+ # ✍️ Handwriting model (Hugging Face Space) configuration
64
  # -------------------------------------------------------------------------
65
+ HANDWRITING_MODEL_ENDPOINT = "3morrrrr/Handwriting_Model_In
66
 
67
  # -------------------------------------------------------------------------
68
  # Text and sizing configuration