
    g:                       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
 d dlmZ d dlmZmZmZmZmZmZ d dl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*d1d"Z+ G d# d$      Z,d2d%Z-d3d&Z.d4d'Z/	 	 	 	 	 	 d5d(Z0d6d)Z1 ed*ed+ef   ,      Z2e	 	 	 	 	 	 d7d-       Z3e	 d8	 	 	 	 	 d9d.       Z3d8d:d/Z3	 d8	 	 	 	 	 	 	 	 	 d;d0Z4y)<    )annotationsN)Sized)wraps)AnyCallableFinalTypeVarcastoverload)config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)ZpymysqlMySQLdbmysqlpymongoibisboto3psycopg2psycopg3
sqlalchemyelasticsearchpyodbcpymssql	cassandraazureredissqlite3neo4jduckdbopensearchpysupabasepolarsdaskvaexmodinpysparkcudfxarrayray	geopandasmarstableszarrdatasets	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prefectluigiairflowdagsterpgvectorfaissannoypineconechromadbweaviateqdrant_clientpymilvuslancedb	snowflakestreamlit_extrasstreamlit_pydanticpydanticplostauthlib_ATTRIBUTIONS_TO_CHECKz/etc/machine-idz/var/lib/dbus/machine-idc                    t        t        j                               } t        j                  j                  t              r*t        t              5 }|j                         } ddd       | S t        j                  j                  t              r*t        t              5 }|j                         } ddd       | S | S # 1 sw Y   | S xY w# 1 sw Y   | S xY w)aC  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
    N)
struuidgetnodeospathisfile_ETC_MACHINE_ID_PATHopenread_DBUS_MACHINE_ID_PATH)
machine_idfs     S/var/www/openai/venv/lib/python3.12/site-packages/streamlit/runtime/metrics_util.py_get_machine_id_v3r      s     T\\^$J	ww~~*+&'1J ( 	 
-	.'(AJ ) : (  ) s   B:C:CCc                  n    e Zd ZU  ej                         ZdZded<   edd       Z	d Z
d	dZe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 InstallationN)r   _instance_lockr   )clss    r   instancezInstallation.instance   sV     == ##==($0NCM $ }}s}} $ }}s   AA)c                x    t        t        j                  t        j                  t	                           | _        y N)r   r   uuid5NAMESPACE_DNSr   installation_id_v3selfs    r   __init__zInstallation.__init__   s'    "%JJt))+=+?@#
    c                ,    t        j                  |       S r   )r   repr_r   s    r   __repr__zInstallation.__repr__   s    zz$r   c                    | j                   S r   )r   r   s    r   installation_idzInstallation.installation_id   s    &&&r   )returnr   r   r   )__name__
__module____qualname__	threadingLockr   r   __annotations__classmethodr   r   r   propertyr    r   r   r   r      sK    #Y^^%N%)I")	 	

  ' '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      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      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                   }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:)r   args)r   getfullargspecr   ismethod	enumerater   r   r   r   mappenditemsr   r   r   r   )_command_func_command_namer   kwargsarg_keywordsself_arg	arguments	is_methodr   ir   poskeywordargumentarg_metadatakwargkwarg_valuetop_level_modules                     r   _get_command_telemetryr      sk    ))-8==LH "I  /IDD/3AA%(%6%:,q/1#fHg)<D(-%HJ" "  %lln{e~k'BC(5%HJ" - -];;& +,AdV4 	!!Hf%MMHMM?+9--r   c                    t        | dz        S )z"Convert seconds into microseconds.i@B )int)secondss    r   to_microsecondsr   /  s    w"##r   F.)boundc                     y r   r   r   r   s     r   gather_metricsr   7  s     	r   c                     y r   r   r   s     r   r   r   >  s     r   c                r     st         j                  d       d |d fd}|S |t               fd       }t        j                  t
              5  |j                  j                  j                         t        j                        |_
        ddd       t        t        |      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	undefinedNc                    t        |       S )Nr   )r   )r   r   s    r   wrapperzgather_metrics.<locals>.wrappera  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
        |_        |d }~w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)timeitr   r   gather_usage_statscommand_tracking_deactivatedr   tracked_commandsr   r   r   tracked_commands_counterr   r   updater   r   debugr   r   time)r   r   timer
exec_startctxtracking_activatedcommand_telemetry$has_set_command_tracking_deactivatedexresultr   non_optional_funcs             r   wrapped_funcz$gather_metrics.<locals>.wrapped_funcl  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!&H	 ;380 <ss=   #BD) 6E )	E2EE	FE==FF F)r   r   r   r   )r   warningr   r   r   AttributeError__dict__r  r   	signature__signature__r
   r   )r   r   r   r  r  s   `   @r   r   r   E  s    , 78|	  !
? ?B 
		^	, 	$$%6%?%?@%,%6%67H%I"	 
-
 <   
-	,s   A B--B6c                ^   t               }|j                  }|j                  j                  |        ||_        ||_        t        j                  d      |_        t               }t        j                  rnt        j                  j                         D ]M  }t        j                  |      st        j                  |   }|j                  r| d}|j                  |       O |j                  j                  |       t        D 	ch c]  }	|	t         j"                  v r|	 }
}	t%        t         j&                        |_        t%        t*        j,                        |_        |j0                  j                  |
       |r||_        t5               x}rt7        |j8                        |_        |S c c}	w )z2Create and return the full PageProfile ForwardMsg.zserver.headlessz:default)r   page_profilecommandsextend	exec_time	prep_timer   
get_optionheadlessset_config_optionskeysis_manually_set
is_defaultaddr~   sysmodulesr   platformr   r  tznametimezoneattributionsuncaught_exceptionr   r   fragment_ids_this_runis_fragment_run)r  r  r  r'  msgr  config_optionsoption_nameconfig_optionattributionr&  r  s               r   create_page_profile_messager/    sn    ,C##L  *&L&L"--.?@L  #uN!11668K))+6"22;?M''!,X6{+ 9 ~.
 21K#++% 	1   #,,'LO,L$$\2*<' ""s"'+C,E,E'F$J!s   F*r   )r   objectr   r   )r   Callable[..., Any]r   r   )r   r0  r   
str | None)r   r1  r   r   r   r   )r   floatr   r   )r   r   r   r   r   r   r   )r   r   r   Noner   zCallable[[F], F])r   r   r   zF | Noner   zCallable[[F], F] | F)
r  zlist[Command]r  r   r  r   r'  r2  r   r   )5
__future__r   r   r   r   r!  r   r  r   collections.abcr   	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   r   r   r   r/  r   r   r   <module>r>     s   #   	 
    !  @ @ " ' 5 = J VH% %  # u " #% % $ 15#.(6$1 2&4&3!/DX:I e a!  aF ) 2 *' ':()	0.%0.690.0.f$
 CxS)* 


  
 
 

  
n!j &*	000 0 #	0
 0r   