Fix template context injection in Starlette Jinja shim
Browse files
app.py
CHANGED
|
@@ -46,7 +46,25 @@ try:
|
|
| 46 |
return _original_get_template(self, template_name, *args, **kwargs)
|
| 47 |
return _original_get_template(self, name, *args, **kwargs)
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
Jinja2Templates.get_template = _safe_get_template
|
|
|
|
| 50 |
except Exception:
|
| 51 |
pass
|
| 52 |
|
|
|
|
| 46 |
return _original_get_template(self, template_name, *args, **kwargs)
|
| 47 |
return _original_get_template(self, name, *args, **kwargs)
|
| 48 |
|
| 49 |
+
_original_template_response = Jinja2Templates.TemplateResponse
|
| 50 |
+
|
| 51 |
+
def _safe_template_response(self, name, context=None, *args, **kwargs):
|
| 52 |
+
if isinstance(context, dict):
|
| 53 |
+
context = dict(context)
|
| 54 |
+
context.setdefault(
|
| 55 |
+
"config",
|
| 56 |
+
{
|
| 57 |
+
"body_css": {},
|
| 58 |
+
"title": "Hebrew OCR Document Comparator",
|
| 59 |
+
"simple_description": "Private OCR comparator for Hebrew documents",
|
| 60 |
+
"thumbnail": "",
|
| 61 |
+
},
|
| 62 |
+
)
|
| 63 |
+
context.setdefault("gradio_api_info", {})
|
| 64 |
+
return _original_template_response(self, name, context, *args, **kwargs)
|
| 65 |
+
|
| 66 |
Jinja2Templates.get_template = _safe_get_template
|
| 67 |
+
Jinja2Templates.TemplateResponse = _safe_template_response
|
| 68 |
except Exception:
|
| 69 |
pass
|
| 70 |
|