3
respostas

Problema na hora de executar script python

Houve alguma modificação na OpenAI? Ao tentar executar o script, obtive o seguinte erro:

You tried to access openai.Audio, but this is no longer supported in openai>=1.0.0 - see the README at https://github.com/openai/openai-python for the API.

You can run openai migrate to automatically upgrade your codebase to use the 1.0.0 interface.

Alternatively, you can pin your installation to the old version, e.g. pip install openai==0.28

A detailed migration guide is available here: https://github.com/openai/openai-python/discussions/742

codigo_alura) PS C:\Users\XXX\Documents\podcasts> openai migrate Error: Windows is not supported yet in the migration CLI

...

(codigo_alura) PS C:\Users\XXX\Documents\podcasts> pip install openai==0.28 Collecting openai==0.28 Using cached openai-0.28.0-py3-none-any.whl.metadata (13 kB) Collecting requests>=2.20 (from openai==0.28) Using cached requests-2.31.0-py3-none-any.whl.metadata (4.6 kB) Requirement already satisfied: tqdm in c:\users\XXX\documents\podcasts\codigo_alura\lib\site-packages (from openai==0.28) (4.66.1) Collecting aiohttp (from openai==0.28) Using cached aiohttp-3.9.1-cp312-cp312-win_amd64.whl.metadata (7.6 kB)

Building wheel for frozenlist (pyproject.toml) ... error error: subprocess-exited-with-error

× Building wheel for frozenlist (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [33 lines of output]

no previously-included directories found matching 'docs_build' adding license file 'LICENSE' writing manifest file 'frozenlist.egg-info\SOURCES.txt' copying frozenlist_init_.pyi -> build\lib.win-amd64-cpython-312\frozenlist copying frozenlist_frozenlist.pyx -> build\lib.win-amd64-cpython-312\frozenlist copying frozenlist\py.typed -> build\lib.win-amd64-cpython-312\frozenlist running build_ext building 'frozenlist._frozenlist' extension error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/ [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for frozenlist Building wheel for multidict (pyproject.toml) ... error error: subprocess-exited-with-error

3 respostas

Meu script:

import openai from dotenv import load_dotenv import os

def openai_whisper_transcrever(caminho_audio, nome_arquivo, modelo_whisper, openai): print("Estou transcrevendo com o Whisper…")

audio = open(caminho_audio, "rb")

resposta = openai.Audio.transcribe(
    api_key=openai.api_key,
    model = modelo_whisper,
    file = audio
)

transcricao = resposta.text

with open(f"texto_completo_{nome_arquivo}.txt", "w",encoding='utf-8') as arquivo_texto:
    arquivo_texto.write(transcricao)

return transcricao

def main(): load_dotenv()

caminho_audio = "podcasts/hipsters_154_testes_short.mp3"
nome_arquivo = "hipsters_154_testes_short"
url_podcast = "https://www.hipsters.tech/testes-de-software-e-inteligencia-artificial-hipsters-154/"

api_openai = os.getenv("API_KEY_OPENAI")
openai.api_key = api_openai

modelo_whisper = "whisper-1"

transcricao_completa = openai_whisper_transcrever(caminho_audio, nome_arquivo, modelo_whisper, openai)

if name == "main": main()

teve atualização sim, pelo o que vi em outro cursos eles falaram que tão trabalhando em regravações:

https://cursos.alura.com.br/course/gpt-python-criando-ferramentas-api/task/146338

Olá Lucas, tudo bem?

Segue a versão do código "atualizada" pra versão nova da biblioteca!


# aqui foi alterado para versão nova
from openai import OpenAI

def openai_whisper_transcrever(caminho_audio, nome_arquivo, modelo_whisper, cliente): 
    print("Estou transcrevendo com o Whisper…")
    audio = open(caminho_audio, "rb")

    # aqui foi alterado para versão nova
    resposta = cliente.audio.transcriptions.create(
        model = modelo_whisper,
        file = audio
    )

    transcricao = resposta.text

    with open(f"texto_completo_{nome_arquivo}.txt", "w",encoding='utf-8') as arquivo_texto:
        arquivo_texto.write(transcricao)

    return transcricao


caminho_audio = "podcasts/hipsters_154_testes_short.mp3"
nome_arquivo = "hipsters_154_testes_short"
url_podcast = "https://www.hipsters.tech/testes-de-software-e-inteligencia-artificial-hipsters-154/"

# aqui foi alterado para versão nova
cliente = OpenAI(api_key="SUA_CHAVE_AQUI")

modelo_whisper = "whisper-1"

transcricao_completa = openai_whisper_transcrever(caminho_audio, nome_arquivo, modelo_whisper, cliente)