deepgram / deepgram-python-sdk

Official Python SDK for Deepgram's automated speech recognition APIs.
https://developers.deepgram.com
MIT License
175 stars 47 forks source link

Issue with Prerecorded Local File Transcription on Vercel #406

Closed duotangx closed 1 month ago

duotangx commented 1 month ago

What is the current behavior?

I am running into an issue with prerecorded local file transcription (v3 SDK) since Vercel does not support web sockets (afaik).

Steps to reproduce

Use the example.py file here: https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/prerecorded/file/main.py

Expected behavior

Goal is to transcribe local prerecorded audio file using Vercel Serverless functions.

Please tell us about your environment

Other information

Appears to be driven by lack of websockets support unless I'm missing/misspecified something.

Full traceback running 'vercel dev' locally:

Traceback (most recent call last):
  File "/Users/user/Library/Caches/com.vercel.fun/runtimes/python3/../python/bootstrap.py", line 147, in <module>
    lambda_runtime_main()
  File "/Users/user/Library/Caches/com.vercel.fun/runtimes/python3/../python/bootstrap.py", line 127, in lambda_runtime_main
    fn = lambda_runtime_get_handler()
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/Library/Caches/com.vercel.fun/runtimes/python3/../python/bootstrap.py", line 113, in lambda_runtime_get_handler
    mod = importlib.import_module(module_name)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/var/folders/dk/x1vx9sqx6fd2994rb430p4840000gn/T/zeit-fun-e58d5740bae4/vc__handler__python.py", line 13, in <module>
    __vc_spec.loader.exec_module(__vc_module)
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/private/var/folders/dk/x1vx9sqx6fd2994rb430p4840000gn/T/zeit-fun-e58d5740bae4/./api/index.py", line 2, in <module>
    from deepgram import DeepgramClient, PrerecordedOptions, FileSource
  File "/var/folders/dk/x1vx9sqx6fd2994rb430p4840000gn/T/zeit-fun-e58d5740bae4/deepgram/__init__.py", line 9, in <module>
    from .client import Deepgram, DeepgramClient
  File "/var/folders/dk/x1vx9sqx6fd2994rb430p4840000gn/T/zeit-fun-e58d5740bae4/deepgram/client.py", line 11, in <module>
    from .clients import ListenClient
  File "/var/folders/dk/x1vx9sqx6fd2994rb430p4840000gn/T/zeit-fun-e58d5740bae4/deepgram/clients/__init__.py", line 6, in <module>
    from .listen import ListenClient
  File "/var/folders/dk/x1vx9sqx6fd2994rb430p4840000gn/T/zeit-fun-e58d5740bae4/deepgram/clients/listen.py", line 27, in <module>
    from .live.client import (
  File "/var/folders/dk/x1vx9sqx6fd2994rb430p4840000gn/T/zeit-fun-e58d5740bae4/deepgram/clients/live/__init__.py", line 5, in <module>
    from .client import LiveClient
  File "/var/folders/dk/x1vx9sqx6fd2994rb430p4840000gn/T/zeit-fun-e58d5740bae4/deepgram/clients/live/client.py", line 5, in <module>
    from .v1.client import LiveClient as LiveClientLatest
  File "/var/folders/dk/x1vx9sqx6fd2994rb430p4840000gn/T/zeit-fun-e58d5740bae4/deepgram/clients/live/v1/__init__.py", line 5, in <module>
    from .client import LiveClient
  File "/var/folders/dk/x1vx9sqx6fd2994rb430p4840000gn/T/zeit-fun-e58d5740bae4/deepgram/clients/live/v1/client.py", line 5, in <module>
    from websockets.sync.client import connect
ModuleNotFoundError: No module named 'websockets.sync'
LambdaError: RequestId: abb32456-8085-47b2-ae00-d2f063d8b9a8 Process exited before completing request
    at Lambda.<anonymous> (/opt/homebrew/lib/node_modules/vercel/node_modules/@vercel/fun/dist/src/index.js:110:27)
    at Generator.next (<anonymous>)
    at fulfilled (/opt/homebrew/lib/node_modules/vercel/node_modules/@vercel/fun/dist/src/index.js:24:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

requirements.txt:

aiohttp==3.8.6
aiosignal==1.3.1
aniso8601==9.0.1
asgiref==3.6.0
async-timeout==4.0.3
attrs==23.1.0
charset-normalizer==3.3.1
click==8.1.7
deepgram-sdk==3.*
Flask==2.2.5
Flask-Cors==3.0.10
Flask-RESTful==0.3.9
frozenlist==1.4.0
idna==3.4
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.3
multidict==6.0.4
python-dotenv==1.0.0
pytz==2023.3.post1
six==1.16.0
websockets==12.0
Werkzeug==3.0.1
yarl==1.9.2
dvonthenen commented 1 month ago

Hi @duotangx

If you are trying locally and not doing a pip install you need to install the dependencies of the SDK.

From the root of the repo: pip install -r requirements.txt

If you want to run any of the examples, you need to install the dependencies the examples have:

cd examples
pip install -r requirements-examples.txt

You can find this documented on the readme: https://github.com/deepgram/deepgram-python-sdk?tab=readme-ov-file#prerequisites https://github.com/deepgram/deepgram-python-sdk/tree/main/examples

duotangx commented 1 month ago

Hi @dvonthenen, thanks for your help.

I did run pip install with the requirements.txt file that I shared and verified the dependencies were installed in my venv prior to running 'vercel dev'.

dvonthenen commented 1 month ago

Can you run this example https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/streaming/http/main.py

duotangx commented 1 month ago

I think this is vercel serverless functions related.

DG probably requires third party provider to run on vercel per https://vercel.com/guides/do-vercel-serverless-functions-support-websocket-connections

dvonthenen commented 1 month ago

Yea, you might want to ask the peeps in Discord. You can join by clicking the link below. The general chat section is a great place for this kind of question https://dpgr.am/discord

I haven't use Vercel so I won't be able to help . Since this isn't python SDK related, closing out this issue.