Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot import name 'JsonValue' from 'pydantic' #8327

Closed
1 task done
BigMann123yt opened this issue May 18, 2024 · 5 comments
Closed
1 task done

cannot import name 'JsonValue' from 'pydantic' #8327

BigMann123yt opened this issue May 18, 2024 · 5 comments
Labels
bug Something isn't working pending clarification

Comments

@BigMann123yt
Copy link

Describe the bug

i was making an ai chatbot using gradio and openai api.
and it gave me this error

Traceback (most recent call last): File "" line 3, in <module> import gradio as gr File "C:\Users\krish\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\gradio\__init__.py", line 3, in <module> import gradio._simple_templates File "C:\Users\krish\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\gradio\_simple_templates\__init__.py", line 1, in <module> from .simpledropdown import SimpleDropdown File "C:\Users\krish\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\gradio\_simple_templates\simpledropdown.py", line 6, in <module> from gradio.components.base import FormComponent File "C:\Users\krish\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\gradio\components\__init__.py", line 1, in <module> from gradio.components.annotated_image import AnnotatedImage File "C:\Users\krish\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\gradio\components\annotated_image.py", line 13, in <module> from gradio import processing_utils, utils File "C:\Users\krish\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\gradio\processing_utils.py", line 22, in <module> from gradio import utils, wasm_utils File "C:\Users\krish\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\gradio\utils.py", line 54, in <module> from gradio.data_classes import FileData File "C:\Users\krish\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\gradio\data_classes.py", line 19, in <module> from pydantic import BaseModel, JsonValue, RootModel, ValidationError ImportError: cannot import name 'JsonValue' from 'pydantic' (C:\Users\krish\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\pydantic\__init__.cp311-win_amd64.pyd)

Please advice on what to do, it's also not showing JsonValue in the pydantic module required by gradio

Have you searched existing issues? 🔎

  • I have searched and found no existing issues

Reproduction

from gpt_index import SimpleDirectoryReader, GPTListIndex, GPTSimpleVectorIndex, LLMPredictor, PromptHelper
from langchain.chat_models import ChatOpenAI
import gradio as gr
import sys
import os

os.environ["OPENAI_API_KEY"] = 'Your API Key'

def construct_index(directory_path):
    max_input_size = 4096
    num_outputs = 512
    max_chunk_overlap = 20
    chunk_size_limit = 600

    prompt_helper = PromptHelper(max_input_size, 
                                num_outputs, 
                                max_chunk_overlap, 
                                chunk_size_limit=chunk_size_limit)

    llm_predictor = LLMPredictor(llm=ChatOpenAI(temperature=0.7, 
                                model_name="gpt-3.5-turbo", 
                                max_tokens=num_outputs))

    documents = SimpleDirectoryReader(directory_path).load_data()

    index = GPTSimpleVectorIndex(documents, 
                                llm_predictor=llm_predictor, 
                                prompt_helper=prompt_helper)

    index.save_to_disk('index.json')

    return index

def chatbot(input_text):
    index = GPTSimpleVectorIndex.load_from_disk('index.json')
    response = index.query(input_text, response_mode="compact")
    return response.response

iface = gr.Interface(fn=chatbot, 
                    inputs=gr.components.Textbox(lines=7, label="Enter your text"), 
                    outputs="text", 
                    title="Custom-trained AI Chatbot")

index = construct_index("docs")
iface.launch(share=True)

Screenshot

No response

Logs

Traceback (most recent call last):
  File "c:\Krishna Main\ISWK\Python Files\AI ChatBot\app.py", line 3, in <module>
    import gradio as gr
  File "C:\Users\krish\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\gradio\__init__.py", line 3, in <module>
    import gradio._simple_templates
  File "C:\Users\krish\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\gradio\_simple_templates\__init__.py", line 1, in <module>     
    from .simpledropdown import SimpleDropdown
  File "C:\Users\krish\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\gradio\_simple_templates\simpledropdown.py", line 6, in <module>
    from gradio.components.base import FormComponent
  File "C:\Users\krish\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\gradio\components\__init__.py", line 1, in <module>
    from gradio.components.annotated_image import AnnotatedImage
  File "C:\Users\krish\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\gradio\components\annotated_image.py", line 13, in <module>    
    from gradio import processing_utils, utils
  File "C:\Users\krish\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\gradio\processing_utils.py", line 22, in <module>
    from gradio import utils, wasm_utils
  File "C:\Users\krish\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\gradio\utils.py", line 54, in <module>
    from gradio.data_classes import FileData
  File "C:\Users\krish\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\gradio\data_classes.py", line 19, in <module>
    from pydantic import BaseModel, JsonValue, RootModel, ValidationError
