CodeChamp95 commited on
Commit
de0a94c
Β·
verified Β·
1 Parent(s): bc634e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -2
app.py CHANGED
@@ -14,6 +14,25 @@ import gradio as gr
14
  import gradio.blocks as _gr_blocks
15
  _gr_blocks.Blocks.get_api_info = lambda self, *a, **kw: {}
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  import pandas as pd
18
  import json
19
  from pathlib import Path
@@ -620,7 +639,7 @@ def build_app():
620
  # Entry point
621
  # ──────────────────────────────────────────────────────────────────────────────
622
 
623
- # Build the app at module level so HuggingFace Spaces can import it correctly.
624
  # The `if __name__ == "__main__"` guard prevented launch() from running on Spaces
625
  # because HF imports app.py rather than executing it as a script.
626
  app = build_app()
@@ -629,7 +648,7 @@ _on_spaces = os.environ.get("SPACE_ID") is not None
629
  app.launch(
630
  server_name="0.0.0.0",
631
  server_port=7860,
632
- share=_on_spaces, # True on HF Spaces (localhost blocked), False locally
633
  show_error=True,
634
  prevent_thread_lock=True, # stops Gradio pinging localhost β€” needed on HF Spaces
635
  )
 
14
  import gradio.blocks as _gr_blocks
15
  _gr_blocks.Blocks.get_api_info = lambda self, *a, **kw: {}
16
 
17
+ # ── Patch for Starlette 1.0.0 TemplateResponse signature change ──────────────
18
+ import starlette.templating
19
+
20
+ _original_template_response = starlette.templating.Jinja2Templates.TemplateResponse
21
+
22
+ def _patched_template_response(self, *args, **kwargs):
23
+ # If Gradio calls it the old positional way: TemplateResponse("name.html", {"request": ...})
24
+ if len(args) >= 2 and isinstance(args[0], str) and isinstance(args[1], dict):
25
+ name, context = args[0], args[1]
26
+ request = context.get("request")
27
+ # Route it to the new signature explicitly
28
+ return _original_template_response(self, request=request, name=name, context=context, **kwargs)
29
+
30
+ # Otherwise, pass through normally
31
+ return _original_template_response(self, *args, **kwargs)
32
+
33
+ starlette.templating.Jinja2Templates.TemplateResponse = _patched_template_response
34
+
35
+
36
  import pandas as pd
37
  import json
38
  from pathlib import Path
 
639
  # Entry point
640
  # ──────────────────────────────────────────────────────────────────────────────
641
 
642
+ # Build the app at module level so Hugging Face Spaces can import it correctly.
643
  # The `if __name__ == "__main__"` guard prevented launch() from running on Spaces
644
  # because HF imports app.py rather than executing it as a script.
645
  app = build_app()
 
648
  app.launch(
649
  server_name="0.0.0.0",
650
  server_port=7860,
651
+ share=False, # Disabled share to prevent the Hugging Face warning
652
  show_error=True,
653
  prevent_thread_lock=True, # stops Gradio pinging localhost β€” needed on HF Spaces
654
  )