
    +j.3                        d Z ddlmZ ddlZddlmZmZ ddlmZ ddl	m
Z
mZ ddlZddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ  G d d          Z edd           G d de                      ZdS )uG   Gradio Server mode — a FastAPI-based server with Gradio's API engine.    )annotationsN)CallableSequence)Path)AnyLiteral)document)mcp)I18n)App)
ThemeClassc                  r    e Zd ZdZ eej                  Z eej                  Z eej                  ZdS )_MCPNamespacez\Namespace for MCP decorators: server.mcp.tool(), server.mcp.resource(), server.mcp.prompt().N)	__name__
__module____qualname____doc__staticmethodr
   toolresourceprompt     Q/home/wildlama/visual-decline/.venv/lib/python3.11/site-packages/gradio/server.pyr   r      sG        ff<!!D|CL))H\#*%%FFFr   r   apilaunchc            %      
    e Zd ZdZdddddddddddd	d
ddddddddddddddddddd fd3Zedd6            Z	 dddd7dddd8d9dd:d;
ddLZ	 	 	 	 	 	 	 	 	 	 	 ddNdOddddddddddddPddddddddddddddddddddddQ#ddZ xZ	S )Servera  
    Server is the Gradio API engine exposed on a FastAPI application (Server mode).
    It inherits from FastAPI, so all standard FastAPI methods (.get(), .post(),
    .add_middleware(), .include_router(), etc.) work directly on this instance.

    New methods added on top of FastAPI:
        api(): Decorator to register a Gradio API endpoint with queue,
            SSE streaming, and concurrency control.
        mcp: Namespace with .tool(), .resource(), and .prompt() decorators
            to tag functions with MCP metadata.
        launch(): Creates an internal Blocks, registers deferred API
            endpoints, and starts the server.

    Example:
        from gradio import Server

        server = Server()

        @server.api(name="hello")
        def hello(name: str) -> str:
            return f"Hello {name}"

        @server.get("/")
        def root():
            return {"message": "Hello World"}

        server.launch()
    Demos: server_app
    Guides: server-mode
    FFastAPIN z0.1.0z/openapi.jsonTz/docsz/redoc)debugtitlesummarydescriptionversionopenapi_urlopenapi_tagsserversdependenciesdefault_response_classredirect_slashesdocs_url	redoc_url
middlewareexception_handlers
on_startupon_shutdownlifespanterms_of_servicecontactlicense_info	root_pathroot_path_in_servers	responses	callbackswebhooks
deprecatedinclude_in_schemagenerate_unique_id_functionseparate_input_output_schemasr!   boolr"   strr#   
str | Noner$   r%   r&   r'   list[dict[str, Any]] | Noner(   r)   r   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   dict[str, Any] | Noner5   r6   r7   r8   &dict[int | str, dict[str, Any]] | Noner9   r:   r;   bool | Noner<   r=   r>   extrac               t   i d|d|d|d|d|d|d|d|d	|d
|d|d|d|d|d|d|d||||d|} |	|	| d<   |
|
| d<   ||| d<   ||| d<   ||| d<   ||| d<   ||| d<   ||| d<   ||| d<   ||| d<    t                      j        di |  g | _        t                      | _        dS )a\  
        Parameters:
            debug: Enable debug mode for detailed error tracebacks.
            title: The title of the API, shown in the OpenAPI docs.
            summary: A short summary of the API.
            description: A longer description of the API. Supports Markdown.
            version: The version of the API.
            openapi_url: The URL path for the OpenAPI schema. Set to None to disable.
            openapi_tags: Tags for organizing endpoints in the OpenAPI docs.
            servers: Server URLs for the OpenAPI schema.
            dependencies: Global dependencies applied to all routes.
            default_response_class: The default response class for routes.
            redirect_slashes: Whether to redirect trailing slashes.
            docs_url: The URL path for the Swagger UI docs. Set to None to disable.
            redoc_url: The URL path for the ReDoc docs. Set to None to disable.
            middleware: List of middleware to add to the server.
            exception_handlers: Custom exception handlers.
            on_startup: List of startup event handlers. Prefer lifespan instead.
            on_shutdown: List of shutdown event handlers. Prefer lifespan instead.
            lifespan: An async context manager for startup/shutdown lifecycle.
            terms_of_service: URL to the terms of service.
            contact: Contact information dict for the API.
            license_info: License information dict for the API.
            root_path: A path prefix for the app when behind a proxy.
            root_path_in_servers: Whether to include root_path in the OpenAPI servers field.
            responses: Additional responses for the OpenAPI schema.
            callbacks: OpenAPI callback definitions.
            webhooks: OpenAPI webhook definitions.
            deprecated: Mark all routes as deprecated.
            include_in_schema: Whether to include all routes in the OpenAPI schema.
            generate_unique_id_function: Custom function to generate unique operation IDs.
            separate_input_output_schemas: Whether to generate separate input/output schemas.
        r!   r"   r#   r$   r%   r&   r'   r(   r+   r,   r-   r3   r4   r5   r6   r7   r8   )r;   r<   r>   Nr)   r*   r.   r/   r0   r1   r2   r9   r:   r=   r   )super__init___deferred_apisr   _mcp)"selfr!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   rF   init_kwargs	__class__s"                                    r   rI   zServer.__init__<   s   H'
