
    [iF                    .   U d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	m
Z
mZ d dlmZ d dlmZmZmZmZmZ d dlmZmZmZ d dlmZ d dlmZ d d	lmZmZ d d
lm Z  d dl!m"Z"  ee#      Z$de%d<   dZ&de%d<   dZ'de%d<   ddddddddddd
Z(de%d<   g dZ)de%d<   d Z*d!Z+d2d"Z,d2d#Z- G d$ d%      Z.d3d&Z/d4d'Z0d5d(Z1	 	 	 	 	 	 	 	 	 	 d6d)Z2d7d*Z3 ed+e
d,ef   -      Z4e	 	 	 	 	 	 d8d.       Z5e	 d9	 	 	 	 	 d:d/       Z5d9d;d0Z5	 d9	 	 	 	 	 	 	 	 	 d<d1Z6y)=    )annotationsN)CallableSized)wraps)AnyFinalTypeVarcastoverload)config	file_utilutil)
get_logger)
ForwardMsg)ArgumentCommand)RerunException)get_script_run_ctxr   _LOGGER   _MAX_TRACKED_COMMANDS   _MAX_TRACKED_PER_COMMANDDG	DataFramePlotlyFigureBokehFigureMatplotlibFigurePandasStylerPandasIndexPandasSeriesSnowparkConnectionSQLConnection)
z(streamlit.delta_generator.DeltaGeneratorzpandas.core.frame.DataFramez plotly.graph_objs._figure.Figurezbokeh.plotting.figure.Figurezmatplotlib.figure.Figurezpandas.io.formats.style.Stylerzpandas.core.indexes.base.Indexzpandas.core.series.Seriesz<streamlit.connections.snowpark_connection.SnowparkConnectionz2streamlit.connections.sql_connection.SQLConnection_OBJECT_NAME_MAPPING)pymysqlMySQLdbmysqlpymongoibisboto3psycopg2psycopg3
sqlalchemyelasticsearchpyodbcpymssql	cassandraazureredissqlite3neo4jduckdbopensearchpysupabase
databrickspolarsdaskvaexmodinpysparkcudfxarrayray	geopandasmarstableszarrdatasetsdaft	mistralaiopenai	langchainllama_index	llama_cpp	anthropic
pyllamacppcoheretransformersnomic	diffuserssemantic_kernel	replicatehuggingface_hubwandbtorch
tensorflowtrubricscomet_mlclarifairekahegelfastchat
assemblyaiopenllm
embedchainhaystackvllmalpajinaaiguidancelitellm	comet_llm
instructorxgboostlightgbmcatboostsklearnpydantic_ai	datachaindoclinglitservecrawl4aibaml_clientbrowser_usecrewaiunsloth	langgraphdspyultralyticsri   ragasswarmfaster_whispermemoriautogen_agentchatxai_sdkagnolangfuse
smolagentsollamagroqtogetherai21marvinoutlines
guardrails
promptflowsemantic_routermem0aisuitemlflowoptunakerasjaxshap	evidentlygreat_expectationsbentomlmodal	sagemakervertexaitiktokensentence_transformersspacynltkonnxruntimellama_api_clientprefectluigiairflowdagstercelerypgvectorfaissannoypineconechromadbweaviateqdrant_clientpymilvuslancedb	snowflakepydanticfastapi	starlette
playwrightfoliumrB   httpx	pyechartsfastplotlibpygfxhighcharts_coreseaborngraphviz
matplotlibuvlooporjsonrichstreamlit_extrasstreamlit_pydantic	pygwalkerplotlybokehplostauthlibpypdf
pdfplumberdocxopenpyxl
xlsxwritercv2	mediapipe_ATTRIBUTIONS_TO_CHECKz/etc/machine-idz/var/lib/dbus/machine-idc                    t         j                  j                  t              r,t	        t        d      5 } | j                         }ddd       |S t         j                  j                  t              r,t	        t        d      5 } | j                         }ddd       |S t        t        j                               }|S # 1 sw Y   S xY w# 1 sw Y   S xY w)aD  Get the machine ID.

    This is a unique identifier for a user for tracking metrics,
    that is broken in different ways in some Linux distros and Docker images.
    - at times just a hash of '', which means many machines map to the same ID
    - at times a hash of the same string, when running in a Docker container
    zutf-8)encodingN)
ospathisfile_ETC_MACHINE_ID_PATHopenread_DBUS_MACHINE_ID_PATHstruuidgetnode)f
machine_ids     o/var/www/html/userprofiledev.eatanceapp.com/venv/lib/python3.12/site-packages/streamlit/runtime/metrics_util.py_get_machine_id_v3r      s     
ww~~*+&9QJ :  
-	.'':aJ ;  (
 :  ; s   B>C>CCc                    t        j                  d      syt        j                  d      } d}t        j
                  j                  |       r.t        j                  |       5 }|j                         }ddd       |sNt        t        j                               }t        j                  |       5 }|j                  |       ddd       |S |S # 1 sw Y   [xY w# 1 sw Y   |S xY w)a  Get a random ID that is stable for each machine, generating if needed.

    This is a unique identifier for a user for tracking metrics.
    Instead of relying on a hardware address in the container or host we'll
    generate a UUID and store it in the ~/.streamlit hidden folder.
    zbrowser.gatherUsageStatszno-machine-id-v4machine_id_v4N)r   
