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

[FEAT][API] Create Avatarization Job #68

Open
youen opened this issue Mar 31, 2024 · 0 comments
Open

[FEAT][API] Create Avatarization Job #68

youen opened this issue Mar 31, 2024 · 0 comments

Comments

@youen
Copy link
Collaborator

youen commented Mar 31, 2024

Description

Creates an avatarization job.

Request

Method

POST

URL

/jobs/avatarization

Request Parameters

Parameter Description Required Example
kind The kind of job to be created. Yes avatarization

Request Body

{
  "parameters": {
    "image_url": "https://example.com/image.jpg",
    "avatarization_config": {
      "output_image_url": "https://example.com/output_image.jpg",
      "output_image_format": "jpg",
      "output_image_size": {
        "width": 256,
        "height": 256
      },
      "avatar_algorithm": "haar",
      "avatar_size": {
        "width": 128,
        "height": 128
      },
      "background_color": "#ffffff"
    }
  }
}

Result

Result parameters

Parameter Description
id The ID of the newly created job.
kind The kind of job.
created_at The timestamp of when the job was created.
status The current status of the job.
error_message The error message if the job failed.
traceback The traceback if the job failed.
result The result of the job.
parameters The parameters of the job.
current_progress The current progress of the job.

Result Body

{
  "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "kind": "avatarization",
  "created_at": "2023-03-08T15:30:00.000Z",
  "status": "running",
  "parameters": {
    "image_url": "https://example.com/image.jpg",
    "avatarization_config": {
      "output_image_url": "https://example.com/output_image.jpg",
      "output_image_format": "jpg",
      "output_image_size": {
        "width": 256,
        "height": 256
      },
      "avatar_algorithm": "haar",
      "avatar_size": {
        "width": 128,
        "height": 128
      },
      "background_color": "#ffffff"
    }
  },
  "current_progress": {
    "percent_complete": 50
  }
}

Example Curl Request

Request

curl -X POST http://localhost:8080/jobs/avatarization \
  -H "Content-Type: application/json" \
  -d '{
  "parameters": {
    "image_url": "https://example.com/image.jpg",
    "avatarization_config": {
      "output_image_url": "https://example.com/output_image.jpg",
      "output_image_format": "jpg",
      "output_image_size": {
        "width": 256,
        "height": 256
      },
      "avatar_algorithm": "haar",
      "avatar_size": {
        "width": 128,
        "height": 128
      },
      "background_color": "#ffffff"
    }
  }
}'

Curl Response

{
  "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "kind": "avatarization",
  "created_at": "2023-03-08T15:30:00.000Z",
  "status": "running",
  "parameters": {
    "image_url": "https://example.com/image.jpg",
    "avatarization_config": {
      "output_image_url": "https://example.com/output_image.jpg",
      "output_image_format": "jpg",
      "output_image_size": {
        "width": 256,
        "height": 256
      },
      "avatar_algorithm": "haar",
      "avatar_size": {
        "width": 128,
        "height": 128
      },
      "background_color": "#ffffff"
    }
  },
  "current_progress": {
    "percent_complete": 50
  }
}

Go server

Struct

type AvatarizationJob struct {
	ID                string                        `json:"id"`
	Kind              JobKind                       `json:"kind"`
	CreatedAt         time.Time                     `json:"created_at"`
	Status            JobStatus                    `json:"status"`
	ErrorMessage      string                        `json:"error_message"`
	Traceback         string                        `json:"traceback"`
	Result            *AvatarizationResult          `json:"result"`
	Parameters        AvatarizationParameters        `json:"parameters"`
	CurrentProgress   *JobProgress                  `json:"current_progress"`
}

Handler

func (h *handler) createAvatarizationJob(w http.ResponseWriter, r *http.Request) {
	var req AvatarizationJobCreate

	if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
		http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
		return
	}

	job, err := h.jobService.CreateAvatarizationJob(req)
	if err != nil {
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}

	w.Header().Set("Content-Type", "application/json")
	if err := json.NewEncoder(w).Encode(job); err != nil {
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}
}

Links

Automated Issue Details

Dear visitor,

This issue has been automatically generated from the Octopize project avatar-python to make SIGO compatible. Please vote with a thumbs up or thumbs down to assess the quality of the automatic generation.

Best regards,
The SIGO Team

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant