# API of working gradio App responding with empty error

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fapi-of-working-gradio-app-responding-with-empty-error%2F68347%3E%5C
**Category:** Beginners\
**Created:** [January 8, 2024, 9:52am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fapi-of-working-gradio-app-responding-with-empty-error%2F68347 "2024-01-08T09:52:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![beelzeebuub](https://avatars.discourse-cdn.com/v4/letter/b/e47774/32.png) [@beelzeebuub](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fbeelzeebuub)%5C
**Post date:** [January 8, 2024, 9:52am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fapi-of-working-gradio-app-responding-with-empty-error%2F68347%2F1 "2024-01-08T09:52:10Z")

</div>

I have trained a model for Image classification and I am trying to host it on huggingface. The gradio app I made works fine but the minimal JS API example does not even work. I am following a tutorial from Jeremy Howard, and everything looks so straight forward, but wont work in the huggingface space I am using. I think this may have something to do with the job queue that should handle my API calls?

Please someone point me in the right direction I could not find anything on this problem on the forum or in the documentation.

Thank you all in advance.

my code:

```auto
# %% ModelTester.ipynb 1
from fastai.vision.all import *
import gradio as gr

# %% ModelTester.ipynb 3
from fastai.metrics import Metric

class OrdinalRegressionMetric(Metric):
    def __init__ (self):
        super(). __init__ ()
        self.total = 0
        self.count = 0

    def accumulate(self, learn):
        # Get predictions and targets
        preds, targs = learn.pred, learn.y

        # Your custom logic to convert predictions and targets to numeric values
        preds_numeric = torch.argmax(preds, dim=1)
        targs_numeric = targs

        # Calculate the metric (modify this based on your specific needs)
        squared_diff = torch.sum(torch.sqrt((preds_numeric - targs_numeric)**2))

        # Normalize by the maximum possible difference
        max_diff = torch.sqrt((torch.max(targs_numeric) - torch.min(targs_numeric))**2)

        # Update the metric value
        self.total += squared_diff
        #print("self.total: ",self.total)
        self.count += max_diff
        #print("self.count: ",self.count)
    @property
    def value(self):
        if self.count == 0:
            return 0.0 # or handle this case appropriately
        # Calculate the normalized metric value
        metric_value = 1/(self.total / self.count)
        return metric_value

# %% ModelTester.ipynb 4
learn = load_learner("textfile3-2.pk1")

# %% ModelTester.ipynb 6
categories = ("1","1-2","2","2-3","3","3-4","4","4-5","5")

def classify_image(img):
    pred, idx, probs = learn.predict(img)
    return dict(zip(categories, map(float, probs)))

# %% ModelTester.ipynb 8

intf = gr.Interface(fn=classify_image, inputs='image', outputs='label')
intf.launch(inline=False)

```

the generated API example:

```auto
import { client } from "@gradio/client";

const response_0 = await fetch("https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png");
const exampleImage = await response_0.blob();
						
const app = await client("https://beelzeebuub-fjgradiominimal.hf.space/--replicas/3xqpt/");
const result = await app.predict("/predict", [
				exampleImage, // blob in 'img' Image component
	]);

console.log(result.data);`

```

The log from my gradio app:  
===== Application Startup at 2024-01-08 09:39:00 =====

Running on local URL: [http://0.0.0.0:7860](http://0.0.0.0:7860)

To create a public link, set `share=True` in `launch()`.  
/home/user/.local/lib/python3.10/site-packages/fastai/torch\_core.py:263: UserWarning: ‘has\_mps’ is deprecated, please use ‘torch.backends.mps.is\_built()’  
return getattr(torch, ‘has\_mps’, False)  
Traceback (most recent call last):  
File “/home/user/.local/lib/python3.10/site-packages/gradio/queueing.py”, line 489, in call\_prediction  
output = await route\_utils.call\_process\_api(  
File “/home/user/.local/lib/python3.10/site-packages/gradio/route\_utils.py”, line 232, in call\_process\_api  
output = await app.get\_blocks().process\_api(  
File “/home/user/.local/lib/python3.10/site-packages/gradio/blocks.py”, line 1531, in process\_api  
inputs = self.preprocess\_data(fn\_index, inputs, state)  
File “/home/user/.local/lib/python3.10/site-packages/gradio/blocks.py”, line 1307, in preprocess\_data  
inputs\_cached = block.data\_model(\*\*inputs\_cached) # type: ignore  
File “/home/user/.local/lib/python3.10/site-packages/pydantic/main.py”, line 164, in **init**  
**pydantic\_self**. **pydantic\_validator**.validate\_python(data, self\_instance= **pydantic\_self** )  
pydantic\_core.\_pydantic\_core.ValidationError: 1 validation error for FileData  
path  
Field required [type=missing, input\_value={}, input\_type=dict]  
For further information visit [Redirecting...](https://errors.pydantic.dev/2.5/v/missing)  
===== Application Startup at 2024-01-08 09:39:00 =====

Running on local URL: [http://0.0.0.0:7860](http://0.0.0.0:7860)

To create a public link, set `share=True` in `launch()`.  
/home/user/.local/lib/python3.10/site-packages/fastai/torch\_core.py:263: UserWarning: ‘has\_mps’ is deprecated, please use ‘torch.backends.mps.is\_built()’  
return getattr(torch, ‘has\_mps’, False)  
Traceback (most recent call last):  
File “/home/user/.local/lib/python3.10/site-packages/gradio/queueing.py”, line 489, in call\_prediction  
output = await route\_utils.call\_process\_api(  
File “/home/user/.local/lib/python3.10/site-packages/gradio/route\_utils.py”, line 232, in call\_process\_api  
output = await app.get\_blocks().process\_api(  
File “/home/user/.local/lib/python3.10/site-packages/gradio/blocks.py”, line 1531, in process\_api  
inputs = self.preprocess\_data(fn\_index, inputs, state)  
File “/home/user/.local/lib/python3.10/site-packages/gradio/blocks.py”, line 1307, in preprocess\_data  
inputs\_cached = block.data\_model(\*\*inputs\_cached) # type: ignore  
File “/home/user/.local/lib/python3.10/site-packages/pydantic/main.py”, line 164, in **init**  
**pydantic\_self**. **pydantic\_validator**.validate\_python(data, self\_instance= **pydantic\_self** )  
pydantic\_core.\_pydantic\_core.ValidationError: 1 validation error for FileData  
path  
Field required [type=missing, input\_value={}, input\_type=dict]  
For further information visit [Redirecting...](https://errors.pydantic.dev/2.5/v/missing)  
===== Application Startup at 2024-01-08 09:39:00 =====

Running on local URL: [http://0.0.0.0:7860](http://0.0.0.0:7860)

To create a public link, set `share=True` in `launch()`.  
/home/user/.local/lib/python3.10/site-packages/fastai/torch\_core.py:263: UserWarning: ‘has\_mps’ is deprecated, please use ‘torch.backends.mps.is\_built()’  
return getattr(torch, ‘has\_mps’, False)  
Traceback (most recent call last):  
File “/home/user/.local/lib/python3.10/site-packages/gradio/queueing.py”, line 489, in call\_prediction  
output = await route\_utils.call\_process\_api(  
File “/home/user/.local/lib/python3.10/site-packages/gradio/route\_utils.py”, line 232, in call\_process\_api  
output = await app.get\_blocks().process\_api(  
File “/home/user/.local/lib/python3.10/site-packages/gradio/blocks.py”, line 1531, in process\_api  
inputs = self.preprocess\_data(fn\_index, inputs, state)  
File “/home/user/.local/lib/python3.10/site-packages/gradio/blocks.py”, line 1307, in preprocess\_data  
inputs\_cached = block.data\_model(\*\*inputs\_cached) # type: ignore  
File “/home/user/.local/lib/python3.10/site-packages/pydantic/main.py”, line 164, in **init**  
**pydantic\_self**. **pydantic\_validator**.validate\_python(data, self\_instance= **pydantic\_self** )  
pydantic\_core.\_pydantic\_core.ValidationError: 1 validation error for FileData  
path  
Field required [type=missing, input\_value={}, input\_type=dict]  
For further information visit [Redirecting...](https://errors.pydantic.dev/2.5/v/missing)

The Response from the API:  
Uncaught (in promise)  
Object { type: “status”, endpoint: “/predict”, fn\_index: 0, time: Date Mon Jan 08 2024 10:37:41 GMT+0100 (Central European Standard Time), queue: true, message: null, stage: “error”, code: undefined, success: false }  
runtime-core.esm-bundler.js:221:6  
logError runtime-core.esm-bundler.js:221  
handleError runtime-core.esm-bundler.js:208  
callWithAsyncErrorHandling runtime-core.esm-bundler.js:169  
(Async: promise callback)  
callWithAsyncErrorHandling runtime-core.esm-bundler.js:168  
invoker runtime-dom.esm-bundler.js:595  
(Async: EventListener.handleEvent)  
addEventListener runtime-dom.esm-bundler.js:549  
patchEvent runtime-dom.esm-bundler.js:564  
patchProp runtime-dom.esm-bundler.js:628  
mountElement runtime-core.esm-bundler.js:5297  
processElement runtime-core.esm-bundler.js:5244  
patch runtime-core.esm-bundler.js:5116  
mountChildren runtime-core.esm-bundler.js:5372  
mountElement runtime-core.esm-bundler.js:5279  
processElement runtime-core.esm-bundler.js:5244  
patch runtime-core.esm-bundler.js:5116  
componentUpdateFn runtime-core.esm-bundler.js:5796  
run reactivity.esm-bundler.js:178  
update runtime-core.esm-bundler.js:5902  
setupRenderEffect runtime-core.esm-bundler.js:5910  
mountComponent runtime-core.esm-bundler.js:5700  
processComponent runtime-core.esm-bundler.js:5653  
patch runtime-core.esm-bundler.js:5128  
componentUpdateFn runtime-core.esm-bundler.js:5861  
run reactivity.esm-bundler.js:178  
update runtime-core.esm-bundler.js:5902  
callWithErrorHandling runtime-core.esm-bundler.js:158  
flushJobs runtime-core.esm-bundler.js:365  
(Async: promise callback)  
queueFlush runtime-core.esm-bundler.js:275  
queueJob runtime-core.esm-bundler.js:269  
effect runtime-core.esm-bundler.js:5898  
triggerEffect reactivity.esm-bundler.js:373  
triggerEffects reactivity.esm-bundler.js:363  
triggerRefValue reactivity.esm-bundler.js:971  
effect reactivity.esm-bundler.js:1128  
triggerEffect reactivity.esm-bundler.js:373  
triggerEffects reactivity.esm-bundler.js:358  
triggerRefValue reactivity.esm-bundler.js:971  
effect reactivity.esm-bundler.js:1128  
triggerEffect reactivity.esm-bundler.js:373  
triggerEffects reactivity.esm-bundler.js:358  
triggerRefValue reactivity.esm-bundler.js:971  
effect reactivity.esm-bundler.js:1128  
triggerEffect reactivity.esm-bundler.js:373  
triggerEffects reactivity.esm-bundler.js:358  
triggerRefValue reactivity.esm-bundler.js:971  
effect reactivity.esm-bundler.js:1128  
triggerEffect reactivity.esm-bundler.js:373  
triggerEffects reactivity.esm-bundler.js:358  
triggerRefValue reactivity.esm-bundler.js:971  
set value reactivity.esm-bundler.js:1015  
finalizeNavigation vue-router.mjs:3353  
pushWithRedirect vue-router.mjs:3218  
(Async: promise callback)  
pushWithRedirect vue-router.mjs:3185  
push vue-router.mjs:3110  
install vue-router.mjs:3551  
use runtime-core.esm-bundler.js:3786  
 main.js:12
