abdeladim-s / subsai

🎞️ Subtitles generation tool (Web-UI + CLI + Python package) powered by OpenAI's Whisper and its variants 🎞️
https://abdeladim-s.github.io/subsai/
GNU General Public License v3.0
1.25k stars 104 forks source link

Circular Import #28

Closed davidliaos closed 1 year ago

davidliaos commented 1 year ago

Debug

davidliao@Davids-MacBook-Air project %  /usr/bin/env /usr/local/bin/python3 /Users/davidliao/.vscode/extensions/ms-python.pyth
on-2023.6.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher 57695 -- /Users/davidliao/Desktop/project/srt.py 
Traceback (most recent call last):
  File "/Users/davidliao/Desktop/project/srt.py", line 2, in <module>
    from subsai import SubsAI
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/subsai/__init__.py", line 1, in <module>
    from subsai.main import SubsAI, Tools
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/subsai/main.py", line 27, in <module>
    from subsai.configs import AVAILABLE_MODELS
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/subsai/configs.py", line 8, in <module>
    from ffsubsync.constants import DEFAULT_MAX_SUBTITLE_SECONDS, DEFAULT_START_SECONDS, DEFAULT_MAX_OFFSET_SECONDS, \
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/ffsubsync/__init__.py", line 21, in <module>
    from .ffsubsync import main  # noqa
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/ffsubsync/ffsubsync.py", line 34, in <module>
    from ffsubsync.speech_transformers import (
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/ffsubsync/speech_transformers.py", line 23, in <module>
    from ffsubsync.generic_subtitles import GenericSubtitle
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/ffsubsync/generic_subtitles.py", line 9, in <module>
    import srt
  File "/Users/davidliao/Desktop/project/srt.py", line 2, in <module>
    from subsai import SubsAI
ImportError: cannot import name 'SubsAI' from partially initialized module 'subsai' (most likely due to a circular import) (/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/subsai/__init__.py)

Code

from subsai import SubsAI

def createsrt(path,name):
    file = f'./{path}/{name}.mp4'
    subs_ai = SubsAI()
    model = subs_ai.create_model('openai/whisper', {'model_type': 'base'})
    subs = subs_ai.transcribe(file, model)
    subs.save('test1.srt')

createsrt("mp4","input")

I am on MacOS Monterey, M2 Silicon using VSC, on latest release, have ffmpeg and setuptools-rust. Using Python 3.10.4, tried as well with 3.9.6

I'm unsure what to do here as I've never ran into a circular import error, but I just copied the code and replaced the path variable with my own. I've attempted to use it as a script/outside of the function but I am getting the same error.

Also, is this usable with mp3 files as well? Assuming that would be faster.

abdeladim-s commented 1 year ago

@davidliaos,

davidliaos commented 1 year ago

Thank you so much!

abdeladim-s commented 1 year ago

You are welcome :)