Open AI Import Error

Hi Folks, Im facing the following error in my cloud:-

My requirements.txt as follows:-

streamlit
openai
googletrans==4.0.0.rc1

Cloud configuration:-

python==3.11

Github Repo
Cloud App

Im not understaning why the error is happening? Can anyone help to resolve the error…?

Regards
Guna Sekhar.

That is because googletrans is incompatible with recent versions of openai. googletrans has been abandoned for almost 4 years.

@Goyo is there any solution to solve this issue?

I think your best option is looking for an alternative to googletrans. Note that you can send http requests to a translation api, you don’t need a dedicated python library for that.

Guna Sekhar try the following, Best regards .
-Alejandro Samid

  • Verify Requirements File: Ensure your requirements.txt file includes the openai module.
  • Install Missing Module: Make sure the openai module is installed in your environment.
  • Environment Check: Confirm your Streamlit app is running in the environment where openai is installed.
  • Streamlit Cloud Configuration: Verify that the requirements.txt file is correctly configured and placed in the root directory of your project.
  • Re-deploy the App: Re-deploy your Streamlit app to ensure the changes take effect.

By following these steps, you should be able to resolve the OpenAI Import Error and get your Streamlit app running smoothly.

Guna Sekha, try the following, Best regards .
-Alejandro Samid

To address the compatibility issue between googletrans and recent versions of openai, you can switch to an alternative translation library. Here’s a step-by-step guide to update your project:

  1. Remove googletrans from your requirements.txt file.
  2. Choose an alternative translation library. Based on the search results, deep-translator is a good option as it’s actively maintained and offers multiple translation services.
  3. Update your requirements.txt file to include the new library:
streamlit
openai
deep-translator
  1. Update your code to use the new library. Here’s an example using deep-translator with Google Translate:

python

from deep_translator import GoogleTranslator

translator = GoogleTranslator(source='auto', target='es')
translation = translator.translate("Hello, world!")
print(translation)
  1. Install the new library in your development environment:
pip install deep-translator
  1. Test your updated code to ensure it works as expected.
  2. Commit the changes to your GitHub repository.
  3. Re-deploy your Streamlit app to apply the changes.

Using deep-translator offers several advantages:

  • It supports multiple translation services, including Google Translate, Microsoft Translator, and others.
  • It can be used directly from the terminal.
  • It supports batch translations.
  • It allows translations from text files.

However, note that language detection with deep-translator requires a private API key.

By following these steps, you should resolve the compatibility issue between googletrans and openai while maintaining the translation functionality in your Streamlit app.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.