diff --git "a/app.py" "b/app.py" deleted file mode 100644--- "a/app.py" +++ /dev/null @@ -1 +0,0 @@ -{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[],"dockerImageVersionId":30664,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"!pip install -q datasets==2.17.0 transformers==4.37.2 gradio==3.50.2 numpy==1.23.5","metadata":{"execution":{"iopub.status.busy":"2024-03-01T13:23:24.594680Z","iopub.execute_input":"2024-03-01T13:23:24.595258Z","iopub.status.idle":"2024-03-01T13:23:40.198732Z","shell.execute_reply.started":"2024-03-01T13:23:24.595203Z","shell.execute_reply":"2024-03-01T13:23:40.197002Z"},"trusted":true},"execution_count":1,"outputs":[]},{"cell_type":"code","source":"from transformers import pipeline\n\npipe = pipeline(\n \"automatic-speech-recognition\",\n model = \"openai/whisper-base\"\n)","metadata":{"execution":{"iopub.status.busy":"2024-03-01T13:26:21.508533Z","iopub.execute_input":"2024-03-01T13:26:21.509099Z","iopub.status.idle":"2024-03-01T13:26:33.013881Z","shell.execute_reply.started":"2024-03-01T13:26:21.509058Z","shell.execute_reply":"2024-03-01T13:26:33.012398Z"},"trusted":true},"execution_count":2,"outputs":[{"name":"stderr","text":"2024-03-01 13:26:25.205176: E external/local_xla/xla/stream_executor/cuda/cuda_dnn.cc:9261] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered\n2024-03-01 13:26:25.205266: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:607] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered\n2024-03-01 13:26:25.206957: E external/local_xla/xla/stream_executor/cuda/cuda_blas.cc:1515] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered\nSpecial tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.\n","output_type":"stream"}]},{"cell_type":"code","source":"from datasets import load_dataset\n\ndataset = load_dataset(\"facebook/voxpopuli\", \"it\", split=\"validation\", streaming=True)\nsample = next(iter(dataset))","metadata":{"execution":{"iopub.status.busy":"2024-03-01T13:26:33.016539Z","iopub.execute_input":"2024-03-01T13:26:33.017414Z","iopub.status.idle":"2024-03-01T13:26:39.402522Z","shell.execute_reply.started":"2024-03-01T13:26:33.017378Z","shell.execute_reply":"2024-03-01T13:26:39.401247Z"},"trusted":true},"execution_count":3,"outputs":[{"name":"stderr","text":"/opt/conda/lib/python3.10/site-packages/datasets/load.py:1454: FutureWarning: The repository for facebook/voxpopuli contains custom code which must be executed to correctly load the dataset. You can inspect the repository content at https://hf.co/datasets/facebook/voxpopuli\nYou can avoid this message in future by passing the argument `trust_remote_code=True`.\nPassing `trust_remote_code=True` will be mandatory to load this dataset from the next major release of `datasets`.\n warnings.warn(\n","output_type":"stream"}]},{"cell_type":"code","source":"# from IPython.display import Audio\n\n# Audio(sample[\"audio\"][\"array\"], rate=sample[\"audio\"][\"sampling_rate\"])","metadata":{"execution":{"iopub.status.busy":"2024-03-01T13:26:39.404258Z","iopub.execute_input":"2024-03-01T13:26:39.405356Z","iopub.status.idle":"2024-03-01T13:26:39.411224Z","shell.execute_reply.started":"2024-03-01T13:26:39.405309Z","shell.execute_reply":"2024-03-01T13:26:39.409610Z"},"trusted":true},"execution_count":4,"outputs":[]},{"cell_type":"code","source":"def translate(audio):\n outputs=pipe(audio, max_new_tokens=256, generate_kwargs={\"task\":\"translate\"})\n return outputs[\"text\"]","metadata":{"execution":{"iopub.status.busy":"2024-03-01T13:26:39.414647Z","iopub.execute_input":"2024-03-01T13:26:39.415072Z","iopub.status.idle":"2024-03-01T13:26:39.426498Z","shell.execute_reply.started":"2024-03-01T13:26:39.415040Z","shell.execute_reply":"2024-03-01T13:26:39.425196Z"},"trusted":true},"execution_count":5,"outputs":[]},{"cell_type":"code","source":"translate(sample[\"audio\"].copy())","metadata":{"execution":{"iopub.status.busy":"2024-03-01T13:26:39.428356Z","iopub.execute_input":"2024-03-01T13:26:39.428731Z","iopub.status.idle":"2024-03-01T13:26:41.395003Z","shell.execute_reply.started":"2024-03-01T13:26:39.428703Z","shell.execute_reply":"2024-03-01T13:26:41.393803Z"},"trusted":true},"execution_count":6,"outputs":[{"execution_count":6,"output_type":"execute_result","data":{"text/plain":"' psychological and social. I think that it is a very important step in the construction of a juridical space of freedom, circulation and protection of rights.'"},"metadata":{}}]},{"cell_type":"code","source":"sample[\"raw_text\"]","metadata":{"execution":{"iopub.status.busy":"2024-03-01T13:26:41.396634Z","iopub.execute_input":"2024-03-01T13:26:41.398111Z","iopub.status.idle":"2024-03-01T13:26:41.405763Z","shell.execute_reply.started":"2024-03-01T13:26:41.398069Z","shell.execute_reply":"2024-03-01T13:26:41.404728Z"},"trusted":true},"execution_count":7,"outputs":[{"execution_count":7,"output_type":"execute_result","data":{"text/plain":"'Penso che questo sia un passo in avanti importante nella costruzione di uno spazio giuridico di libertà di circolazione e di protezione dei diritti per le persone in Europa.'"},"metadata":{}}]},{"cell_type":"code","source":"from transformers import SpeechT5Processor, SpeechT5ForTextToSpeech, SpeechT5HifiGan\n\nprocessor=SpeechT5Processor.from_pretrained(\"microsoft/speecht5_tts\")\n\nmodel = SpeechT5ForTextToSpeech.from_pretrained(\"microsoft/speecht5_tts\")\nvocoder = SpeechT5HifiGan.from_pretrained(\"microsoft/speecht5_hifigan\")","metadata":{"execution":{"iopub.status.busy":"2024-03-01T13:26:41.407305Z","iopub.execute_input":"2024-03-01T13:26:41.408535Z","iopub.status.idle":"2024-03-01T13:26:47.542417Z","shell.execute_reply.started":"2024-03-01T13:26:41.408492Z","shell.execute_reply":"2024-03-01T13:26:47.541084Z"},"trusted":true},"execution_count":8,"outputs":[{"output_type":"display_data","data":{"text/plain":"spm_char.model: 0%| | 0.00/238k [00:00","text/html":"\n \n "},"metadata":{}}]},{"cell_type":"code","source":"speech.shape","metadata":{"execution":{"iopub.status.busy":"2024-03-01T13:26:55.951199Z","iopub.execute_input":"2024-03-01T13:26:55.951595Z","iopub.status.idle":"2024-03-01T13:26:55.959532Z","shell.execute_reply.started":"2024-03-01T13:26:55.951540Z","shell.execute_reply":"2024-03-01T13:26:55.958228Z"},"trusted":true},"execution_count":12,"outputs":[{"execution_count":12,"output_type":"execute_result","data":{"text/plain":"torch.Size([28160])"},"metadata":{}}]},{"cell_type":"code","source":"import numpy as np\n\ntarget_dtype=np.int16\nmax_range=np.iinfo(target_dtype).max\n\ndef speech_to_speech_translation(audio):\n translated_text=translate(audio)\n synthesised_speech=synthesise(translated_text)\n synthesised_speech=(synthesised_speech.numpy()*max_range).astype(np.int16)\n return 16000, synthesised_speech","metadata":{"execution":{"iopub.status.busy":"2024-03-01T13:26:55.961230Z","iopub.execute_input":"2024-03-01T13:26:55.961671Z","iopub.status.idle":"2024-03-01T13:26:55.971675Z","shell.execute_reply.started":"2024-03-01T13:26:55.961641Z","shell.execute_reply":"2024-03-01T13:26:55.970401Z"},"trusted":true},"execution_count":13,"outputs":[]},{"cell_type":"code","source":"sampling_rate, synthesised_speech = speech_to_speech_translation(sample[\"audio\"])\n\nAudio(synthesised_speech, rate=sampling_rate)","metadata":{"execution":{"iopub.status.busy":"2024-03-01T13:26:55.972812Z","iopub.execute_input":"2024-03-01T13:26:55.973211Z","iopub.status.idle":"2024-03-01T13:27:13.291658Z","shell.execute_reply.started":"2024-03-01T13:26:55.973183Z","shell.execute_reply":"2024-03-01T13:27:13.290377Z"},"trusted":true},"execution_count":14,"outputs":[{"execution_count":14,"output_type":"execute_result","data":{"text/plain":"","text/html":"\n \n "},"metadata":{}}]},{"cell_type":"code","source":"import gradio as gr\n\ndemo = gr.Blocks()\n\nmic_translate = gr.Interface(\n fn=speech_to_speech_translation,\n inputs=gr.Audio(source=\"microphone\", type=\"filepath\"),\n outputs=gr.Audio(label=\"Generated Speech\", type=\"numpy\"),\n)\n\nfile_translate = gr.Interface(\n fn=speech_to_speech_translation,\n inputs=gr.Audio(source=\"upload\", type=\"filepath\"),\n outputs=gr.Audio(label=\"Generated Speech\", type=\"numpy\"),\n)\n\nwith demo:\n gr.TabbedInterface([mic_translate, file_translate], [\"Microphone\", \"Audio File\"])\n\ndemo.launch(debug=True, share=True)","metadata":{"execution":{"iopub.status.busy":"2024-03-01T13:27:13.293657Z","iopub.execute_input":"2024-03-01T13:27:13.294068Z"},"trusted":true},"execution_count":null,"outputs":[{"name":"stderr","text":"/opt/conda/lib/python3.10/site-packages/gradio/blocks.py:1025: UserWarning: api_name predict already exists, using predict_1\n warnings.warn(\n","output_type":"stream"},{"name":"stdout","text":"Running on local URL: http://127.0.0.1:7860\nRunning on public URL: https://de10cbb1a7bf29bcfb.gradio.live\n\nThis share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://huggingface.co/spaces)\n","output_type":"stream"},{"output_type":"display_data","data":{"text/plain":"","text/html":"
"},"metadata":{}}]},{"cell_type":"code","source":"!gradio deploy","metadata":{"execution":{"iopub.status.busy":"2024-03-01T13:29:39.201310Z","iopub.execute_input":"2024-03-01T13:29:39.201671Z","iopub.status.idle":"2024-03-01T13:29:40.236120Z","shell.execute_reply.started":"2024-03-01T13:29:39.201644Z","shell.execute_reply":"2024-03-01T13:29:40.235004Z"},"trusted":true},"execution_count":1,"outputs":[{"name":"stdout","text":"/bin/bash: gradio: command not found\n","output_type":"stream"}]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]} \ No newline at end of file