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

422 - Strange fields required, does not allow for custom input #5601

Closed
1 task done
LifeBoey opened this issue Sep 19, 2023 · 7 comments
Closed
1 task done

422 - Strange fields required, does not allow for custom input #5601

LifeBoey opened this issue Sep 19, 2023 · 7 comments
Labels
bug Something isn't working pending clarification

Comments

@LifeBoey
Copy link

Describe the bug

Hi there, I am currently learning how to use gradio by using a simple example.

I am unable to use gradio as intended, and trying to rectify the errors as intended as led me to a rather restrictive use of gradio where I cannot submit any custom inputs to be processed.

Launching the app led to a problem where it would not accept any input except for a particular format as shown in the reproduction; with a 'naive' way of requesting it would return a 422 error with some very strange fields required that I don't know why they're required.

{'detail': [{'type': 'missing',
   'loc': ['body', 'session_hash'],
   'msg': 'Field required',
   'input': {'name': 'John'},
   'url': 'https://errors.pydantic.dev/2.3/v/missing'},
  {'type': 'missing',
   'loc': ['body', 'example_id'],
   'msg': 'Field required',
   'input': {'name': 'John'},
   'url': 'https://errors.pydantic.dev/2.3/v/missing'},
  {'type': 'missing',
   'loc': ['body', 'data'],
   'msg': 'Field required',
   'input': {'name': 'John'},
   'url': 'https://errors.pydantic.dev/2.3/v/missing'},
  {'type': 'missing',
   'loc': ['body', 'state'],
   'msg': 'Field required',
   'input': {'name': 'John'},
   'url': 'https://errors.pydantic.dev/2.3/v/missing'},
  {'type': 'missing',
   'loc': ['body', 'fn_index'],
   'msg': 'Field required',
   'input': {'name': 'John'},
   'url': 'https://errors.pydantic.dev/2.3/v/missing'},
  {'type': 'missing',
   'loc': ['body', 'cleared'],
   'msg': 'Field required',
   'input': {'name': 'John'},
   'url': 'https://errors.pydantic.dev/2.3/v/missing'}]}

Changing this to the new request as show in the reproduction would also result in an error of NoneType having no index; the basic problem being that the interface is not initiated with examples, and the example_id is overriding any data provided.

When the interface is initiated with examples, say with examples=['Mary'], the request does return a 200 response, but because of the example_id override, it returns "Hello Mary!" instead of "Hello John!"

I'd like to find out how to rectify this issue so that I can pass in my own input into the gradio app without the need for examples.

Have you searched existing issues? 🔎

  • I have searched and found no existing issues

Reproduction

Code of app launched:

import gradio as gr

def greet(name):
    return "Hello " + name + "!"

demo = gr.Interface(fn=greet, inputs="text", outputs="text")
    
demo.launch()  

Code of naive request launched:

import requests
import json

# Define the URL of your Gradio app
gradio_app_url = "http://localhost:7860/api/predict"  # Replace with the actual URL of your app

# Define the input data
input_data = {"name": "John"}

# Make a POST request to the Gradio app's API endpoint
response = requests.post(gradio_app_url, json=input_data)

Code of changed request launched:

response = requests.post(url=gradio_app_url, json={"data": ["John"],
                                                                    "session_hash": "",
                                                                    "example_id": 0,
                                                                    "state": "",
                                                                    "fn_index": 0,
                                                                    "cleared": True})

Screenshot

Error when using the gradio UI directly:

image

Logs

No response

System Info

Here due to the circumstances of the gradio version to use I can only use gradio version 2.9.4. At first I was facing an issue prescribed in https://github.com/gradio-app/gradio/issues/1203 but I managed to fix it as per the solution inside it.

Severity

Blocking usage of gradio

@LifeBoey LifeBoey added the bug Something isn't working label Sep 19, 2023
@pngwn
Copy link
Member

pngwn commented Sep 19, 2023

Can you provide more information on why you can only use version 2.9.4?

I'm afraid this version is no longer maintained and it will be difficult to figure out or fix what is happening here. Not only is the current version 3.x but we also working on 4.x and have no plans to maintain previous major versions unfortunately.

@LifeBoey
Copy link
Author

The reason for using 2.9.4 is because I plan to use gradio in an offline/airgapped environment. Gradio 3 is unable to support working in such an environment as it needs to pull in fonts, css, js from a CDN.

@pngwn
Copy link
Member

pngwn commented Sep 20, 2023

Hmm. I thought we mostly fixed this issue.

Does gradio not work at all offline for you or is it just certain components?

@LifeBoey
Copy link
Author

Not at all, no. Admittedly this is more of how my colleagues have tested it but the environment is gradio 2.9.4 and there are no plans to upgrade it unless it can work offline.

Believe the issue is still open? #1450

@pngwn
Copy link
Member

pngwn commented Sep 21, 2023

We'll get that fixed as soon as we can, we don't want people downgrading for this reason. New gradio is lots better!

@freddyaboulton
Copy link
Collaborator

Thanks @LifeBoey !

Looks like you're using pydantic version 2, which is only supported on recent versions of gradio. Please downgrade to version 1. Also, the API expects the input data to be passed in a list on the "data" key of the json object. You can get info on how to use the API by clicking the view the API button in the bottom.

After making those two changes, the api works for me

image

Let's close this out since it's tracked by #1450.

@arushijain71
Copy link

Hi, I am using Gradio 3.34.0 but I am also facing same issue.
using following code:

import gradio as gr
def greet(name):
    return "Hello " + name + "!"
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
demo.launch()

I am getting following error in UI:
image

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