Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -77,18 +77,22 @@ zerogpu_fix_js = """
|
|
| 77 |
|
| 78 |
const originalFetch = window.fetch;
|
| 79 |
window.fetch = async function(url, options) {
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 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 |
-
|
|
|
|
| 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__":
|