ó
    ‚¤jÅ3  ã                  óÒ   • S r SSKJr  SSKrSSKJrJrJr  SSKJ	r	  SSK
JrJr  SSKrSSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr   " S S5      r\" SS5       " S S\5      5       rg)uG   Gradio Server mode â€” a FastAPI-based server with Gradio's API engine.é    )ÚannotationsN)Ú	AwaitableÚCallableÚSequence)ÚPath)ÚAnyÚLiteral)Údocument)Úmcp)ÚI18n)ÚApp)Ú
ThemeClassc                  ó„   • \ rS rSrSr\" \R                  5      r\" \R                  5      r\" \R                  5      r	Sr
g)Ú_MCPNamespaceé   z\Namespace for MCP decorators: server.mcp.tool(), server.mcp.resource(), server.mcp.prompt().© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ústaticmethodr   ÚtoolÚresourceÚpromptÚ__static_attributes__r   ó    Ú›C:\Users\johnn\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\gradio/server.pyr   r      s/   † Ùfá˜Ÿ™Ó!€DÙ˜CŸL™LÓ)€HÙ˜#Ÿ*™*Ó%ƒFr   r   ÚapiÚlaunchc            &      ó„  ^ • \ rS rSrSrSSSSSSSSSSS	S
SSSSSSSSSSS	SSSSS	SS	S.                                                             SU 4S jjjr\SS j5       r SSSSSS	SSSSSS.
                     SS jjjr           SSSSSSSS	SSSSSSSSSSSSSSS	SSSSSS	SSSSSSSSS.$                                                                                               S S jjjr	Sr
U =r$ )!ÚServeré   a‰  
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_schemasc               ól  >• 0 SU_SU_SU_SU_SU_SU_SU_SU_S	U_S
U_SU_SU_SU_SU_SU_SU_SU_UUUS.EUEn U	b  U	U S'   U
b  U
U S'   Ub  UU S'   Ub  UU S'   Ub  UU S'   Ub  UU S'   Ub  UU S'   Ub  UU S'   Ub  UU S'   Ub  UU S'   [         T!U ]  " S0 U D6  / U l        [        5       U l        g)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-   r0   r1   r2   r8   r9   r:   r;   r<   r=   )r@   rA   rC   Nr.   r/   r3   r4   r5   r6   r7   r>   r?   rB   r   )ÚsuperÚ__init__Ú_deferred_apisr   Ú_mcp)"Úselfr&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   ÚextraÚinit_kwargsÚ	__class__s"                                    €r   rF   ÚServer.__init__<   s¶  ø€ ðH'
Ø�Uð'
à�Uð'
ð �wð'
ð ˜;ð	'
ð
 �wð'
ð ˜;ð'
ð ˜Lð'
ð �wð'
ð Ð 0ð'
ð ˜ð'
ð ˜ð'
ð Ð 0ð'
ð �wð'
ð ˜Lð'
ð ˜ð'
ð  #Ð$8ð!'
ð" ˜ð#'
ð$ %Ø!2Ø-Jò)'
ð* ð+'
ˆð. Ñ#Ø*6ˆK˜Ñ'Ø!Ñ-Ø4JˆKÐ0Ñ1ØÑ!Ø(2ˆK˜Ñ%ØÑ)Ø0BˆKÐ,Ñ-ØÑ!Ø(2ˆK˜Ñ%ØÑ"Ø)4ˆK˜Ñ&ØÑØ&.ˆK˜
Ñ#ØÑ Ø'0ˆK˜Ñ$ØÑØ&.ˆK˜
Ñ#Ø&Ñ2Ø9TˆKÐ5Ñ6Ü‰ÒÑ'˜;Ò'ØEGˆÔÜ!“Oˆ�	r   c                ó   • U R                   $ )zWMCP decorator namespace: server.mcp.tool(), server.mcp.resource(), server.mcp.prompt().)rH   )rI   s    r   r   Ú
Server.mcp¯   s   € ð �y‰yÐr   Údefaulté   Úpublicg      à?)
Únamer)   Úconcurrency_limitÚconcurrency_idÚqueueÚbatchÚmax_batch_sizeÚapi_visibilityÚ
time_limitÚstream_everyc       
        óv   ^ ^• UUUUUUUU	U
US.
mUb  T R                   R                  UT45        U$ UU 4S jnU$ )z„Decorator to register a function as a Gradio API endpoint.