get_optionr   get_streamlit_file_pathr   r   existsstreamlit_readr   r   r   uuid4streamlit_writewrite)filepath	stable_idfileoutputs       r   _get_machine_id_v4r     s     78 "00AHI	ww~~h%%h/4		I 0 

%	&&x0FLL# 1 9 0/
 1 s   "C/CCC#c                  r    e Zd ZU  ej                         ZdZded<   edd       Z	d	dZ
d
dZed
d       Zy)InstallationNzInstallation | None	_instancec                    | j                   <| j                  5  | j                   t               | _         ddd       | j                   S | j                   S # 1 sw Y   | j                   S xY w)z#Returns the singleton Installation.N)r   _instance_lockr   )clss    r   instancezInstallation.instance-  sV     == ##==($0NCM $ }}s}}	 $ }}s   AA)c                    t        t        j                  t        j                  t	                           | _        t               | _        y N)r   r   uuid5NAMESPACE_DNSr   installation_id_v3r   installation_id_v4selfs    r   __init__zInstallation.__init__:  s4    "%JJt))+=+?@#
 #5"6    c                ,    t        j                  |       S r   )r   repr_r   s    r   __repr__zInstallation.__repr__A  s    zz$r   c                    | j                   S r   )r   r   s    r   installation_idzInstallation.installation_idD  s    &&&r   )returnr   )r  Noner  r   )__name__
__module____qualname__	threadingLockr   r   __annotations__classmethodr   r   r   propertyr    r   r   r   r   )  sK    #Y^^%N%)I")
 
7  ' 'r   r   c                p   t        j                  t              5  t        j                  |       r| n
t        |       }d}t        |d      r|j                  }nt        |d      r|j                  }|j                  dk7  r|j                   d| }|t        v r	t        |   }|cddd       S # 1 sw Y   yxY w)z7Get a simplified name for the type of the given object.unknownr  r  builtins.Nfailed)
contextlibsuppress	Exceptioninspectisclasstypehasattrr  r  r  r$   )objobj_type	type_names      r   _get_type_namer  I  s    			Y	'!//#.3DI	8^, --IXz* ))I*,#../q<I,,,Y7I 
(	'	' s   BB,,B5c                    t        j                  |       }||j                  sy|j                  j                  d      d   S )z0Get the top level module for the given function.r  r  r   )r  	getmoduler  split)funcmodules     r   _get_top_level_moduler"  ]  s:    t$F~V__??  %a((r   c                    t        j                  t              5  t        | t              rd|  cddd       S t        | t
              rdt        |        cddd       S 	 ddd       y# 1 sw Y   yxY w)zBGet metadata information related to the value of the given object.zval:Nzlen:)r  r  r  
isinstanceboolr   len)args    r   _get_arg_metadatar(  e  sg    			Y	'cD"#< 
(	' c5!#c($ 
(	' "	 
(  
( s   A*A**A3c                   t        j                  |       j                  }d}g }t        j                  |       }|}t	        |      D ]h  \  }	}
|	}|r|	dz  }	t        |      |	kD  r||	   n|	 }|dk(  r|
}-t        |t        |
      |      }t        |
      }|r||_	        |j                  |       j |j                         D ]@  \  }}t        |t        |            }t        |      }|r||_	        |j                  |       B t        |       }|dk7  rd| d| }|d	k(  r)|r't        |d
      r|j                  rd|j                   }|dk(  r+t        |      dkD  rt        |d   t               r
|d   }d| }t#        ||      S )zCGet telemetry information for the given callable and its arguments.N   r   )ktp)r+  r,  	streamlitz	external::create_instancenamez
component:_bidi_componentzcomponent_v2:)r1  args)r  getfullargspecr3  ismethod	enumerater&  r   r  r(  mappenditemsr"  r  r1  r$  r   r   )_command_func_command_namer3  kwargsarg_keywordsself_arg	arguments	is_methodr1  ir'  poskeywordargumentarg_metadatakwargkwarg_valuetop_level_modulecomponent_names                      r   _get_command_telemetryrJ  q  s    ))-8==LH "I  /IDD/3FA%(%6%:,q/1#fHg)<D(-%HJ" "  %lln{e~k'BC(5%HJ" - -];;& +,AdV4 	!!Hf%MMHMM?+  SY]z$q'37O a~./9--r   c                    t        | dz        S )z"Convert seconds into microseconds.i@B )int)secondss    r   to_microsecondsrN    s    w"##r   F.)boundc                     y r   r  r1  r   s     r   gather_metricsrS    s     	r   c                     y r   r  rR  s     r   rS  rS    s     r   c                l     st         j                  d       d |d fd}|S |t              d fd       }t        j                  t
              5  |j                  j                  j                         t        j                        |_
        ddd       t        d|      S # 1 sw Y   xY w)	a  Function decorator to add telemetry tracking to commands.

    Parameters
    ----------
    func : callable
    The function to track for telemetry.

    name : str or None
    Overwrite the function name with a custom name that is used for telemetry tracking.

    Example
    -------
    >>> @st.gather_metrics
    ... def my_command(url):
    ...     return url

    >>> @st.gather_metrics(name="custom_name")
    ... def my_command(url):
    ...     return url
    zgather_metrics: name is empty	undefinedNrO  c                    t        |       S )NrR  )rS  )r   r1  s    r   wrapperzgather_metrics.<locals>.wrapper  s    ! r   c                 $   ddl m}  |       }t        d      }|d uxr9 |j                  xr+ |j                   xr t        |j                        t        k  }d }d}|r|r	 t        
