CoolFace
Apppublic

zinoubm/Voice_Commands

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
app.cpython-310.pyc68 linesDownload Raw Back to __pycache__
1o

2�x�d��	@s�ddlmZddlZddlZddlZddlTddlZee_	e3e_dZdZ
dZdd�Zdd4d�Zddd
�Zdd�Zejeejdddd�gejdd�ejdd�gdee
ed�Zedkr_e��dSdS)�)�debugN)�*zCar Seats Voice Commandsa�5This is a demo for controlling car seats with Voice Commands, On the left there's the inputs section6and on the right you'll find your outputs. For the inputs you have two choices **Voice** and **Text**,7Use **Voice** If you want a closer experience to the final product, Or use **Text** if you just want to test the command model.8for the outputs you have the **transcription**(Please check that it's accurate), **command**(to know which9command the system detected) and you have the robot voice (again use this if you want a more real experience).10 11**Features** : You can either activate of deactivate the following features 12- Heated Seats 13- Cooled Seats 14- Massage Seats 15 16Examples:17- **Direct Commands** : Try to say something like "Activate heated seats" or "Turn Off massage seats"18- **Indirect Commands** : Try "My back is cold" , "No heating is needed anymore" or "I'm stressed today"19a20This demo processes commands in two steps, the first step is the transcription phase and the second is the21Command Classification phase. For Transcription I used The OpenAi whisper model, and for the classification 22I Fine-Tuned the OpenAi **ada** model on Car Seats Command.23cCst�ddtj�}|�|�}|S)N�)�str�	maketrans�string�punctuation�	translate)�input_string�24translator�clean_string�r
�>/home/boumaza/Desktop/Programming/UpWork/Voice_Commands/app.py�remove_punctuation1s25r�text-davinci-003cCsXd|�d�}tjj||ddd�}tt|ddd����}||vr(||}|Sd}|S)	�F26    This function get the classification outputs from openai API27    zo28    We want to control the seats of a car which has features to cool, heat, or massage a seat. The user said "a3", Which feature we should use to ensure user comfort? Give just the number of the feature without any punctuation.29    Mapping:30    1: "massage_seats_on"31    2: "massage_seats_off"32    3: "heated_seats_on"33    4: "heated_seats_off"34    5: "cooled_seats_on"35    6: "cooled_seats_off"36 37    Command_Code:38    �r��model�prompt�39max_tokens�temperature�choices�text�unknown)�openai�40Completion�create�intr�strip)�command�id2labelrr�41completion�id�resultr
r
r�get_command7s�
��r%cCsbd}tjj||ddd�}|ddd��}|�dd��d	d��d42d��d�}tt|�d�|��S)
rac43        Give an array of the same length of the input, for every element of the returned array use  one of the labels in the label-list44 45        label-list :46        - unit if belongs to the International System of Units47        - value48        - none if none of the above49 50        input : [raise , the, tmeprature, to, 20, degrees]51        output :52    �rrrr�[r�]�'�,� )rrrr�replace�split�list�zip)r rrr"r$�result_listr
r
r�command_tokensQs�"r1cCsRt|d�}tjjd|dd�}|d}t|t�}t|�}td|�td|�||fS)z�53    if text provided the function will classify the input directly.54    if not the audio will be transcribed then the transcription will be classified.55 56    return a tuple of (transcription, command, audio to be played)57    �rbz	whisper-1�en)�languagerr$�tokens)�openr�Audio�58transcriber%r!r1�print)�audio�59audio_file�
transcriptionr$r5r
r
rr8ks60	616263r8r�64microphone�filepath)�label�source�typezMachine Response (Text Version))r?z:Token Classification (We can use It for advanced commands)�auto)�fn�inputs�outputs�allow_flagging�title�description�article�__main__)r)�doctestr�logging�gradio�grr�	constantsr�OPENAI_API_KEY�api_key�OPENAI_ORGANIZATION�organizationrGrHrIrr%r1r8�	Interfacer7�Textbox�HighlightedText�app�__name__�launchr
r
r
r�<module>s<6566�6768���