Goes through Gradio's queue with concurrency control and SSE streaming.
)
Úapi_nameÚapi_descriptionrT   rU   rV   rW   rX   rY   rZ   r[   c                óB   >• TR                   R                  U T45        U $ ©N©rG   Úappend)ÚfuncÚkwargsrI   s    €€r   ÚwrapperÚServer.api.<locals>.wrapper×   s    ø€ Ø×Ñ×&Ñ&¨¨f ~Ô6ØˆKr   ra   )rI   ÚfnrS   r)   rT   rU   rV   rW   rX   rY   rZ   r[   re   rd   s   `            @r   r   Ú
Server.api´   sZ   ù€ ð( Ø*Ø!2Ø,ØØØ,Ø,Ø$Ø(ñ
ˆð ‰>Ø×Ñ×&Ñ&¨¨F |Ô4ØˆIö	ð ˆr   iô  z100%i'  )$ÚheightÚwidthÚfavicon_pathÚssl_keyfileÚssl_certfileÚssl_keyfile_passwordÚ
ssl_verifyÚquietÚfooter_linksÚrun_historyÚallowed_pathsÚblocked_pathsr;   Ú
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_workersc       $        ó   • SSK Jn0  SSKJn1  U0" SS9 n2U R                   H  u  n3n4U1" S:SU30U4D6  M     SSS5        S[
        R                  S	'   W2R                  " S:0 S
U _SU_SU_SU_SU_SU_SU_SU_SU_SU	_SU
_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_S U_S!U_S"U_S#U_S$U_S%U_S&U_S'U_S(U_S)U_S*U _S+U!_S,U"_S-U#_S.U$_S/U%_S0U&_S1U'_S2U(_S3U)_S4U*_S5U+_S6U,_S7U-_S8U._S9U/_6$ ! , (       d  f       NÁ= f);z¶Launch 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)Úmoderg   NÚ1ÚGRADIO_SERVER_MODE_ENABLEDÚ_appÚinlineÚ	inbrowserÚsharer&   Úmax_threadsÚauthÚauth_messageÚprevent_thread_lockÚ
show_errorÚserver_nameÚserver_portri   rj   rk   rl   rm   rn   ro   rp   rq   rr   rs   rt   r;   ru   rv   rw   rx   ry   rz   r{   r|   r}   r~   r   r€   r�   r‚   rƒ   r„   r…   r†   r‡   rˆ   r‰   rŠ   r‹   r   )Úgradio.blocksr�   Úgradio.eventsr   rG   ÚosÚenvironr    )5rI   r“   r”   r•   r&   r–   r—   r˜   r™   rš   r›   rœ   ri   rj   rk   rl   rm   rn   ro   rp   rq   rr   rs   rt   r;   ru   rv   rw   rx   ry   rz   r{   r|   r}   r~   r   r€   r�   r‚   rƒ   r„   r…   r†   r‡   rˆ   r‰   rŠ   r‹   r�   Úgr_apiÚblocksrg   Ú
api_kwargss5                                                        r   r    ÚServer.launchÝ   sh  € õ@ 	)Ý/á˜Ò" fØ"&×"5Ô"5‘��JÙÑ+˜"Ð+ 
Ô+ñ #6÷ #ð 47Œ�
‰
Ð/Ñ0à�}Š}ò 1
Ùð1
áð1
ñ  ð1
ñ ð	1
ñ
 ð1
ñ $ð1
ñ ð1
ñ &ð1
ñ !4ð1
ñ "ð1
ñ $ð1
ñ $ð1
ñ ð1
ñ ð1
ñ &ð1
ñ  $ð!1
ñ" &ð#1
ñ$ "6ð%1
ñ& "ð'1
ñ( ð)1
ñ* &ð+1
ñ, $ð-1
ñ. (ð/1
ñ0 (ð11
ñ2  ð31
ñ4 "ð51
ñ6 $:ð71
ñ8 "6ð91
ñ: #8ð;1
ñ< *Fð=1
ñ> ,ð?1
ñ@ (ðA1
ñB 0ðC1
ñD $ðE1
ñF .ðG1
ñH  ðI1
ñJ ðK1
ñL ðM1
ñN "ðO1
ñP  ðQ1
ñR ðS1
ñT ðU1
ñV ðW1
ñX  ðY1
ñZ ð[1
ñ\ ð]1
ñ^ "ð_1
ñ` $ða1
ð 1	
÷ #Õ"ús   “!C/Ã/
C=)rG   rH   )>r&   Úboolr'   Ústrr(   ú
str | Noner)   r¦   r*   r¦   r+   r§   r,   úlist[dict[str, Any]] | Noner-   r¨   r.   r   r/   r   r0   r¥   r1   r§   r2   r§   r3   r   r4   r   r5   r   r6   r   r7   r   r8   r§   r9   údict[str, Any] | Noner:   r©   r;   r¦   r<   r¥   r=   z&dict[int | str, dict[str, Any]] | Noner>   r   r?   r   r@   úbool | NonerA   r¥   rB   r   rC   r¥   rJ   r   )Úreturnr   r`   )rg   zCallable | NonerS   r§   r)   r§   rT   zint | None | Literal['default']rU   r§   rV   r¥   rW   r¥   rX   ÚintrY   z,Literal['public', 'private', 'undocumented']rZ   ú
int | Noner[   Úfloat)NFNFé(   NNFFNN)`r“   rª   r”   r¥   r•   rª   r&   r¥   r–   r¬   r—   zKCallable[[str, str], bool] | tuple[str, str] | list[tuple[str, str]] | Noner˜   r§   r™   r¥   rš   r¥   r›   r§   rœ   r­   ri   r¬   rj   z	int | strrk   zstr | Path | Nonerl   r§   rm   r§   rn   r§   ro   r¥   rp   r¥   rq   zJlist[Literal['api', 'gradio', 'settings', 'runs'] | dict[str, str]] | Nonerr   rª   rs   úlist[str] | Nonert   r°   r;   r§   ru   r©   rv   r¬   rw   r§   rx   zLiteral['http', 'https'] | Nonery   r§   rz   zFCallable[[fastapi.Request], str | None | Awaitable[str | None]] | Noner{   zstr | int | Noner|   rª   r}   r¥   r~   r§   r   r­   r€   rª   r�   rª   r‚   rª   rƒ   r¥   r„   zI18n | Noner…   zTheme | str | Noner†   r§   r‡   ú(str | Path | Sequence[str | Path] | Nonerˆ   zstr | Literal[True] | Noner‰   r§   rŠ   r±   r‹   r­   r«   ztuple[App, str, str])r   r   r   r   r   rF   Úpropertyr   r   r    r   Ú__classcell__)rL   s   @r   r"   r"      sd  ø† ñðD ØØ"ØØØ"1Ø48Ø/3Ø Ø&*Ø!%Ø&Ø (ØØ"&ØØØØ'+Ø)-Ø.2ØØ%)Ø<@ØØØ"&Ø"&Ø+/Ø.2ñAq$ð ðq$ð ð	q$ð
 ðq$ð ðq$ð ðq$ð  ðq$ð 2ðq$ð -ðq$ð ðq$ð !$ðq$ð ðq$ð ðq$ð ðq$ð  ð!q$ð"  ð#q$ð$ ð%q$ð& ð'q$ð( ð)q$ð* %ð+q$ð, 'ð-q$ð. ,ð/q$ð0 ð1q$ð2 #ð3q$ð4 :ð5q$ð6 ð7q$ð8 ð9q$ð:  ð;q$ð<  ð=q$ð> &)ð?q$ð@ (,ðAq$ðB ÷Cq$ð q$ðf óó ðð #ð'ð  Ø"&Ø=FØ%)ØØØØGOØ!%Ø!ñ'àð'ð ð	'ð
  ð'ð ;ð'ð #ð'ð ð'ð ð'ð ð'ð Eð'ð ð'ð ö'ðV #ØØ!ØØð Ø#'Ø$)Ø Ø"&Ø"&ðz
