ramonsj11 commited on
Commit
7fab552
Β·
verified Β·
1 Parent(s): 6bfcfea

deploy: automated upload via deploy_to_hf.py

Browse files
Files changed (1) hide show
  1. app_optimized.py +21 -3
app_optimized.py CHANGED
@@ -24,9 +24,12 @@ from pathlib import Path
24
  import faiss
25
  import gradio as gr
26
 
27
- # ── Patch gradio_client 0.6.x: bool JSON-Schema values cause TypeError ────────
28
  import gradio_client.utils as _gcu
29
 
 
 
 
30
  def _safe_get_type(schema):
31
  if not isinstance(schema, dict):
32
  return "Any"
@@ -37,10 +40,25 @@ def _safe_jstpt(schema, defs=None):
37
  return "Any"
38
  return _orig_jstpt(schema, defs)
39
 
40
- _orig_get_type = _gcu.get_type
41
- _orig_jstpt = _gcu._json_schema_to_python_type
42
  _gcu.get_type = _safe_get_type
43
  _gcu._json_schema_to_python_type = _safe_jstpt
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  # ─────────────────────────────────────────────────────────────────────────────
45
 
46
  import pandas as pd
 
24
  import faiss
25
  import gradio as gr
26
 
27
+ # ── Patch 1: gradio_client 0.6.x β€” bool JSON-Schema values cause TypeError ───
28
  import gradio_client.utils as _gcu
29
 
30
+ _orig_get_type = _gcu.get_type
31
+ _orig_jstpt = _gcu._json_schema_to_python_type
32
+
33
  def _safe_get_type(schema):
34
  if not isinstance(schema, dict):
35
  return "Any"
 
40
  return "Any"
41
  return _orig_jstpt(schema, defs)
42
 
 
 
43
  _gcu.get_type = _safe_get_type
44
  _gcu._json_schema_to_python_type = _safe_jstpt
45
+
46
+ # ── Patch 2: Starlette >=1.0 changed TemplateResponse(name, ctx) β†’ (req, name) ─
47
+ import starlette.templating as _st
48
+
49
+ _orig_TemplateResponse = _st.Jinja2Templates.TemplateResponse
50
+
51
+ def _compat_TemplateResponse(self, *args, **kwargs):
52
+ # Old API (Starlette <1.0): TemplateResponse(name: str, context: dict, ...)
53
+ # New API (Starlette >=1.0): TemplateResponse(request, name: str, context=...)
54
+ if args and isinstance(args[0], str):
55
+ name = args[0]
56
+ context = args[1] if len(args) > 1 else kwargs.pop("context", {})
57
+ request = context.get("request")
58
+ return _orig_TemplateResponse(self, request, name, context=context, **kwargs)
59
+ return _orig_TemplateResponse(self, *args, **kwargs)
60
+
61
+ _st.Jinja2Templates.TemplateResponse = _compat_TemplateResponse
62
  # ─────────────────────────────────────────────────────────────────────────────
63
 
64
  import pandas as pd