# Spaces error with custom webpage

**URL:** <https://discuss.huggingface.co/t/spaces-error-with-custom-webpage/41687>\
**Category:** Spaces\
**Created:** [May 31, 2023, 6:58pm UTC](https://discuss.huggingface.co/t/spaces-error-with-custom-webpage/41687 "2023-05-31T18:58:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![aus10powell](https://avatars.discourse-cdn.com/v4/letter/a/9de0a6/32.png) [@aus10powell](https://discuss.huggingface.co/u/aus10powell)\
**Post date:** [May 31, 2023, 6:59pm UTC](https://discuss.huggingface.co/t/spaces-error-with-custom-webpage/41687/1 "2023-05-31T18:59:00Z")

</div>

I have a call that is made using a FastAPI site that I built. I’m calling a “def generate\_response” function

`python @app.post("/api/generate") async def generate_text(request: Request):`  
`

This call works locally but fails when on huggingface spaces

Getting the following error: "Failed to fetch data. Reason: Network response was not ok. Status: 504 - "

---

<div class="post-metadata">

**Author:** ![radames](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/radames/32/28246_2.png) [@radames](https://discuss.huggingface.co/u/radames)\
**Post date:** [June 1, 2023, 11:09pm UTC](https://discuss.huggingface.co/t/spaces-error-with-custom-webpage/41687/2 "2023-06-01T23:09:50Z")

</div>

hi @aus10powell , could you please provide more context? we might be able to help you, do you have a Space demo? or Gradio project

---

<div class="post-metadata">

**Author:** ![aus10powell](https://avatars.discourse-cdn.com/v4/letter/a/9de0a6/32.png) [@aus10powell](https://discuss.huggingface.co/u/aus10powell)\
**Post date:** [June 1, 2023, 11:25pm UTC](https://discuss.huggingface.co/t/spaces-error-with-custom-webpage/41687/3 "2023-06-01T23:25:24Z")

</div>

Hi,

Thanks the spaces site is: [TwitterAccounts - a Hugging Face Space by aus10powell](https://huggingface.co/spaces/aus10powell/TwitterAccounts)

---

<div class="post-metadata">

**Author:** ![aus10powell](https://avatars.discourse-cdn.com/v4/letter/a/9de0a6/32.png) [@aus10powell](https://discuss.huggingface.co/u/aus10powell)\
**Post date:** [June 1, 2023, 11:26pm UTC](https://discuss.huggingface.co/t/spaces-error-with-custom-webpage/41687/4 "2023-06-01T23:26:29Z")

</div>

The code snippet in the post is within the app.py file if that helps. I’d be happy to add more detail but the code might make more sense. Please let me know if it needs to be broken down more.

---

<div class="post-metadata">

**Author:** ![radames](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/radames/32/28246_2.png) [@radames](https://discuss.huggingface.co/u/radames)\
**Post date:** [June 2, 2023, 2:21am UTC](https://discuss.huggingface.co/t/spaces-error-with-custom-webpage/41687/5 "2023-06-02T02:21:21Z")

</div>

sorry I don’t have access to your logs. Considering that you app is functional overall, my guess would be that the model loading in the POST request function is not ideal, could you move this to the app loading, thus loading the language package model only once

```auto
nlp = spacy.load("en_core_web_sm")
nlp.add_pipe("sentencizer")

```

---

<div class="post-metadata">

**Author:** ![aus10powell](https://avatars.discourse-cdn.com/v4/letter/a/9de0a6/32.png) [@aus10powell](https://discuss.huggingface.co/u/aus10powell)\
**Post date:** [June 3, 2023, 6:55pm UTC](https://discuss.huggingface.co/t/spaces-error-with-custom-webpage/41687/6 "2023-06-03T18:55:02Z")

</div>

I’ll play around with that thanks!
