wL i LUddlmZddlmZmZddlmZmZmZddl m Z ddl m Z m Z ddl mZmZmZe j"eZd aeeed <eZeZeed <d d d d d edeedeedeeed fdd f dZdZdZd d d d d edeedeedeeed fdd f dZy ))Queue)LockThread)DictOptionalUnion)quote) constantslogging)build_hf_headers get_sessionhf_raise_for_statusN_TELEMETRY_THREAD_TELEMETRY_QUEUE) library_namelibrary_version user_agenttopicrrrreturnctjstjryttj ||||dy)a_ Sends telemetry that helps tracking usage of different HF libraries. This usage data helps us debug issues and prioritize new features. However, we understand that not everyone wants to share additional information, and we respect your privacy. You can disable telemetry collection by setting the `HF_HUB_DISABLE_TELEMETRY=1` as environment variable. Telemetry is also disabled in offline mode (i.e. when setting `HF_HUB_OFFLINE=1`). Telemetry collection is run in a separate thread to minimize impact for the user. Args: topic (`str`): Name of the topic that is monitored. The topic is directly used to build the URL. If you want to monitor subtopics, just use "/" separation. Examples: "gradio", "transformers/examples",... library_name (`str`, *optional*): The name of the library that is making the HTTP request. Will be added to the user-agent header. library_version (`str`, *optional*): The version of the library that is making the HTTP request. Will be added to the user-agent header. user_agent (`str`, `dict`, *optional*): The user agent info in the form of a dictionary or a single string. It will be completed with information about the installed packages. Example: ```py >>> from huggingface_hub.utils import send_telemetry # Send telemetry without library information >>> send_telemetry("ping") # Send telemetry to subtopic with library information >>> send_telemetry("gradio/local_link", library_name="gradio", library_version="3.22.1") # Send telemetry with additional data >>> send_telemetry( ... topic="examples", ... library_name="transformers", ... library_version="4.26.0", ... user_agent={"pipeline": "text_classification", "framework": "flax"}, ... ) ``` Nrrrr)r HF_HUB_OFFLINEHF_HUB_DISABLE_TELEMETRY_start_telemetry_threadrputrs f/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/huggingface_hub/utils/_telemetry.pysend_telemetryrs:^9#E#E/istct5ttjs%ttdatj dddy#1swYyxYw)zyStart a daemon thread to consume tasks from the telemetry queue. If the thread is interrupted, start a new one. NT)targetdaemon)_TELEMETRY_THREAD_LOCKris_aliver_telemetry_workerstartr rrrLsH &  $,=,F,F,H &.? M   # # % &&&s AAAcl tj}tdi|tj4)zWait for a task and consume it.r()rget_send_telemetry_in_thread task_done)kwargss rr&r&Xs/ !%%'!+F+""$ r c <djd|jdD} tjtj d|t d|||}t|y#t$r"}tjd|Yd}~yd}~wwxYw) a*Contains the actual data sending data to the Hub. This function is called directly in gradio's analytics because it is not possible to send telemetry from a daemon thread. See here: https://github.com/gradio-app/gradio/pull/8180 Please do not rename or remove this function. /c3PK|]}t|dkDst| yw)rN)lenr ).0parts r z,_send_telemetry_in_thread..psNDD A E$KNs&&z/api/telemetry/F)tokenrrr)headerszError while sending telemetry: N) joinsplitrheadr ENDPOINTrr Exceptionloggerdebug)rrrrpathres rr+r+`s 88NEKK,<N ND < M  !!"/$ 8$) /%    A < 6qc:;;rJs "((!@@   H % '+8F#*'%! #'%))- 5 53-5c] 5 dCo& 5  5p &%#'%))- < <3-<c] < dCo& <