Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
henomis committed Dec 19, 2023
1 parent 411863b commit a9ef0d8
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions transformer/hf-text-to-image.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,15 @@ func (h *HFTextToImage) WithPersistImage(mediaFile string) *HFTextToImage {
}

func (h *HFTextToImage) Transform(ctx context.Context, input string) (any, error) {

respBody, err := h.hfTextToImageHttpCall(ctx, input)
respBody, err := h.hfTextToImageHTTPCall(ctx, input)
if err != nil {
return "", err
}

return respBody, nil
}

func (h *HFTextToImage) hfTextToImageHttpCall(ctx context.Context, input string) ([]byte, error) {

func (h *HFTextToImage) hfTextToImageHTTPCall(ctx context.Context, input string) ([]byte, error) {
request := HFTextToImageRequest{
Input: input,
}
Expand Down Expand Up @@ -95,28 +93,19 @@ func (h *HFTextToImage) hfTextToImageHttpCall(ctx context.Context, input string)
}

if h.mediaFile != "" {
f, err := os.Create(h.mediaFile)
if err != nil {
return nil, err
f, errCreate := os.Create(h.mediaFile)
if errCreate != nil {
return nil, errCreate
}
defer f.Close()

_, err = io.Copy(f, resp.Body)
if err != nil {
return nil, err
_, errCreate = io.Copy(f, resp.Body)
if errCreate != nil {
return nil, errCreate
}

return nil, nil
}

respBody, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}

if err != nil {
return nil, err
}

return respBody, nil
return io.ReadAll(resp.Body)
}

0 comments on commit a9ef0d8

Please sign in to comment.