0

when I run my code :

import openai
import gradio

openai.api_key = "REDACTED_OPENAI_KEY"

messages = [{"role": "system", "content": "You are a financial experts that specializes in real                  estate investment and negotiation"}]

def CustomChatGPT(user_input):
  messages.append({"role": "user", "content": user_input})
  response = openai.ChatCompletion.create(
    model = "gpt-3.5-turbo",
    messages = messages
  )
   ChatGPT_reply = response["choices"][0]["message"]["content"]
   messages.append({"role": "assistant", "content": ChatGPT_reply})
  return ChatGPT_reply

demo = gradio.Interface(fn=CustomChatGPT, inputs = "text", outputs = "text", title = "Real        Estate Pro")

demo.launch(share=True)

in the terminal it returns:

PS C:\Users\gdcou\.vscode\pyProjects> & C:/Python311/python.exe "c:/Users/gdcou/Downloads/03 chatgpt chat assistant website.py"
Traceback (most recent call last):
  File "c:\Users\gdcou\Downloads\03 chatgpt chat assistant website.py", line 2, in <module>
    import gradio
ModuleNotFoundError: No module named 'gradio'

Thank you for your help

picsoung
  • 6,314
  • 1
  • 18
  • 35
Gabe coupal
  • 11
  • 1
  • 1

2 Answers2

1

Looks like it isn't installed. Run this command in the terminal:

pip install gradio

If it is installed and code still throws the same error, then place these two lines first:

import sys
sys.path.append( path_to_the_gradio_module )

import openai
import gradio
# ...

But you need to replace path_to_the_gradio_module with the actual path to this module. For example (this path will not work. You should understand from this path what I mean): C:\\Users\\User\\AppData\\Local\\Programs\\Python\\Python3.VERSION\\Lib\\Gradio

NotMEE12
  • 74
  • 7
  • now it returns : PS C:\Users\gdcou.vscode\pyProjects> & C:/Python311/python.exe "c:/Users/gdcou/Downloads/03 chatgpt chat assistant website.py" Traceback (most recent call last): File "c:\Users\gdcou\Downloads\03 chatgpt chat assistant website.py", line 2, in sys.path.append( path_to_the_gradio_module ) ^^^^^^^^^^^^^^^^^^^^^^^^^ NameError: name 'path_to_the_gradio_module' is not defined – Gabe coupal Apr 01 '23 at 07:16
  • I edited my answer so it can be more understandable @Gabe coupal – NotMEE12 Apr 01 '23 at 07:18
  • It doesn't seem to show gradio in my lib folder. I tried installing it again and it returns : PS C:\Users\gdcou\.vscode\pyProjects> pip install gradio *had to delete repeting stuff* WARNING: Failed to write executable - trying to use .deleteme logic ERROR: Could not install packages due to an OSError: [WinError 2] The system cannot find the file specified: 'C:\\Python311\\Scripts\\uvicorn.exe' -> 'C:\\Python311\\Scripts\\uvicorn.exe.deletem [notice] A new release of pip available: 22.3 -> 23.0.1 [notice] To update, run: python.exe -m pip install --upgrade pip – Gabe coupal Apr 01 '23 at 07:39
  • What about this path example `C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python3.VERSION\\Lib\site-packages` (first try without the `gradio` , and if the error still occurs find the gradio path and use it) – NotMEE12 Apr 01 '23 at 07:54
1

I came across this error using python version 3.11 in VSCODE. I changed the usage version to 3.9 using virtualenv and it worked normally.