1
2
Image generation hub that leverages multiple AI models which
3
streamlines the complex process of AI image generation by
4
providing a simple interface for model selection and prompt
5
input.
6
7
Built with ~0% javascript, utilizing the power of Golang, Templ
8
and HTMX to deliver a user-friendly experience.
9
10
11
13
14
prediction, err := replicate.Client.CreatePrediction(
15
r.Context(),
16
model,
17
replicate.PredictionInput{
18
"prompt": prompt,
19
"negative_prompt": negativePrompt,
20
"num_outputs": 1,
21
"width": 960,
22
"height": 1280,
23
"output_quality": 100,
24
"prompt_strength": 0.8,
25
"num_inference_steps": 10,
26
},
27
&replicate.Webhook{
28
URL: os.Getenv("REPLICATE_WEBHOOK"),
29
Events: []replicate.WebhookEventType{"completed"},
30
},
31
false,
32
)
33
34
35
36
prediction, err := replicate.Client.CreatePrediction(
r.Context(),
model,
replicate.PredictionInput{
"prompt": prompt,
"negative_prompt": negativePrompt,
"num_outputs": 1,
"width": 960,
"height": 1280,
"output_quality": 100,
"prompt_strength": 0.8,
"num_inference_steps": 10,
},
&replicate.Webhook{
URL: os.Getenv("REPLICATE_WEBHOOK"),
Events: []replicate.WebhookEventType{"completed"},
},
false,
)
func AddUserAuthCookies(w http.ResponseWriter, accessToken, refreshToken, accountId string) {
http.SetCookie(w, &http.Cookie{
Name: domain.AccessTokenCookieKey,
Path: "/",
HttpOnly: true,
Secure: true,
Value: accessToken,
})
http.SetCookie(w, &http.Cookie{
Name: domain.RefreshTokenCookieKey,
Path: "/",
HttpOnly: true,
Secure: true,
Value: refreshToken,
})
http.SetCookie(w, &http.Cookie{
Name: domain.AccountIdCookieKey,
Path: "/",
HttpOnly: true,
Secure: true,
Value: accountId,
})
}
func GetTokensFromQuery(values url.Values) (accessToken string, refreshToken string, err error) {
accessToken = values.Get("access_token")
refreshToken = values.Get("refresh_token")
if accessToken == "" || refreshToken == "" {
return "", "", fmt.Errorf(
"Cannot get 'access_token' or 'refresh_token' from query: %v",
values,
)
}
return accessToken, refreshToken, nil
}
func MakeRoute(handler func(w http.ResponseWriter, r *http.Request) error) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
err := handler(w, r)
if err != nil {
log.Printf("Handler unhanded error %s %s\nError: %v", r.Method, r.URL.Path, err)
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprintf(w, "Something went wrong: %v", err)
}
})
}
func downloadImage(url, filepath string) error {
r, err := http.Get(url)
if err != nil {
return err
}
defer r.Body.Close()
file, err := os.Create(filepath)
if err != nil {
return err
}
defer file.Close()
_, err = io.Copy(file, r.Body)
return err
}