ð  Ø!Ø*.Ø"&Ø#'Ø+/ØØð Ø#'Ø*.Ø*.Ø $Ø,0Ø&+Ø+/ØAEØ37àØ*.Ø)-Ø Ø'+Ø $Ø $ØØ"&ØØ Ø$(ØØ>BØ)-ØØ?CØ"&ñoz
àðz
ð ðz
ð ð	z
ð
 ðz
ð ðz
ð Xðz
ð !ðz
ð "ðz
ð ðz
ð  ðz
ð  ðz
ð  ð!z
ð" ð#z
ð$ (ð%z
ð&  ð'z
ð( !ð)z
ð* )ð+z
ð, ð-z
ð. ð/z
ð0ð1z
ð8 !ð9z
ð: (ð;z
ð< (ð=z
ð> ð?z
ð@ *ðAz
ðB !$ðCz
ðD )ðEz
ðF  ?ðGz
ðH '1ðIz
ðJðKz
ðN (ðOz
ðP 'ðQz
ðR ðSz
ðT %ðUz
ðV ðWz
ðX ðYz
ðZ ð[z
ð\  ð]z
ð^ ð_z
ð` ðaz
ðb "ðcz
ðd ðez
ðf <ðgz
ðh 'ðiz
ðj ðkz
ðl =ðmz
ðn  ðoz
ðp 
÷qz
ô z
r   r"   )r   Ú
__future__r   rŸ   Úcollections.abcr   r   r   Úpathlibr   Útypingr   r	   ÚfastapiÚgradio_client.documentationr
   Úgradior   Úgradio.i18nr   Úgradio.routesr   Úgradio.themesr   ÚThemer   r"   r   r   r   Ú<module>r¿      s[   ðÙ Må "ã 	ß 9Ñ 9Ý ß ã Ý 0å Ý Ý Ý -÷&ñ &ñ 
ˆ%�Óô{
ˆSó {
ó ñ{
r   