daviddwlee84 commited on
Commit
ae15419
·
1 Parent(s): c8b4b8f

Fix the launch queue

Browse files
.specstory/history/2025-03-27_10-40-gradio-code-update-and-error-fix.md CHANGED
@@ -117,6 +117,163 @@ _**Assistant**_
117
 
118
  I've updated the code by replacing the deprecated `allow_flagging=False` parameter with the new `flagging_mode="never"` parameter. The newer versions of Gradio have replaced the boolean flag with a more flexible string parameter that supports different flagging modes: 'auto', 'manual', or 'never'.
119
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  ---
121
 
122
 
 
117
 
118
  I've updated the code by replacing the deprecated `allow_flagging=False` parameter with the new `flagging_mode="never"` parameter. The newer versions of Gradio have replaced the boolean flag with a more flexible string parameter that supports different flagging modes: 'auto', 'manual', or 'never'.
119
 
120
+ ---
121
+
122
+ _**User**_
123
+
124
+ Here is another error
125
+
126
+ ```
127
+ Traceback (most recent call last):
128
+ File "/home/user/app/app.py", line 116, in <module>
129
+ demo.launch(enable_queue=True, debug=True)
130
+ TypeError: Blocks.launch() got an unexpected keyword argument 'enable_queue'
131
+ ```
132
+
133
+ ---
134
+
135
+ _**Assistant**_
136
+
137
+
138
+
139
+ ---
140
+
141
+ ```diff
142
+
143
+ if __name__ == "__main__":
144
+ - demo.launch(enable_queue=True, debug=True)
145
+ + demo.launch(queue=True, debug=True)
146
+
147
+ ```
148
+
149
+ ---
150
+
151
+ I've updated the code by replacing the deprecated `enable_queue=True` parameter with `queue=True`. In Gradio 5.23.1, the parameter name was changed from `enable_queue` to simply `queue`.
152
+
153
+ ---
154
+
155
+ _**User**_
156
+
157
+ I'm not sure is the queue exist?
158
+
159
+ @blocks.py
160
+ ```py
161
+ def launch(
162
+ self,
163
+ inline: bool | None = None,
164
+ inbrowser: bool = False,
165
+ share: bool | None = None,
166
+ debug: bool = False,
167
+ max_threads: int = 40,
168
+ auth: (
169
+ Callable[[str, str], bool] | tuple[str, str] | list[tuple[str, str]] | None
170
+ ) = None,
171
+ auth_message: str | None = None,
172
+ prevent_thread_lock: bool = False,
173
+ show_error: bool = False,
174
+ server_name: str | None = None,
175
+ server_port: int | None = None,
176
+ *,
177
+ height: int = 500,
178
+ width: int | str = "100%",
179
+ favicon_path: str | None = None,
180
+ ssl_keyfile: str | None = None,
181
+ ssl_certfile: str | None = None,
182
+ ssl_keyfile_password: str | None = None,
183
+ ssl_verify: bool = True,
184
+ quiet: bool = False,
185
+ show_api: bool = not wasm_utils.IS_WASM,
186
+ allowed_paths: list[str] | None = None,
187
+ blocked_paths: list[str] | None = None,
188
+ root_path: str | None = None,
189
+ app_kwargs: dict[str, Any] | None = None,
190
+ state_session_capacity: int = 10000,
191
+ share_server_address: str | None = None,
192
+ share_server_protocol: Literal["http", "https"] | None = None,
193
+ share_server_tls_certificate: str | None = None,
194
+ auth_dependency: Callable[[fastapi.Request], str | None] | None = None,
195
+ max_file_size: str | int | None = None,
196
+ enable_monitoring: bool | None = None,
197
+ strict_cors: bool = True,
198
+ node_server_name: str | None = None,
199
+ node_port: int | None = None,
200
+ ssr_mode: bool | None = None,
201
+ pwa: bool | None = None,
202
+ _frontend: bool = True,
203
+ ) -> tuple[App, str, str]:
204
+ """
205
+ Launches a simple web server that serves the demo. Can also be used to create a
206
+ public link used by anyone to access the demo from their browser by setting share=True.
207
+ Parameters:
208
+ inline: whether to display in the gradio app inline in an iframe. Defaults to True in python notebooks; False otherwise.
209
+ inbrowser: whether to automatically launch the gradio app in a new tab on the default browser.
210
+ share: whether to create a publicly shareable link for the gradio app. Creates an SSH tunnel to make your UI accessible from anywhere. If not provided, it is set to False by default every time, except when running in Google Colab. When localhost is not accessible (e.g. Google Colab), setting share=False is not supported. Can be set by environment variable GRADIO_SHARE=True.
211
+ debug: if True, blocks the main thread from running. If running in Google Colab, this is needed to print the errors in the cell output.
212
+ auth: If provided, username and password (or list of username-password tuples) required to access app. Can also provide function that takes username and password and returns True if valid login.
213
+ auth_message: If provided, HTML message provided on login page.
214
+ prevent_thread_lock: By default, the gradio app blocks the main thread while the server is running. If set to True, the gradio app will not block and the gradio server will terminate as soon as the script finishes.
215
+ show_error: If True, any errors in the gradio app will be displayed in an alert modal and printed in the browser console log
216
+ server_port: will start gradio app on this port (if available). Can be set by environment variable GRADIO_SERVER_PORT. If None, will search for an available port starting at 7860.
217
+ server_name: to make app accessible on local network, set this to "0.0.0.0". Can be set by environment variable GRADIO_SERVER_NAME. If None, will use "127.0.0.1".
218
+ max_threads: the maximum number of total threads that the Gradio app can generate in parallel. The default is inherited from the starlette library (currently 40).
219
+ width: The width in pixels of the iframe element containing the gradio app (used if inline=True)
220
+ height: The height in pixels of the iframe element containing the gradio app (used if inline=True)
221
+ favicon_path: If a path to a file (.png, .gif, or .ico) is provided, it will be used as the favicon for the web page.
222
+ ssl_keyfile: If a path to a file is provided, will use this as the private key file to create a local server running on https.
223
+ ssl_certfile: If a path to a file is provided, will use this as the signed certificate for https. Needs to be provided if ssl_keyfile is provided.
224
+ ssl_keyfile_password: If a password is provided, will use this with the ssl certificate for https.
225
+ ssl_verify: If False, skips certificate validation which allows self-signed certificates to be used.
226
+ quiet: If True, suppresses most print statements.
227
+ show_api: If True, shows the api docs in the footer of the app. Default True.
228
+ allowed_paths: List of complete filepaths or parent directories that gradio is allowed to serve. Must be absolute paths. Warning: if you provide directories, any files in these directories or their subdirectories are accessible to all users of your app. Can be set by comma separated environment variable GRADIO_ALLOWED_PATHS. These files are generally assumed to be secure and will be displayed in the browser when possible.
229
+ blocked_paths: List of complete filepaths or parent directories that gradio is not allowed to serve (i.e. users of your app are not allowed to access). Must be absolute paths. Warning: takes precedence over `allowed_paths` and all other directories exposed by Gradio by default. Can be set by comma separated environment variable GRADIO_BLOCKED_PATHS.
230
+ root_path: The root path (or "mount point") of the application, if it's not served from the root ("/") of the domain. Often used when the application is behind a reverse proxy that forwards requests to the application. For example, if the application is served at "https://example.com/myapp", the `root_path` should be set to "/myapp". A full URL beginning with http:// or https:// can be provided, which will be used as the root path in its entirety. Can be set by environment variable GRADIO_ROOT_PATH. Defaults to "".
231
+ app_kwargs: Additional keyword arguments to pass to the underlying FastAPI app as a dictionary of parameter keys and argument values. For example, `{"docs_url": "/docs"}`
232
+ state_session_capacity: The maximum number of sessions whose information to store in memory. If the number of sessions exceeds this number, the oldest sessions will be removed. Reduce capacity to reduce memory usage when using gradio.State or returning updated components from functions. Defaults to 10000.
233
+ share_server_address: Use this to specify a custom FRP server and port for sharing Gradio apps (only applies if share=True). If not provided, will use the default FRP server at https://gradio.live. See https://github.com/huggingface/frp for more information.
234
+ share_server_protocol: Use this to specify the protocol to use for the share links. Defaults to "https", unless a custom share_server_address is provided, in which case it defaults to "http". If you are using a custom share_server_address and want to use https, you must set this to "https".
235
+ share_server_tls_certificate: The path to a TLS certificate file to use when connecting to a custom share server. This parameter is not used with the default FRP server at https://gradio.live. Otherwise, you must provide a valid TLS certificate file (e.g. a "cert.pem") relative to the current working directory, or the connection will not use TLS encryption, which is insecure.
236
+ auth_dependency: A function that takes a FastAPI request and returns a string user ID or None. If the function returns None for a specific request, that user is not authorized to access the app (they will see a 401 Unauthorized response). To be used with external authentication systems like OAuth. Cannot be used with `auth`.
237
+ max_file_size: The maximum file size in bytes that can be uploaded. Can be a string of the form "<value><unit>", where value is any positive integer and unit is one of "b", "kb", "mb", "gb", "tb". If None, no limit is set.
238
+ enable_monitoring: Enables traffic monitoring of the app through the /monitoring endpoint. By default is None, which enables this endpoint. If explicitly True, will also print the monitoring URL to the console. If False, will disable monitoring altogether.
239
+ strict_cors: If True, prevents external domains from making requests to a Gradio server running on localhost. If False, allows requests to localhost that originate from localhost but also, crucially, from "null". This parameter should normally be True to prevent CSRF attacks but may need to be False when embedding a *locally-running Gradio app* using web components.
240
+ ssr_mode: If True, the Gradio app will be rendered using server-side rendering mode, which is typically more performant and provides better SEO, but this requires Node 20+ to be installed on the system. If False, the app will be rendered using client-side rendering mode. If None, will use GRADIO_SSR_MODE environment variable or default to False.
241
+ pwa: If True, the Gradio app will be set up as an installable PWA (Progressive Web App). If set to None (default behavior), then the PWA feature will be enabled if this Gradio app is launched on Spaces, but not otherwise.
242
+ Returns:
243
+ app: FastAPI app object that is running the demo
244
+ local_url: Locally accessible link to the demo
245
+ share_url: Publicly accessible link to the demo (if share=True, otherwise None)
246
+ Example: (Blocks)
247
+ import gradio as gr
248
+ def reverse(text):
249
+ return text[::-1]
250
+ with gr.Blocks() as demo:
251
+ button = gr.Button(value="Reverse")
252
+ button.click(reverse, gr.Textbox(), gr.Textbox())
253
+ demo.launch(share=True, auth=("username", "password"))
254
+ Example: (Interface)
255
+ import gradio as gr
256
+ def reverse(text):
257
+ return text[::-1]
258
+ demo = gr.Interface(reverse, "text", "text")
259
+ demo.launch(share=True, auth=("username", "password"))
260
+ """
261
+ ```
262
+
263
+ ---
264
+
265
+ _**Assistant**_
266
+
267
+
268
+
269
+ ---
270
+
271
+ Cancelled
272
+
273
+ ---
274
+
275
+
276
+
277
  ---
278
 
279
 
app.py CHANGED
@@ -113,4 +113,5 @@ demo = gr.Interface(
113
  )
114
 
115
  if __name__ == "__main__":
116
- demo.launch(enable_queue=True, debug=True)
 
 
113
  )
114
 
115
  if __name__ == "__main__":
116
+ demo.queue()
117
+ demo.launch(debug=True)