ImportError: cannot import name 'JsonValue' from 'pydantic' (C:\Users\krish\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\pydantic\__init__.cp311-win_amd64.pyd)

System Info

Name: gradio
Version: 4.31.3
Summary: Python library for easily interacting with trained machine learning models
Home-page:
Author:
Author-email: Abubakar Abid <gradio-team@huggingface.co>, Ali Abid <gradio-team@huggingface.co>, Ali Abdalla <gradio-team@huggingface.co>, Dawood Khan <gradio-team@huggingface.co>, Ahsen Khaliq <gradio-team@huggingface.co>, Pete Allen <gradio-team@huggingface.co>, Ömer Faruk Özdemir <gradio-team@huggingface.co>, Freddy A Boulton <gradio-team@huggingface.co>, Hannah Blair <gradio-team@huggingface.co>
License:
Location: C:\Users\krish\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages
Requires: aiofiles, altair, fastapi, ffmpy, gradio-client, httpx, huggingface-hub, importlib-resources, jinja2, markupsafe, matplotlib, numpy, orjson, packaging, pandas, pillow, pydantic, pydub, python-multipart, pyyaml, ruff, semantic-version, tomlkit, typer, typing-extensions, urllib3, uvicorn
Required-by:

Severity

Blocking usage of gradio

@BigMann123yt BigMann123yt added the bug Something isn't working label May 18, 2024
@abidlabs
Copy link
Member

Hi @BigMann123yt it looks like you might be using an older version of pydantic -- can you please upgrade?

pip install --upgrade pydantic

@BigMann123yt
Copy link
Author

k that error got fixed, but now theres a different error

Traceback (most recent call last): File "c:\Krishna Main\ISWK\Python Files\AI ChatBot\app.py", line 1, in <module> from gpt_index import SimpleDirectoryReader, GPTListIndex, GPTSimpleVectorIndex, LLMPredictor, PromptHelper File "C:\Users\krish\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\gpt_index\__init__.py", line 14, in <module> from gpt_index.embeddings.langchain import LangchainEmbedding File "C:\Users\krish\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\gpt_index\embeddings\langchain.py", line 6, in <module> from langchain.embeddings.base import Embeddings as LCEmbeddings File "C:\Users\krish\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\langchain\__init__.py", line 6, in <module> from langchain.agents import MRKLChain, ReActChain, SelfAskWithSearchChain File "C:\Users\krish\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\langchain\agents\__init__.py", line 2, in <module> from langchain.agents.agent import ( File "C:\Users\krish\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\langchain\agents\agent.py", line 15, in <module> from langchain.agents.tools import InvalidTool File "C:\Users\krish\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\langchain\agents\tools.py", line 8, in <module> from langchain.tools.base import ( File "C:\Users\krish\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\langchain\tools\__init__.py", line 3, in <module> from langchain.tools.base import BaseTool File "C:\Users\krish\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\langchain\tools\base.py", line 16, in <module> from pydantic.main import ModelMetaclass ImportError: cannot import name 'ModelMetaclass' from 'pydantic.main' (C:\Users\krish\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\pydantic\main.py)

@freddyaboulton
Copy link
Collaborator

Hi @BigMann123yt ! You may need to update your langchain version. I can't repro this issue when importing langchain. Will close this as the issue does not seem related to gradio but I will open a PR to fallback to Any if JsonValue is not available in pydantic.

@gjnave
Copy link

gjnave commented May 23, 2024

yo BigMann.. did you figure this out?

@BigMann123yt
Copy link
Author

aah yes i did, thank you for the response anyways.
i downgraded a few of the imported modules and it worked properly without the error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pending clarification
Projects
None yet
Development

No branches or pull requests

4 participants