LiuZichen commited on
Commit
5c0f2ff
·
verified ·
1 Parent(s): cfb64d9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -13
app.py CHANGED
@@ -77,18 +77,22 @@ zerogpu_fix_js = """
77
 
78
  const originalFetch = window.fetch;
79
  window.fetch = async function(url, options) {
80
- if (!options) options = {};
81
- if (!options.headers) options.headers = {};
82
-
83
- const headerMap = headers instanceof Map ? headers : new Map(Object.entries(headers));
84
-
85
- headerMap.forEach((value, key) => {
86
- if (options.headers instanceof Headers) {
87
- options.headers.append(key, value);
88
- } else {
89
- options.headers[key] = value;
90
- }
91
- });
 
 
 
 
92
 
93
  return originalFetch(url, options);
94
  };
@@ -402,7 +406,8 @@ async def segmentation(request: Request):
402
  return {"error": str(e)}
403
 
404
  # Mount the Gradio app
405
- demo.queue(default_concurrency_limit=20, max_size=40)
 
406
  app = gr.mount_gradio_app(app, demo, path="/", root_path="/demo")
407
 
408
  if __name__ == "__main__":
 
77
 
78
  const originalFetch = window.fetch;
79
  window.fetch = async function(url, options) {
80
+ // Only inject headers for prediction requests to avoid rate limiting on heartbeats/static assets
81
+ // Gradio requests typically go to /queue/join, /api/predict, etc.
82
+ if (typeof url === 'string' && (url.includes('/queue/join') || url.includes('/call/') || url.includes('/api/'))) {
83
+ if (!options) options = {};
84
+ if (!options.headers) options.headers = {};
85
+
86
+ const headerMap = headers instanceof Map ? headers : new Map(Object.entries(headers));
87
+
88
+ headerMap.forEach((value, key) => {
89
+ if (options.headers instanceof Headers) {
90
+ options.headers.append(key, value);
91
+ } else {
92
+ options.headers[key] = value;
93
+ }
94
+ });
95
+ }
96
 
97
  return originalFetch(url, options);
98
  };
 
406
  return {"error": str(e)}
407
 
408
  # Mount the Gradio app
409
+ # Reduce concurrency for ZeroGPU to prevent rate limiting
410
+ demo.queue(default_concurrency_limit=10, max_size=20)
411
  app = gr.mount_gradio_app(app, demo, path="/", root_path="/demo")
412
 
413
  if __name__ == "__main__":