CoolFace
Apppublic

zinoubm/Voice_Commands

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

2�{�d*�@s�ddlZddlZddlZddlTddlZee_ee_	dZ3dZdZdd�Z
dd	d4�Zddd�Zd
d�Zejeejddd�ddgd�ZdS)�N)�*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/demo.py�remove_punctuation0s25r�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_command6s�
��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)rrrr!r#�result_listrrr
�command_tokensPs�"r0cCsTt|d�}tjjd|dd�}|d}t|t�}t|�}td|�td|�dd	gfS)53z�54    if text provided the function will classify the input directly.55    if not the audio will be transcribed then the transcription will be classified.56 57    return a tuple of (transcription, command, audio to be played)58    �rbz	whisper-1�en)�languagerr#�tokens�wow)r5�none)�openr�Audio�59transcriber$r r0�print)�audio�60audio_file�
transcriptionr#r4rrr
r9js61	62636465r9�66microphone�filepath)�source�typer�	highlight)�fn�inputs�outputs)r)�logging�gradio�grr�	constantsr�OPENAI_API_KEY�api_key�OPENAI_ORGANIZATION�organization�title�description�articlerr$r0r9�	Interfacer8�apprrrr
�<module>s&6768&69