o
    ٷis                     @   s4   d e de fddZedkrddlZee dS dS )url_or_space_idsource_directoryc                    s   dd l ddlm} ddlm} ddlm} ddlm m	  ||d}|| r0| 
dn	d|| j d	| d
tdtf fdd}|jdd d S )N    )is_http_url_like)
space_info)FastMCP)abspathis_in_or_equalz
upload-mcp/zhttps://z	.hf.spacefilereturnc                    s    | }|st d|  d t|d}j dd|id}W d   n1 s/w   Y  |  | d } d	| S )
a  Generate a Gradio File Input for a local file by uploading it to a Gradio app and returning the URL.
        Arguments:
            file: A complete, absolute path to a local file to upload.
        Returns:
            Gradio File Input - A URL to the uploaded file.
        zFile z is not in rbz/gradio_api/uploadfiles)r   Nr   z/gradio_api/file=)
ValueErroropenpostraise_for_statusjson)r
   target_pathfresponseresultr   httpxr   source_pathurl R/home/ubuntu/.local/lib/python3.10/site-packages/gradio/cli/commands/upload_mcp.pyupload_file_to_gradio   s   	
z#main.<locals>.upload_file_to_gradiostdio)	transport)r   gradio_client.utilsr   huggingface_hubr   mcp.server.fastmcpr   gradio.utilsr   r   rstrip	subdomaintoolstrrun)r   r   r   r   r   mcpr   r   r   r   main   s    r*   __main__r   N)r'   r*   __name__typerr(   r   r   r   r   <module>   s
    (