g| i |}|j                  |j                  vs |j                  |j                     t        k  r|j                  j                  |       |j                  j                  |j                  g       d|_        d}	  | i |}		 |r
|rd|_        	 |r|rt%         |       |z
        |_        |	S # t        $ r!}t        j!                  d|       Y d }~Yd }~ww xY w# t"        $ r |r|rt%         |       |z
        |_         w xY w# |r|rd|_        w w w xY w)Nr   )default_timerT)suppress_warningFz#Failed to collect command telemetry)exc_info)timeitrZ  r   gather_usage_statscommand_tracking_deactivatedr&  tracked_commandsr   rJ  r1  tracked_commands_counterr   r8  updater  r   debugr   rN  time)r3  r<  timer
exec_startctxtracking_activatedcommand_telemetry$has_set_command_tracking_deactivatedexresultr1  non_optional_funcs             r   wrapped_funcz$gather_metrics.<locals>.wrapped_func  s   1W
 $7 tO $&&$444$ C(()#$	 	 -1
 05,%R$:%t%.2%6<%!
 &**#2N2NN334E4J4JK./ ((//0AB,,335F5K5K4LM370 8<4
	9&77F ;380"3%4UWz5I%J"/  R CbQQR  	 "&7)8:9M)N!&	 ;380 <ss1   #BD) 6E )	E2EE'E==F   F)r   rO  r  rO  )r3  r   r<  r   r  r   )r   warningr   r  r  AttributeError__dict__rb  r  	signature__signature__r
   )r1  r   rX  rn  rm  s   `   @r   rS  rS    s    , 78|	 
? ?B 
		^	, 	$$%6%?%?@%,%6%67H%I"	 
-
 \"" 
-	,s   A B**B3c                   t               }|j                  }|j                  j                  |        ||_        ||_        t        j                  d      |_        t        j                  rt        j                  |_
        t               }t        j                  r`t        j                  D ]M  }t        j                  |      st        j                  |   }|j                  |j                  r| dn|       O |j                  j                  |       t         D 	ch c]  }	|	t"        j$                  v r|	 }
}	t'        t"        j(                        |_        t'        t,        j.                        |_        |j2                  j                  |
       |r||_        t7               x}rt9        |j:                        |_        |S c c}	w )z2Create and return the full PageProfile ForwardMsg.zserver.headlessz:default)r   page_profilecommandsextend	exec_time	prep_timer   r   headless_server_modeserver_modeset_config_optionsis_manually_setadd
is_defaultr   sysmodulesr   platformr   rd  tznametimezoneattributionsuncaught_exceptionr   r%  fragment_ids_this_runis_fragment_run)rv  rx  ry  r  msgru  config_optionsoption_nameconfig_optionattributionr  rg  s               r   create_page_profile_messager  0  s}    ,C##L  *&L&L"--.?@L #)#6#6   #uN!11K))+6"22;?M,9,D,D;-x(+ 2 ~.
 21K#++% 	1   #,,'LO,L$$\2*<' ""s"'+C,E,E'F$J!s   Gr  )r  objectr  r   )r   Callable[..., Any]r  r   )r'  r  r  
str | None)
r:  r  r;  r   r3  r   r<  r   r  r   )rM  floatr  rL  )r1  r   r   rO  r  rO  r   )r1  r   r   r  r  zCallable[[F], F])r1  r   r   zF | Noner  zCallable[[F], F] | F)
rv  zlist[Command]rx  rL  ry  rL  r  r  r  r   )7
__future__r   r  r  r   r  r  rd  r   collections.abcr   r   	functoolsr   typingr   r   r	   r
   r   r.  r   r   r   streamlit.loggerr   streamlit.proto.ForwardMsg_pb2r   streamlit.proto.PageProfile_pb2r   r   /streamlit.runtime.scriptrunner_utils.exceptionsr   7streamlit.runtime.scriptrunner_utils.script_run_contextr   r  r   r	  r   r   r$   r   r   r   r   r   r   r  r"  r(  rJ  rN  rO  rS  r  r  r   r   <module>r     s   #   	 
    +  6 6 - - ' 5 = J VH% %  # u " #% % $ 15#.(6$1 2&4&3!/DX:I e s!  sj ) 2 .<' '@()	6.%6.696.BE6.QT6.6.r$
 CxS)* 


  
 
 

  
m#h &*	444 4 #	4
 4r   