o
    g.f                     @   s   d dl Z d dlZd dlmZ d dlmZmZmZmZm	Z	m
Z
mZmZmZmZmZ dedee fddZedkrYd dlZeejd	krKed
 ed ejd Ze ee dS dS )    N)List)get_keywordsget_questionget_distractorspostprocesstexts2vnormalized_levenshteinsentence_transformer_modelsummary_modelsummary_tokenizerquestion_modelquestion_tokenizercontextreturnc              
      s|  zt d|  t| }t d| t| |}t d| g }|D ]o}t d| d||}tj|dddd	d
tj}|d |d }}tj	||dddddd}	dd |	D }
dd |
D }t d| |D ])}t
||ddttt}|d d }| g| }t| ||| |d qcqg }t }|D ]}|d }||vr|| || q|W S  ty } ztd|d }~ww )NzContext:zSummary text:z	Keywords:zGenerating question for answer:zcontext: {} answer: {}i  FTpt)
max_lengthpad_to_max_length
truncationreturn_tensors	input_idsattention_mask         H   )r   r   early_stopping	num_beamsnum_return_sequencesno_repeat_ngram_sizer   c                 S   s   g | ]	}t j|d dqS )T)skip_special_tokens)r   decode).0ids r#   I/var/www/chatrigo.edurigo1.com/get_recommendations/testing/main_static.py
<listcomp>   s    z%generate_question.<locals>.<listcomp>c                 S   s   g | ]
}| d d qS )z	question: )replacestrip)r!   qr#   r#   r$   r%      s    zGenerated questions:(   g?)questioncorrect_answeroptionsr+   zError generating questions)printr   r   formatr   encode_plustor   devicegenerater   r   r   r	   
capitalizerandomshuffleappendsetadd	Exception
ValueError)r   summary_textkeywordsoutputanswerquestion_inputencodingr   r   outsdec	questionsr+   distractorsselected_distractorsr-   unique_outputseen_questionsquestion_dataer#   r#   r$   generate_question   sX   









rK   __main__r   z'Usage: python3 main_static.py <context>   )asyncior5   typingr   main_static_partialr   r   r   r   r   r   r	   r
   r   r   r   strdictrK   __name__syslenargvr.   exitr   runr#   r#   r#   r$   <module>   s    41