U'
U'
 w'
 ;	'

 w'
 ;'
 L'
 w'
  0'
 '
 '
  0'
 w'
 L'
 '
  #$8!'
" #'
$ %!2-J)'
 '
 '
* +'
. #*6K'!-4JK01!(2K%)0BK,-!(2K%")4K&&.K
# '0K$&.K
#&29TK56'';'''EG!OO			r   returnr   c                    | j         S )zWMCP decorator namespace: server.mcp.tool(), server.mcp.resource(), server.mcp.prompt().)rK   )rL   s    r   r
   z
Server.mcp   s     yr   default   publicg      ?)
namer$   concurrency_limitconcurrency_idqueuebatchmax_batch_sizeapi_visibility
time_limitstream_everyfnCallable | NonerT   rU   int | None | Literal['default']rV   rW   rX   rY   intrZ   ,Literal['public', 'private', 'undocumented']r[   
int | Noner\   floatc       
        p     ||||||||	|
|d
| j                             |f           |S  fd}|S )zDecorator to register a function as a Gradio API endpoint.

        Goes through Gradio's queue with concurrency control and SSE streaming.
        )
api_nameapi_descriptionrU   rV   rW   rX   rY   rZ   r[   r\   Nc                @    j                             | f           | S NrJ   append)funckwargsrL   s    r   wrapperzServer.api.<locals>.wrapper   s#    &&f~666Kr   ri   )rL   r]   rT   r$   rU   rV   rW   rX   rY   rZ   r[   r\   rm   rl   s   `            @r   r   z
Server.api   s|    ( *!2,,,$(
 
 >&&F|444I	 	 	 	 	 	 r   (   i  z100%i'  )#heightwidthfavicon_pathssl_keyfilessl_certfilessl_keyfile_password
ssl_verifyquietfooter_linksallowed_pathsblocked_pathsr6   
app_kwargsstate_session_capacityshare_server_addressshare_server_protocolshare_server_tls_certificateauth_dependencymax_file_sizeenable_monitoringstrict_corsnode_server_name	node_portssr_modepwa
mcp_server	_frontendi18nthemecss	css_pathsjshead
head_pathsnum_workersinline	inbrowsersharemax_threadsauthKCallable[[str, str], bool] | tuple[str, str] | list[tuple[str, str]] | Noneauth_messageprevent_thread_lock
show_errorserver_nameserver_portro   rp   	int | strrq   str | Path | Nonerr   rs   rt   ru   rv   rw   Blist[Literal['api', 'gradio', 'settings'] | dict[str, str]] | Nonerx   list[str] | Nonery   rz   r{   r|   r}   Literal['http', 'https'] | Noner~   r   .Callable[[fastapi.Request], str | None] | Noner   str | int | Noner   r   r   r   r   r   r   r   r   I18n | Noner   Theme | str | Noner   r   (str | Path | Sequence[str | Path] | Noner   str | Literal[True] | Noner   r   r   tuple[App, str, str]c       #           ddl m}/ ddlm}0  |/d          5 }1| j        D ]\  }2}3 |0d9d|2i|3 	 ddd           n# 1 swxY w Y   dt
          j        d	<    |1j        d9i d
| d|d|d|d|d|d|d|d|d|	d|
d|d|d|d|d|d|d|d|d|d|d|d |d!|d"|d#|d$|d%|d&|d'|d(|d)|d*| d+|!d,|"d-|#d.|$d/|%d0|&d1|'d2|(d3|)d4|*d5|+d6|,d7|-d8|.S ):zLaunch the Gradio API server (Server mode).

        Parameters match ``Blocks.launch()``; see that method for full descriptions.

        Returns:
            Tuple of (fastapi_app, local_url, share_url).
        r   )Blocks)r   server)moder]   N1GRADIO_SERVER_MODE_ENABLED_appr   r   r   r!   r   r   r   r   r   r   r   ro   rp   rq   rr   rs   rt   ru   rv   rw   rx   ry   r6   rz   r{   r|   r}   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )gradio.blocksr   gradio.eventsr   rJ   osenvironr   )4rL   r   r   r   r!   r   r   r   r   r   r   r   ro   rp   rq   rr   rs   rt   ru   rv   rw   rx   ry   r6   rz   r{   r|   r}   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   gr_apiblocksr]   
