# Adapting a model from Spaces to Inference Endpoint

**URL:** <https://discuss.huggingface.co/t/adapting-a-model-from-spaces-to-inference-endpoint/26609>\
**Category:** Inference Endpoints on the Hub\
**Created:** [November 23, 2022, 10:09pm UTC](https://discuss.huggingface.co/t/adapting-a-model-from-spaces-to-inference-endpoint/26609 "2022-11-23T22:09:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![plexus3d](https://avatars.discourse-cdn.com/v4/letter/p/f08c70/32.png) [@plexus3d](https://discuss.huggingface.co/u/plexus3d)\
**Post date:** [November 23, 2022, 10:09pm UTC](https://discuss.huggingface.co/t/adapting-a-model-from-spaces-to-inference-endpoint/26609/1 "2022-11-23T22:09:25Z")

</div>

I have a custom inference pipeline working as a Spaces app: it look like there is no easy route to deploy as an Inference Endpoint. Is that correct?

I have seen the [custom inference handler](https://www.philschmid.de/custom-inference-handler) notes Phil posted, but would love more detail as my input and output is different than the one example given.

Thanks for any starting points or forum links I’ve overlooked…

---

<div class="post-metadata">

**Author:** ![philschmid](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/philschmid/32/38022_2.png) [@philschmid](https://discuss.huggingface.co/u/philschmid)\
**Post date:** [November 24, 2022, 6:28am UTC](https://discuss.huggingface.co/t/adapting-a-model-from-spaces-to-inference-endpoint/26609/2 "2022-11-24T06:28:20Z")

</div>

Hello @plexus3d,

You can directly deploy your custom inference pipeline as an inference endpoint using a custom container. This would mean creating a model repository with your space code and then using a custom docker with gradio. Here is an example: [philschmid/space-naver-donut-cord · Hugging Face](https://huggingface.co/philschmid/space-naver-donut-cord).

Additionally, as you mentioned, you can create a [custom inference handler.](https://huggingface.co/docs/inference-endpoints/guides/custom_handler) In the documentation, we have several examples on how to do this: \* [Optimum and ONNX Runtime](https://huggingface.co/philschmid/distilbert-onnx-banking77)

- [Diffusers with stable-diffusion](https://huggingface.co/philschmid/stable-diffusion-v1-4-endpoints)
- [Image Embeddings with BLIP](https://huggingface.co/florentgbelidji/blip_image_embeddings)
- [TrOCR for OCR Detection](https://huggingface.co/philschmid/trocr-base-printed)
- [Optimized Sentence Transformers with Optimum](https://huggingface.co/philschmid/all-MiniLM-L6-v2-optimum-embeddings)
- [Pyannote Speaker diarization](https://huggingface.co/philschmid/pyannote-speaker-diarization-endpoint)
- [LayoutLM](https://huggingface.co/philschmid/layoutlm-funsd)
- [Flair NER](https://huggingface.co/philschmid/flair-ner-english-ontonotes-large)
- [GPT-J 6B Single GPU](https://huggingface.co/philschmid/gpt-j-6B-fp16-sharded)
- [Donut Document understanding](https://huggingface.co/philschmid/donut-base-finetuned-cord-v2)
- [SetFit classifier](https://huggingface.co/philschmid/setfit-ag-news-endpoint)

* * *

Or you can use the API from your Spaces

---

<div class="post-metadata">

**Author:** ![plexus3d](https://avatars.discourse-cdn.com/v4/letter/p/f08c70/32.png) [@plexus3d](https://discuss.huggingface.co/u/plexus3d)\
**Post date:** [November 24, 2022, 10:05pm UTC](https://discuss.huggingface.co/t/adapting-a-model-from-spaces-to-inference-endpoint/26609/3 "2022-11-24T22:05:17Z")

</div>

Thanks @philschmid for a characteristically fine response, with much detail. Your last line suggestion seems simplest – simply calling the existing gradio API in the existing Space.

At the risk of sidetracking, following your suggestion is there a way to meter Spaces via an API? That is, to set ‘running’ and ‘stopped’ states via code. I ask because I believe Spaces activate as ‘running’ and then charge 24/7 (for CPU/GPU upgrades). I’m looking to run a Space selectively. Any hints?

---

<div class="post-metadata">

**Author:** ![philschmid](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/philschmid/32/38022_2.png) [@philschmid](https://discuss.huggingface.co/u/philschmid)\
**Post date:** [November 25, 2022, 7:03am UTC](https://discuss.huggingface.co/t/adapting-a-model-from-spaces-to-inference-endpoint/26609/4 "2022-11-25T07:03:01Z")

</div>

I am not sure about that one I think it is possible to programmatically change the Hardware but not sure about stopping. You could ask in #spaces
