
    MgH                         S SK r S SKrS SKrS SKJr  S SKrS SKJr  \R                  R                  \R                  R                  \
5      5      r\" S5      S 5       rS rS rS rg)	    N)Fore)pluginzdetect langc                     US:X  a  U R                  S5      nUS:X  a  M  [        5       nUR                  U5      n[        X5        g)z)
Detects the language of an input string
 zEnter text 
N)input
open_modelpredictgenerate_response)jarvissmodeloutputs       E/Users/admin/workspace/ai/Jarvis/jarviscli/plugins/detect_language.pydetect_languager      sA     r'LL) r' LE]]1Ff%    c                 P   US   S   nUS   S   n[        5       nUR                  S5      S   nXE   nUS:  a$  U R                  SU-   [        R                  5        g
US:  a$  U R                  SU-   [        R
                  5        g
U R                  S	[        R                  5        g
)zE
Generates response based on the probability of a predicted language
   r   _g      ?zThe language of the text is g      ?z(I'm not sure, but the language might be z I couldn't identify the languageN)open_languagessplitsayr   GREENYELLOWBLUE)r   r   scorelabelcode_to_lang	lang_codelanguages          r   r
   r
      s     1IaLE1IaLE!#LC $I&Hs{

1H<djjI	

=H$++V

5tyyAr   c                  v   [         R                  R                  [        S5      n [        [
        R                  l        [        [         R                  S5       n[        R                  " U5         [
        R                  " U 5      nSSS5        SSS5        W$ ! , (       d  f       N= f! , (       d  f       W$ = f)z7
Opens a language detector model and disables warnings
z../data/lid.176.ftzwN)ospathjoin	FILE_PATHprintfasttextFastTexteprintopendevnull
contextlibredirect_stdout
load_model)
model_pathfr   s      r   r   r   ,   sx     i)>?J$H	bjj#	!Z%?%?%B##J/ &C	L &C%B		Ls$   B)/BB)
B&	"B))
B8c                      [         R                  R                  [        S5      n [	        U S5       n[
        R                  " U5      nSSS5        U$ ! , (       d  f       W$ = f)z<
Opens a dictionary from code to its corresponding language
z../data/code_to_lang.jsonrN)r#   r$   r%   r&   r+   jsonload)language_pathr1   	languagess      r   r   r   7   sL     GGLL,GHM	mS	!QIIaL	 
" 
"	!s   A
A!)r-   r4   r#   coloramar   r(   r   r$   abspathdirname__file__r&   r   r
   r   r    r   r   <module>r=      s_      	   GGOOBGGOOH56	 
& 
&B"r   