# 3D model from single photo

### Prerequisites

* blender >= 3.5

## An example of work from all our service offerings

The full pipeline of our services allows you to receive one photo of a person with a digital avatar.

<div><figure><img src="https://1042198524-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6orDwlXzPvb3WASo4u11%2Fuploads%2FtUCynI1B0OmAxb22yxuk%2Fimg000700811.png?alt=media&#x26;token=6529b411-b153-4e57-a1a6-0b2070a7097f" alt=""><figcaption></figcaption></figure> <figure><img src="https://1042198524-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6orDwlXzPvb3WASo4u11%2Fuploads%2FPXpYOTBGLnPP66sU7yYH%2Fspaces_6ou11_2.png?alt=media&#x26;token=565cfde2-3005-4fc7-ab56-79e2b6be6c38" alt=""><figcaption></figcaption></figure></div>

1. Create model-config.json file via `echo "{}" > model-config.json` We are creating an empty config because we don't want to use preloading of models.&#x20;
2. Run following python sctipt.&#x20;

<pre class="language-python"><code class="lang-python">"""
    Full Pipeline Example.
"""

import json
import requests
import urllib

service_headers = {"accept": "application/json"}

name = "ENTER_YOUR_NAME"
mail = "ENTER_YOUR_MAIL"
comment = "ENTER_YOUR_COMMENT"
image_path = "ENTER IMAGE PATH"

class UserSimulate():
    def __init__(self):
        self.auth_url = "http://api.metahumansdk.io/auth"
        self.head_url = "https://api.metahumansdk.io/face_recon"
        self.hair_url = "https://api.metahumansdk.io/hair_recon"
        self.glb_url = "https://api.metahumansdk.io/glb_const"

        self.token = None
        self.head_json = None
        self.head_uv = None
        self.hair_glb = None

    def get_token(self):
        data = {
            "name": name,
            "mail": mail,
            "comment": comment
        }
        response_config = requests.post(self.auth_url + "/token", headers=service_headers, data=data)
        assert (response_config.status_code == 200)
        self.token = response_config.json()["result"]["token"]
    
    def reconstruct_head(self):
        files_base = {
            "token": (None, self.token),
            "image_bytes": ("image", open(image_path, "rb"), "image/png")
        }
        response = requests.post(self.head_url + "/run_pipeline", headers=service_headers, files=files_base)
        print(response.json())
        assert (response.status_code == 200)
        with urllib.request.urlopen(self.head_url + response.json()['result']['face']['textureUrl']) as f:
            self.head_uv = f.read()

        self.head_json = response.json()

<strong>    def reconstruct_hair(self):
</strong>        files_base = {
            "token": (None, self.token),
            "image_bytes": ("test_image.png", open(image_path, "rb"), "image/png"),
            "mode": (None, "volume")
        }
        response_config = requests.post(self.hair_url + '/run_pipeline', headers=service_headers, files=files_base)
        assert (response_config.status_code == 200)
        self.hair_glb = response_config.content

    def put_schema(self):
        files = {
            "token": (None, self.token),
            "schema": ("data/schema.json", open("model-config.json", 'r'), "application/json")
        }
        response = requests.put(self.glb_url + "/schema", headers=service_headers, files=files)
        assert (response.status_code == 200)

    def assemble_model(self):

        with open("model-config.json", 'r') as out:
            models_config = json.load(out)

        files = {
            "token": (None, self.token),
            "head_uv": ("head_model", self.head_uv, "image/png"),
            "head_config": ("head_config", json.dumps(self.head_json), "application/json"),
            "models_config": ("models_config", json.dumps(models_config), "application/json"),
            "custom_models": ("custom_models", self.hair_glb, "application/json"),
            "add_facs": (None, True)
        }
        response = requests.post(self.glb_url + "/assemble", headers=service_headers, files=files)
        assert (response.status_code == 200)
        return response.content


if __name__ == "__main__":
    user = UserSimulate()
    print("Obtaining token...")
    user.get_token()
    print("Reconstructing head...")
    user.reconstruct_head()
    print("Reconstructing hair...")
    user.reconstruct_hair()
    print("Putting schema...")
    user.put_schema()
    print("Obtaining model...")
    model = user.assemble_model()

    with open("head.glb", "wb") as out:
        out.write(model)
</code></pre>

{% hint style="info" %}
Note: replace curly braces with yout information
{% endhint %}

If the script is executed successfully, you should have a glb model with the token name.