api_kwargss4                                                       r   r   zServer.launch   sJ   x 	)(((((//////V""" 	,f"&"5 , ,J++"+
++++,	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 47
/0v} 0
 0
 0
0
60
  i0
 %	0

 %0
 $0
 0
 &0
 !4 30
 "z0
 $0
 $0
 60
 %0
 &0
  $!0
" &#0
$ "6!5%0
& "z'0
( %)0
* &+0
, (--0
. (-/0
0  i10
2 "z30
4 $:#950
6 "6!570
8 #8"790
: *F)E;0
< ,O=0
> (-?0
@ 0/A0
B $C0
D .-E0
F  iG0
H XI0
J K0
L "zM0
N  iO0
P Q0
R %S0
T U0
V  iW0
X rY0
Z [0
\ "z]0
^ $_0
 0	
s   >AA)>r!   r?   r"   r@   r#   rA   r$   r@   r%   r@   r&   rA   r'   rB   r(   rB   r)   r   r*   r   r+   r?   r,   rA   r-   rA   r.   r   r/   r   r0   r   r1   r   r2   r   r3   rA   r4   rC   r5   rC   r6   r@   r7   r?   r8   rD   r9   r   r:   r   r;   rE   r<   r?   r=   r   r>   r?   rF   r   )rO   r   rh   )r]   r^   rT   rA   r$   rA   rU   r_   rV   rA   rW   r?   rX   r?   rY   r`   rZ   ra   r[   rb   r\   rc   )NFNFrn   NNFFNN)^r   rE   r   r?   r   rE   r!   r?   r   r`   r   r   r   rA   r   r?   r   r?   r   rA   r   rb   ro   r`   rp   r   rq   r   rr   rA   rs   rA   rt   rA   ru   r?   rv   r?   rw   r   rx   r   ry   r   r6   rA   rz   rC   r{   r`   r|   rA   r}   r   r~   rA   r   r   r   r   r   rE   r   r?   r   rA   r   rb   r   rE   r   rE   r   rE   r   r?   r   r   r   r   r   rA   r   r   r   r   r   rA   r   r   r   rb   rO   r   )
r   r   r   r   rI   propertyr
   r   r   __classcell__)rN   s   @r   r   r      s        D ""148/3 &*!%& ("&'+)-.2%)<@"&"&+/.2Aq$ q$ q$ q$ q$ q$ q$ q$f    X #'  "&=F%)GO!%!' ' ' ' ' 'V #! #'$) "&"&u
  !*."&#'+/*.*. $,0&++/AE37JN*.)- '+ $ $"& $(>B)-?C"&gu
 u
 u
 u
 u
 u
 u
 u
 u
 u
r   r   )r   
__future__r   r   collections.abcr   r   pathlibr   typingr   r   fastapigradio_client.documentationr	   gradior
   gradio.i18nr   gradio.routesr   gradio.themesr   Themer   r   r   r   r   <module>r      sJ   M M " " " " " " 				 . . . . . . . .                0 0 0 0 0 0                   - - - - - -& & & & & & & & 
%v
 v
 v
 v
 v
S v
 v
 v
 v
 v
r   