init commit
This commit is contained in:
commit
559f6f959f
|
@ -0,0 +1,5 @@
|
||||||
|
[
|
||||||
|
import_deps: [:ecto, :phoenix],
|
||||||
|
inputs: ["*.{ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{ex,exs}"],
|
||||||
|
subdirectories: ["priv/*/migrations"]
|
||||||
|
]
|
|
@ -0,0 +1,37 @@
|
||||||
|
# The directory Mix will write compiled artifacts to.
|
||||||
|
/_build/
|
||||||
|
|
||||||
|
# If you run "mix test --cover", coverage assets end up here.
|
||||||
|
/cover/
|
||||||
|
|
||||||
|
# The directory Mix downloads your dependencies sources to.
|
||||||
|
/deps/
|
||||||
|
|
||||||
|
# Where 3rd-party dependencies like ExDoc output generated docs.
|
||||||
|
/doc/
|
||||||
|
|
||||||
|
# Ignore .fetch files in case you like to edit your project deps locally.
|
||||||
|
/.fetch
|
||||||
|
|
||||||
|
# If the VM crashes, it generates a dump, let's ignore it too.
|
||||||
|
erl_crash.dump
|
||||||
|
|
||||||
|
# Also ignore archive artifacts (built via "mix archive.build").
|
||||||
|
*.ez
|
||||||
|
|
||||||
|
# Ignore package tarball (built via "mix hex.build").
|
||||||
|
diffuser-*.tar
|
||||||
|
|
||||||
|
# Ignore assets that are produced by build tools.
|
||||||
|
/priv/static/assets/
|
||||||
|
|
||||||
|
# Ignore digested assets cache.
|
||||||
|
/priv/static/cache_manifest.json
|
||||||
|
|
||||||
|
# In case you use Node.js/npm, you want to ignore these.
|
||||||
|
npm-debug.log
|
||||||
|
/assets/node_modules/
|
||||||
|
|
||||||
|
output.png
|
||||||
|
*.pyc
|
||||||
|
uploads/*
|
|
@ -0,0 +1,4 @@
|
||||||
|
elixir 1.13.4
|
||||||
|
erlang 25.0.2
|
||||||
|
nodejs 16.15.1
|
||||||
|
python 3.8.13
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"[elixir]": {
|
||||||
|
"editor.defaultFormatter": "elixir-lsp.elixir-ls"
|
||||||
|
},
|
||||||
|
"editor.formatOnSave": true,
|
||||||
|
"emmet.includeLanguages": {
|
||||||
|
"html-eex": "html"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,86 @@
|
||||||
|
{
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [{
|
||||||
|
"label": "mix test",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "mix",
|
||||||
|
"args": [
|
||||||
|
"test",
|
||||||
|
"--exclude",
|
||||||
|
"integration",
|
||||||
|
"--exclude",
|
||||||
|
"feature",
|
||||||
|
"--color"
|
||||||
|
],
|
||||||
|
"options": {
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"requireFiles": [
|
||||||
|
"test/**/test_helper.exs",
|
||||||
|
"test/**/*_test.exs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"problemMatcher": "$mixTestFailure"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "mix test file",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "mix",
|
||||||
|
"args": [
|
||||||
|
"test",
|
||||||
|
"${relativeFile}",
|
||||||
|
"--color",
|
||||||
|
"--trace"
|
||||||
|
],
|
||||||
|
"options": {
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"requireFiles": [
|
||||||
|
"test/**/test_helper.exs",
|
||||||
|
"test/**/*_test.exs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"problemMatcher": "$mixTestFailure"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "mix test focused",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "mix",
|
||||||
|
"args": [
|
||||||
|
"test",
|
||||||
|
"${relativeFile}:${lineNumber}",
|
||||||
|
"--color",
|
||||||
|
"--trace"
|
||||||
|
],
|
||||||
|
"options": {
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"requireFiles": [
|
||||||
|
"test/**/test_helper.exs",
|
||||||
|
"test/**/*_test.exs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"problemMatcher": "$mixTestFailure",
|
||||||
|
"group": {
|
||||||
|
"kind": "test",
|
||||||
|
"isDefault": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "open all screenshots",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "open",
|
||||||
|
"args": [
|
||||||
|
"./screenshots"
|
||||||
|
],
|
||||||
|
"problemMatcher": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "open last screenshot",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "open `ls -t | head -n1`",
|
||||||
|
"args": [],
|
||||||
|
"options": {
|
||||||
|
"cwd": "${workspaceRoot}/screenshots"
|
||||||
|
},
|
||||||
|
"problemMatcher": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Diffuser
|
||||||
|
|
||||||
|
To start your Phoenix server:
|
||||||
|
|
||||||
|
* Install dependencies with `mix deps.get`
|
||||||
|
* Create and migrate your database with `mix ecto.setup`
|
||||||
|
* Start Phoenix endpoint with `mix phx.server` or inside IEx with `iex -S mix phx.server`
|
||||||
|
|
||||||
|
Now you can visit [`localhost:4000`](http://localhost:4000) from your browser.
|
||||||
|
|
||||||
|
Ready to run in production? Please [check our deployment guides](https://hexdocs.pm/phoenix/deployment.html).
|
||||||
|
|
||||||
|
## Learn more
|
||||||
|
|
||||||
|
* Official website: https://www.phoenixframework.org/
|
||||||
|
* Guides: https://hexdocs.pm/phoenix/overview.html
|
||||||
|
* Docs: https://hexdocs.pm/phoenix
|
||||||
|
* Forum: https://elixirforum.com/c/phoenix-forum
|
||||||
|
* Source: https://github.com/phoenixframework/phoenix
|
|
@ -0,0 +1,120 @@
|
||||||
|
/* This file is for your main application CSS */
|
||||||
|
@import "./phoenix.css";
|
||||||
|
|
||||||
|
/* Alerts and form errors used by phx.new */
|
||||||
|
.alert {
|
||||||
|
padding: 15px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
border: 1px solid transparent;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
.alert-info {
|
||||||
|
color: #31708f;
|
||||||
|
background-color: #d9edf7;
|
||||||
|
border-color: #bce8f1;
|
||||||
|
}
|
||||||
|
.alert-warning {
|
||||||
|
color: #8a6d3b;
|
||||||
|
background-color: #fcf8e3;
|
||||||
|
border-color: #faebcc;
|
||||||
|
}
|
||||||
|
.alert-danger {
|
||||||
|
color: #a94442;
|
||||||
|
background-color: #f2dede;
|
||||||
|
border-color: #ebccd1;
|
||||||
|
}
|
||||||
|
.alert p {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
.alert:empty {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.invalid-feedback {
|
||||||
|
color: #a94442;
|
||||||
|
display: block;
|
||||||
|
margin: -1rem 0 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* LiveView specific classes for your customization */
|
||||||
|
.phx-no-feedback.invalid-feedback,
|
||||||
|
.phx-no-feedback .invalid-feedback {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.phx-click-loading {
|
||||||
|
opacity: 0.5;
|
||||||
|
transition: opacity 1s ease-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
.phx-loading{
|
||||||
|
cursor: wait;
|
||||||
|
}
|
||||||
|
|
||||||
|
.phx-modal {
|
||||||
|
opacity: 1!important;
|
||||||
|
position: fixed;
|
||||||
|
z-index: 1;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
overflow: auto;
|
||||||
|
background-color: rgba(0,0,0,0.4);
|
||||||
|
}
|
||||||
|
|
||||||
|
.phx-modal-content {
|
||||||
|
background-color: #fefefe;
|
||||||
|
margin: 15vh auto;
|
||||||
|
padding: 20px;
|
||||||
|
border: 1px solid #888;
|
||||||
|
width: 80%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.phx-modal-close {
|
||||||
|
color: #aaa;
|
||||||
|
float: right;
|
||||||
|
font-size: 28px;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.phx-modal-close:hover,
|
||||||
|
.phx-modal-close:focus {
|
||||||
|
color: black;
|
||||||
|
text-decoration: none;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fade-in-scale {
|
||||||
|
animation: 0.2s ease-in 0s normal forwards 1 fade-in-scale-keys;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fade-out-scale {
|
||||||
|
animation: 0.2s ease-out 0s normal forwards 1 fade-out-scale-keys;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fade-in {
|
||||||
|
animation: 0.2s ease-out 0s normal forwards 1 fade-in-keys;
|
||||||
|
}
|
||||||
|
.fade-out {
|
||||||
|
animation: 0.2s ease-out 0s normal forwards 1 fade-out-keys;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes fade-in-scale-keys{
|
||||||
|
0% { scale: 0.95; opacity: 0; }
|
||||||
|
100% { scale: 1.0; opacity: 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes fade-out-scale-keys{
|
||||||
|
0% { scale: 1.0; opacity: 1; }
|
||||||
|
100% { scale: 0.95; opacity: 0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes fade-in-keys{
|
||||||
|
0% { opacity: 0; }
|
||||||
|
100% { opacity: 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes fade-out-keys{
|
||||||
|
0% { opacity: 1; }
|
||||||
|
100% { opacity: 0; }
|
||||||
|
}
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,46 @@
|
||||||
|
// We import the CSS which is extracted to its own file by esbuild.
|
||||||
|
// Remove this line if you add a your own CSS build pipeline (e.g postcss).
|
||||||
|
import "../css/app.css"
|
||||||
|
|
||||||
|
// If you want to use Phoenix channels, run `mix help phx.gen.channel`
|
||||||
|
// to get started and then uncomment the line below.
|
||||||
|
// import "./user_socket.js"
|
||||||
|
|
||||||
|
// You can include dependencies in two ways.
|
||||||
|
//
|
||||||
|
// The simplest option is to put them in assets/vendor and
|
||||||
|
// import them using relative paths:
|
||||||
|
//
|
||||||
|
// import "../vendor/some-package.js"
|
||||||
|
//
|
||||||
|
// Alternatively, you can `npm install some-package --prefix assets` and import
|
||||||
|
// them using a path starting with the package name:
|
||||||
|
//
|
||||||
|
// import "some-package"
|
||||||
|
//
|
||||||
|
|
||||||
|
// Include phoenix_html to handle method=PUT/DELETE in forms and buttons.
|
||||||
|
import "phoenix_html"
|
||||||
|
// Establish Phoenix Socket and LiveView configuration.
|
||||||
|
import {Socket} from "phoenix"
|
||||||
|
import {LiveSocket} from "phoenix_live_view"
|
||||||
|
import topbar from "../vendor/topbar"
|
||||||
|
import "./request_socket.js"
|
||||||
|
|
||||||
|
let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
|
||||||
|
let liveSocket = new LiveSocket("/live", Socket, {params: {_csrf_token: csrfToken}})
|
||||||
|
|
||||||
|
// Show progress bar on live navigation and form submits
|
||||||
|
topbar.config({barColors: {0: "#29d"}, shadowColor: "rgba(0, 0, 0, .3)"})
|
||||||
|
window.addEventListener("phx:page-loading-start", info => topbar.show())
|
||||||
|
window.addEventListener("phx:page-loading-stop", info => topbar.hide())
|
||||||
|
|
||||||
|
// connect if there are any LiveViews on the page
|
||||||
|
liveSocket.connect()
|
||||||
|
|
||||||
|
// expose liveSocket on window for web console debug logs and latency simulation:
|
||||||
|
// >> liveSocket.enableDebug()
|
||||||
|
// >> liveSocket.enableLatencySim(1000) // enabled for duration of browser session
|
||||||
|
// >> liveSocket.disableLatencySim()
|
||||||
|
window.liveSocket = liveSocket
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
// NOTE: The contents of this file will only be executed if
|
||||||
|
// you uncomment its entry in "assets/js/app.js".
|
||||||
|
|
||||||
|
// Bring in Phoenix channels client library:
|
||||||
|
import {Socket} from "phoenix"
|
||||||
|
|
||||||
|
// And connect to the path in "lib/diffuser_web/endpoint.ex". We pass the
|
||||||
|
// token for authentication. Read below how it should be used.
|
||||||
|
let socket = new Socket("/socket", {params: {token: window.userToken}})
|
||||||
|
|
||||||
|
// When you connect, you'll often need to authenticate the client.
|
||||||
|
// For example, imagine you have an authentication plug, `MyAuth`,
|
||||||
|
// which authenticates the session and assigns a `:current_user`.
|
||||||
|
// If the current user exists you can assign the user's token in
|
||||||
|
// the connection for use in the layout.
|
||||||
|
//
|
||||||
|
// In your "lib/diffuser_web/router.ex":
|
||||||
|
//
|
||||||
|
// pipeline :browser do
|
||||||
|
// ...
|
||||||
|
// plug MyAuth
|
||||||
|
// plug :put_user_token
|
||||||
|
// end
|
||||||
|
//
|
||||||
|
// defp put_user_token(conn, _) do
|
||||||
|
// if current_user = conn.assigns[:current_user] do
|
||||||
|
// token = Phoenix.Token.sign(conn, "user socket", current_user.id)
|
||||||
|
// assign(conn, :user_token, token)
|
||||||
|
// else
|
||||||
|
// conn
|
||||||
|
// end
|
||||||
|
// end
|
||||||
|
//
|
||||||
|
// Now you need to pass this token to JavaScript. You can do so
|
||||||
|
// inside a script tag in "lib/diffuser_web/templates/layout/app.html.heex":
|
||||||
|
//
|
||||||
|
// <script>window.userToken = "<%= assigns[:user_token] %>";</script>
|
||||||
|
//
|
||||||
|
// You will need to verify the user token in the "connect/3" function
|
||||||
|
// in "lib/diffuser_web/channels/user_socket.ex":
|
||||||
|
//
|
||||||
|
// def connect(%{"token" => token}, socket, _connect_info) do
|
||||||
|
// # max_age: 1209600 is equivalent to two weeks in seconds
|
||||||
|
// case Phoenix.Token.verify(socket, "user socket", token, max_age: 1_209_600) do
|
||||||
|
// {:ok, user_id} ->
|
||||||
|
// {:ok, assign(socket, :user, user_id)}
|
||||||
|
//
|
||||||
|
// {:error, reason} ->
|
||||||
|
// :error
|
||||||
|
// end
|
||||||
|
// end
|
||||||
|
//
|
||||||
|
// Finally, connect to the socket:
|
||||||
|
socket.connect()
|
||||||
|
|
||||||
|
// Now that you are connected, you can join channels with a topic.
|
||||||
|
// Let's assume you have a channel with a topic named `room` and the
|
||||||
|
// subtopic is its id - in this case 42:
|
||||||
|
// let channel = socket.channel("room:42", {})
|
||||||
|
// channel.join()
|
||||||
|
// .receive("ok", resp => { console.log("Joined successfully", resp) })
|
||||||
|
// .receive("error", resp => { console.log("Unable to join", resp) })
|
||||||
|
|
||||||
|
export default socket
|
|
@ -0,0 +1,157 @@
|
||||||
|
/**
|
||||||
|
* @license MIT
|
||||||
|
* topbar 1.0.0, 2021-01-06
|
||||||
|
* https://buunguyen.github.io/topbar
|
||||||
|
* Copyright (c) 2021 Buu Nguyen
|
||||||
|
*/
|
||||||
|
(function (window, document) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
// https://gist.github.com/paulirish/1579671
|
||||||
|
(function () {
|
||||||
|
var lastTime = 0;
|
||||||
|
var vendors = ["ms", "moz", "webkit", "o"];
|
||||||
|
for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
|
||||||
|
window.requestAnimationFrame =
|
||||||
|
window[vendors[x] + "RequestAnimationFrame"];
|
||||||
|
window.cancelAnimationFrame =
|
||||||
|
window[vendors[x] + "CancelAnimationFrame"] ||
|
||||||
|
window[vendors[x] + "CancelRequestAnimationFrame"];
|
||||||
|
}
|
||||||
|
if (!window.requestAnimationFrame)
|
||||||
|
window.requestAnimationFrame = function (callback, element) {
|
||||||
|
var currTime = new Date().getTime();
|
||||||
|
var timeToCall = Math.max(0, 16 - (currTime - lastTime));
|
||||||
|
var id = window.setTimeout(function () {
|
||||||
|
callback(currTime + timeToCall);
|
||||||
|
}, timeToCall);
|
||||||
|
lastTime = currTime + timeToCall;
|
||||||
|
return id;
|
||||||
|
};
|
||||||
|
if (!window.cancelAnimationFrame)
|
||||||
|
window.cancelAnimationFrame = function (id) {
|
||||||
|
clearTimeout(id);
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
|
var canvas,
|
||||||
|
progressTimerId,
|
||||||
|
fadeTimerId,
|
||||||
|
currentProgress,
|
||||||
|
showing,
|
||||||
|
addEvent = function (elem, type, handler) {
|
||||||
|
if (elem.addEventListener) elem.addEventListener(type, handler, false);
|
||||||
|
else if (elem.attachEvent) elem.attachEvent("on" + type, handler);
|
||||||
|
else elem["on" + type] = handler;
|
||||||
|
},
|
||||||
|
options = {
|
||||||
|
autoRun: true,
|
||||||
|
barThickness: 3,
|
||||||
|
barColors: {
|
||||||
|
0: "rgba(26, 188, 156, .9)",
|
||||||
|
".25": "rgba(52, 152, 219, .9)",
|
||||||
|
".50": "rgba(241, 196, 15, .9)",
|
||||||
|
".75": "rgba(230, 126, 34, .9)",
|
||||||
|
"1.0": "rgba(211, 84, 0, .9)",
|
||||||
|
},
|
||||||
|
shadowBlur: 10,
|
||||||
|
shadowColor: "rgba(0, 0, 0, .6)",
|
||||||
|
className: null,
|
||||||
|
},
|
||||||
|
repaint = function () {
|
||||||
|
canvas.width = window.innerWidth;
|
||||||
|
canvas.height = options.barThickness * 5; // need space for shadow
|
||||||
|
|
||||||
|
var ctx = canvas.getContext("2d");
|
||||||
|
ctx.shadowBlur = options.shadowBlur;
|
||||||
|
ctx.shadowColor = options.shadowColor;
|
||||||
|
|
||||||
|
var lineGradient = ctx.createLinearGradient(0, 0, canvas.width, 0);
|
||||||
|
for (var stop in options.barColors)
|
||||||
|
lineGradient.addColorStop(stop, options.barColors[stop]);
|
||||||
|
ctx.lineWidth = options.barThickness;
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.moveTo(0, options.barThickness / 2);
|
||||||
|
ctx.lineTo(
|
||||||
|
Math.ceil(currentProgress * canvas.width),
|
||||||
|
options.barThickness / 2
|
||||||
|
);
|
||||||
|
ctx.strokeStyle = lineGradient;
|
||||||
|
ctx.stroke();
|
||||||
|
},
|
||||||
|
createCanvas = function () {
|
||||||
|
canvas = document.createElement("canvas");
|
||||||
|
var style = canvas.style;
|
||||||
|
style.position = "fixed";
|
||||||
|
style.top = style.left = style.right = style.margin = style.padding = 0;
|
||||||
|
style.zIndex = 100001;
|
||||||
|
style.display = "none";
|
||||||
|
if (options.className) canvas.classList.add(options.className);
|
||||||
|
document.body.appendChild(canvas);
|
||||||
|
addEvent(window, "resize", repaint);
|
||||||
|
},
|
||||||
|
topbar = {
|
||||||
|
config: function (opts) {
|
||||||
|
for (var key in opts)
|
||||||
|
if (options.hasOwnProperty(key)) options[key] = opts[key];
|
||||||
|
},
|
||||||
|
show: function () {
|
||||||
|
if (showing) return;
|
||||||
|
showing = true;
|
||||||
|
if (fadeTimerId !== null) window.cancelAnimationFrame(fadeTimerId);
|
||||||
|
if (!canvas) createCanvas();
|
||||||
|
canvas.style.opacity = 1;
|
||||||
|
canvas.style.display = "block";
|
||||||
|
topbar.progress(0);
|
||||||
|
if (options.autoRun) {
|
||||||
|
(function loop() {
|
||||||
|
progressTimerId = window.requestAnimationFrame(loop);
|
||||||
|
topbar.progress(
|
||||||
|
"+" + 0.05 * Math.pow(1 - Math.sqrt(currentProgress), 2)
|
||||||
|
);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
progress: function (to) {
|
||||||
|
if (typeof to === "undefined") return currentProgress;
|
||||||
|
if (typeof to === "string") {
|
||||||
|
to =
|
||||||
|
(to.indexOf("+") >= 0 || to.indexOf("-") >= 0
|
||||||
|
? currentProgress
|
||||||
|
: 0) + parseFloat(to);
|
||||||
|
}
|
||||||
|
currentProgress = to > 1 ? 1 : to;
|
||||||
|
repaint();
|
||||||
|
return currentProgress;
|
||||||
|
},
|
||||||
|
hide: function () {
|
||||||
|
if (!showing) return;
|
||||||
|
showing = false;
|
||||||
|
if (progressTimerId != null) {
|
||||||
|
window.cancelAnimationFrame(progressTimerId);
|
||||||
|
progressTimerId = null;
|
||||||
|
}
|
||||||
|
(function loop() {
|
||||||
|
if (topbar.progress("+.1") >= 1) {
|
||||||
|
canvas.style.opacity -= 0.05;
|
||||||
|
if (canvas.style.opacity <= 0.05) {
|
||||||
|
canvas.style.display = "none";
|
||||||
|
fadeTimerId = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fadeTimerId = window.requestAnimationFrame(loop);
|
||||||
|
})();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
if (typeof module === "object" && typeof module.exports === "object") {
|
||||||
|
module.exports = topbar;
|
||||||
|
} else if (typeof define === "function" && define.amd) {
|
||||||
|
define(function () {
|
||||||
|
return topbar;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.topbar = topbar;
|
||||||
|
}
|
||||||
|
}.call(this, window, document));
|
|
@ -0,0 +1,58 @@
|
||||||
|
# This file is responsible for configuring your application
|
||||||
|
# and its dependencies with the aid of the Config module.
|
||||||
|
#
|
||||||
|
# This configuration file is loaded before any dependency and
|
||||||
|
# is restricted to this project.
|
||||||
|
|
||||||
|
# General application configuration
|
||||||
|
import Config
|
||||||
|
|
||||||
|
config :diffuser,
|
||||||
|
ecto_repos: [Diffuser.Repo]
|
||||||
|
|
||||||
|
# Configures the endpoint
|
||||||
|
config :diffuser, DiffuserWeb.Endpoint,
|
||||||
|
url: [host: "localhost"],
|
||||||
|
render_errors: [view: DiffuserWeb.ErrorView, accepts: ~w(html json), layout: false],
|
||||||
|
pubsub_server: Diffuser.PubSub,
|
||||||
|
live_view: [signing_salt: "mxn2AV/s"]
|
||||||
|
|
||||||
|
# Configures the mailer
|
||||||
|
#
|
||||||
|
# By default it uses the "Local" adapter which stores the emails
|
||||||
|
# locally. You can see the emails in your browser, at "/dev/mailbox".
|
||||||
|
#
|
||||||
|
# For production it's recommended to configure a different adapter
|
||||||
|
# at the `config/runtime.exs`.
|
||||||
|
config :diffuser, Diffuser.Mailer, adapter: Swoosh.Adapters.Local
|
||||||
|
|
||||||
|
# Swoosh API client is needed for adapters other than SMTP.
|
||||||
|
config :swoosh, :api_client, false
|
||||||
|
|
||||||
|
# Configure esbuild (the version is required)
|
||||||
|
config :esbuild,
|
||||||
|
version: "0.14.29",
|
||||||
|
default: [
|
||||||
|
args:
|
||||||
|
~w(js/app.js --bundle --target=es2017 --outdir=../priv/static/assets --external:/fonts/* --external:/images/*),
|
||||||
|
cd: Path.expand("../assets", __DIR__),
|
||||||
|
env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)}
|
||||||
|
]
|
||||||
|
|
||||||
|
# Configures Elixir's Logger
|
||||||
|
config :logger, :console,
|
||||||
|
format: "$time $metadata[$level] $message\n",
|
||||||
|
metadata: [:request_id]
|
||||||
|
|
||||||
|
# Use Jason for JSON parsing in Phoenix
|
||||||
|
config :phoenix, :json_library, Jason
|
||||||
|
|
||||||
|
## non default phoenix config
|
||||||
|
config :waffle,
|
||||||
|
storage: Waffle.Storage.Local,
|
||||||
|
# or {:system, "ASSET_HOST"}
|
||||||
|
asset_host: "http://localhost:4000"
|
||||||
|
|
||||||
|
# Import environment specific config. This must remain at the bottom
|
||||||
|
# of this file so it overrides the configuration defined above.
|
||||||
|
import_config "#{config_env()}.exs"
|
|
@ -0,0 +1,75 @@
|
||||||
|
import Config
|
||||||
|
|
||||||
|
# Configure your database
|
||||||
|
config :diffuser, Diffuser.Repo,
|
||||||
|
username: "postgres",
|
||||||
|
password: "postgres",
|
||||||
|
hostname: "localhost",
|
||||||
|
database: "diffuser_dev",
|
||||||
|
stacktrace: true,
|
||||||
|
show_sensitive_data_on_connection_error: true,
|
||||||
|
pool_size: 10
|
||||||
|
|
||||||
|
# For development, we disable any cache and enable
|
||||||
|
# debugging and code reloading.
|
||||||
|
#
|
||||||
|
# The watchers configuration can be used to run external
|
||||||
|
# watchers to your application. For example, we use it
|
||||||
|
# with esbuild to bundle .js and .css sources.
|
||||||
|
config :diffuser, DiffuserWeb.Endpoint,
|
||||||
|
# Binding to loopback ipv4 address prevents access from other machines.
|
||||||
|
# Change to `ip: {0, 0, 0, 0}` to allow access from other machines.
|
||||||
|
http: [ip: {127, 0, 0, 1}, port: 4000],
|
||||||
|
check_origin: false,
|
||||||
|
code_reloader: true,
|
||||||
|
debug_errors: true,
|
||||||
|
secret_key_base: "mLAQpOCHwqL2jI5ljtcULJFRTpsXnvFSjLRM3HjFYJF8Rc1Uqh6o7PT7GaIQ+ERA",
|
||||||
|
watchers: [
|
||||||
|
# Start the esbuild watcher by calling Esbuild.install_and_run(:default, args)
|
||||||
|
esbuild: {Esbuild, :install_and_run, [:default, ~w(--sourcemap=inline --watch)]}
|
||||||
|
]
|
||||||
|
|
||||||
|
# ## SSL Support
|
||||||
|
#
|
||||||
|
# In order to use HTTPS in development, a self-signed
|
||||||
|
# certificate can be generated by running the following
|
||||||
|
# Mix task:
|
||||||
|
#
|
||||||
|
# mix phx.gen.cert
|
||||||
|
#
|
||||||
|
# Note that this task requires Erlang/OTP 20 or later.
|
||||||
|
# Run `mix help phx.gen.cert` for more information.
|
||||||
|
#
|
||||||
|
# The `http:` config above can be replaced with:
|
||||||
|
#
|
||||||
|
# https: [
|
||||||
|
# port: 4001,
|
||||||
|
# cipher_suite: :strong,
|
||||||
|
# keyfile: "priv/cert/selfsigned_key.pem",
|
||||||
|
# certfile: "priv/cert/selfsigned.pem"
|
||||||
|
# ],
|
||||||
|
#
|
||||||
|
# If desired, both `http:` and `https:` keys can be
|
||||||
|
# configured to run both http and https servers on
|
||||||
|
# different ports.
|
||||||
|
|
||||||
|
# Watch static and templates for browser reloading.
|
||||||
|
config :diffuser, DiffuserWeb.Endpoint,
|
||||||
|
live_reload: [
|
||||||
|
patterns: [
|
||||||
|
~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$",
|
||||||
|
~r"priv/gettext/.*(po)$",
|
||||||
|
~r"lib/diffuser_web/(live|views)/.*(ex)$",
|
||||||
|
~r"lib/diffuser_web/templates/.*(eex)$"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
# Do not include metadata nor timestamps in development logs
|
||||||
|
config :logger, :console, format: "[$level] $message\n"
|
||||||
|
|
||||||
|
# Set a higher stacktrace during development. Avoid configuring such
|
||||||
|
# in production as building large stacktraces may be expensive.
|
||||||
|
config :phoenix, :stacktrace_depth, 20
|
||||||
|
|
||||||
|
# Initialize plugs at runtime for faster development compilation
|
||||||
|
config :phoenix, :plug_init_mode, :runtime
|
|
@ -0,0 +1,49 @@
|
||||||
|
import Config
|
||||||
|
|
||||||
|
# For production, don't forget to configure the url host
|
||||||
|
# to something meaningful, Phoenix uses this information
|
||||||
|
# when generating URLs.
|
||||||
|
#
|
||||||
|
# Note we also include the path to a cache manifest
|
||||||
|
# containing the digested version of static files. This
|
||||||
|
# manifest is generated by the `mix phx.digest` task,
|
||||||
|
# which you should run after static files are built and
|
||||||
|
# before starting your production server.
|
||||||
|
config :diffuser, DiffuserWeb.Endpoint, cache_static_manifest: "priv/static/cache_manifest.json"
|
||||||
|
|
||||||
|
# Do not print debug messages in production
|
||||||
|
config :logger, level: :info
|
||||||
|
|
||||||
|
# ## SSL Support
|
||||||
|
#
|
||||||
|
# To get SSL working, you will need to add the `https` key
|
||||||
|
# to the previous section and set your `:url` port to 443:
|
||||||
|
#
|
||||||
|
# config :diffuser, DiffuserWeb.Endpoint,
|
||||||
|
# ...,
|
||||||
|
# url: [host: "example.com", port: 443],
|
||||||
|
# https: [
|
||||||
|
# ...,
|
||||||
|
# port: 443,
|
||||||
|
# cipher_suite: :strong,
|
||||||
|
# keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"),
|
||||||
|
# certfile: System.get_env("SOME_APP_SSL_CERT_PATH")
|
||||||
|
# ]
|
||||||
|
#
|
||||||
|
# The `cipher_suite` is set to `:strong` to support only the
|
||||||
|
# latest and more secure SSL ciphers. This means old browsers
|
||||||
|
# and clients may not be supported. You can set it to
|
||||||
|
# `:compatible` for wider support.
|
||||||
|
#
|
||||||
|
# `:keyfile` and `:certfile` expect an absolute path to the key
|
||||||
|
# and cert in disk or a relative path inside priv, for example
|
||||||
|
# "priv/ssl/server.key". For all supported SSL configuration
|
||||||
|
# options, see https://hexdocs.pm/plug/Plug.SSL.html#configure/1
|
||||||
|
#
|
||||||
|
# We also recommend setting `force_ssl` in your endpoint, ensuring
|
||||||
|
# no data is ever sent via http, always redirecting to https:
|
||||||
|
#
|
||||||
|
# config :diffuser, DiffuserWeb.Endpoint,
|
||||||
|
# force_ssl: [hsts: true]
|
||||||
|
#
|
||||||
|
# Check `Plug.SSL` for all available options in `force_ssl`.
|
|
@ -0,0 +1,83 @@
|
||||||
|
import Config
|
||||||
|
|
||||||
|
# config/runtime.exs is executed for all environments, including
|
||||||
|
# during releases. It is executed after compilation and before the
|
||||||
|
# system starts, so it is typically used to load production configuration
|
||||||
|
# and secrets from environment variables or elsewhere. Do not define
|
||||||
|
# any compile-time configuration in here, as it won't be applied.
|
||||||
|
# The block below contains prod specific runtime configuration.
|
||||||
|
|
||||||
|
# ## Using releases
|
||||||
|
#
|
||||||
|
# If you use `mix release`, you need to explicitly enable the server
|
||||||
|
# by passing the PHX_SERVER=true when you start it:
|
||||||
|
#
|
||||||
|
# PHX_SERVER=true bin/diffuser start
|
||||||
|
#
|
||||||
|
# Alternatively, you can use `mix phx.gen.release` to generate a `bin/server`
|
||||||
|
# script that automatically sets the env var above.
|
||||||
|
if System.get_env("PHX_SERVER") do
|
||||||
|
config :diffuser, DiffuserWeb.Endpoint, server: true
|
||||||
|
end
|
||||||
|
|
||||||
|
if config_env() == :prod do
|
||||||
|
database_url =
|
||||||
|
System.get_env("DATABASE_URL") ||
|
||||||
|
raise """
|
||||||
|
environment variable DATABASE_URL is missing.
|
||||||
|
For example: ecto://USER:PASS@HOST/DATABASE
|
||||||
|
"""
|
||||||
|
|
||||||
|
maybe_ipv6 = if System.get_env("ECTO_IPV6"), do: [:inet6], else: []
|
||||||
|
|
||||||
|
config :diffuser, Diffuser.Repo,
|
||||||
|
# ssl: true,
|
||||||
|
url: database_url,
|
||||||
|
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"),
|
||||||
|
socket_options: maybe_ipv6
|
||||||
|
|
||||||
|
# The secret key base is used to sign/encrypt cookies and other secrets.
|
||||||
|
# A default value is used in config/dev.exs and config/test.exs but you
|
||||||
|
# want to use a different value for prod and you most likely don't want
|
||||||
|
# to check this value into version control, so we use an environment
|
||||||
|
# variable instead.
|
||||||
|
secret_key_base =
|
||||||
|
System.get_env("SECRET_KEY_BASE") ||
|
||||||
|
raise """
|
||||||
|
environment variable SECRET_KEY_BASE is missing.
|
||||||
|
You can generate one by calling: mix phx.gen.secret
|
||||||
|
"""
|
||||||
|
|
||||||
|
host = System.get_env("PHX_HOST") || "example.com"
|
||||||
|
port = String.to_integer(System.get_env("PORT") || "4000")
|
||||||
|
|
||||||
|
config :diffuser, DiffuserWeb.Endpoint,
|
||||||
|
url: [host: host, port: 443, scheme: "https"],
|
||||||
|
http: [
|
||||||
|
# Enable IPv6 and bind on all interfaces.
|
||||||
|
# Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access.
|
||||||
|
# See the documentation on https://hexdocs.pm/plug_cowboy/Plug.Cowboy.html
|
||||||
|
# for details about using IPv6 vs IPv4 and loopback vs public addresses.
|
||||||
|
ip: {0, 0, 0, 0, 0, 0, 0, 0},
|
||||||
|
port: port
|
||||||
|
],
|
||||||
|
secret_key_base: secret_key_base
|
||||||
|
|
||||||
|
# ## Configuring the mailer
|
||||||
|
#
|
||||||
|
# In production you need to configure the mailer to use a different adapter.
|
||||||
|
# Also, you may need to configure the Swoosh API client of your choice if you
|
||||||
|
# are not using SMTP. Here is an example of the configuration:
|
||||||
|
#
|
||||||
|
# config :diffuser, Diffuser.Mailer,
|
||||||
|
# adapter: Swoosh.Adapters.Mailgun,
|
||||||
|
# api_key: System.get_env("MAILGUN_API_KEY"),
|
||||||
|
# domain: System.get_env("MAILGUN_DOMAIN")
|
||||||
|
#
|
||||||
|
# For this example you need include a HTTP client required by Swoosh API client.
|
||||||
|
# Swoosh supports Hackney and Finch out of the box:
|
||||||
|
#
|
||||||
|
# config :swoosh, :api_client, Swoosh.ApiClient.Hackney
|
||||||
|
#
|
||||||
|
# See https://hexdocs.pm/swoosh/Swoosh.html#module-installation for details.
|
||||||
|
end
|
|
@ -0,0 +1,30 @@
|
||||||
|
import Config
|
||||||
|
|
||||||
|
# Configure your database
|
||||||
|
#
|
||||||
|
# The MIX_TEST_PARTITION environment variable can be used
|
||||||
|
# to provide built-in test partitioning in CI environment.
|
||||||
|
# Run `mix help test` for more information.
|
||||||
|
config :diffuser, Diffuser.Repo,
|
||||||
|
username: "postgres",
|
||||||
|
password: "postgres",
|
||||||
|
hostname: "localhost",
|
||||||
|
database: "diffuser_test#{System.get_env("MIX_TEST_PARTITION")}",
|
||||||
|
pool: Ecto.Adapters.SQL.Sandbox,
|
||||||
|
pool_size: 10
|
||||||
|
|
||||||
|
# We don't run a server during test. If one is required,
|
||||||
|
# you can enable the server option below.
|
||||||
|
config :diffuser, DiffuserWeb.Endpoint,
|
||||||
|
http: [ip: {127, 0, 0, 1}, port: 4002],
|
||||||
|
secret_key_base: "GhuLG8ovQiKsXiQ9oOdVEloqYl4qTSi5i5FmU/dkVNQgJq8UbvVUQKA0hQaBDJgR",
|
||||||
|
server: false
|
||||||
|
|
||||||
|
# In test we don't send emails.
|
||||||
|
config :diffuser, Diffuser.Mailer, adapter: Swoosh.Adapters.Test
|
||||||
|
|
||||||
|
# Print only warnings and errors during test
|
||||||
|
config :logger, level: :warn
|
||||||
|
|
||||||
|
# Initialize plugs at runtime for faster test compilation
|
||||||
|
config :phoenix, :plug_init_mode, :runtime
|
|
@ -0,0 +1,9 @@
|
||||||
|
defmodule Diffuser do
|
||||||
|
@moduledoc """
|
||||||
|
Diffuser keeps the contexts that define your domain
|
||||||
|
and business logic.
|
||||||
|
|
||||||
|
Contexts are also responsible for managing your data, regardless
|
||||||
|
if it comes from the database, an external API or others.
|
||||||
|
"""
|
||||||
|
end
|
|
@ -0,0 +1,37 @@
|
||||||
|
defmodule Diffuser.Application do
|
||||||
|
# See https://hexdocs.pm/elixir/Application.html
|
||||||
|
# for more information on OTP Applications
|
||||||
|
@moduledoc false
|
||||||
|
|
||||||
|
use Application
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def start(_type, _args) do
|
||||||
|
children = [
|
||||||
|
# Start the Ecto repository
|
||||||
|
Diffuser.Repo,
|
||||||
|
# Start the Telemetry supervisor
|
||||||
|
DiffuserWeb.Telemetry,
|
||||||
|
# Start the PubSub system
|
||||||
|
{Phoenix.PubSub, name: Diffuser.PubSub},
|
||||||
|
# Start the Endpoint (http/https)
|
||||||
|
DiffuserWeb.Endpoint,
|
||||||
|
# Start a worker by calling: Diffuser.Worker.start_link(arg)
|
||||||
|
# {Diffuser.Worker, arg}
|
||||||
|
{Task.Supervisor, name: Diffuser.Generator.PromptRequestSupervisor}
|
||||||
|
]
|
||||||
|
|
||||||
|
# See https://hexdocs.pm/elixir/Supervisor.html
|
||||||
|
# for other strategies and supported options
|
||||||
|
opts = [strategy: :one_for_one, name: Diffuser.Supervisor]
|
||||||
|
Supervisor.start_link(children, opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Tell Phoenix to update the endpoint configuration
|
||||||
|
# whenever the application is updated.
|
||||||
|
@impl true
|
||||||
|
def config_change(changed, _new, removed) do
|
||||||
|
DiffuserWeb.Endpoint.config_change(changed, removed)
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,125 @@
|
||||||
|
defmodule Diffuser.Generator do
|
||||||
|
@moduledoc """
|
||||||
|
The Generator context.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import Ecto.Query, warn: false
|
||||||
|
alias Diffuser.Repo
|
||||||
|
|
||||||
|
alias Diffuser.Generator.{PromptRequest, PromptRequestResult}
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Returns the list of prompt_requests.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
iex> list_prompt_requests()
|
||||||
|
[%PromptRequest{}, ...]
|
||||||
|
|
||||||
|
"""
|
||||||
|
def list_prompt_requests do
|
||||||
|
Repo.all(PromptRequest)
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Gets a single prompt_request.
|
||||||
|
|
||||||
|
Raises `Ecto.NoResultsError` if the Prompt request does not exist.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
iex> get_prompt_request!(123)
|
||||||
|
%PromptRequest{}
|
||||||
|
|
||||||
|
iex> get_prompt_request!(456)
|
||||||
|
** (Ecto.NoResultsError)
|
||||||
|
|
||||||
|
"""
|
||||||
|
def get_prompt_request!(id),
|
||||||
|
do: Repo.one!(from pr in PromptRequest, where: pr.id == ^id, preload: [:images])
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Creates a prompt_request.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
iex> create_prompt_request(%{field: value})
|
||||||
|
{:ok, %PromptRequest{}}
|
||||||
|
|
||||||
|
iex> create_prompt_request(%{field: bad_value})
|
||||||
|
{:error, %Ecto.Changeset{}}
|
||||||
|
|
||||||
|
"""
|
||||||
|
def create_prompt_request(attrs \\ %{}) do
|
||||||
|
%PromptRequest{}
|
||||||
|
|> PromptRequest.changeset(attrs)
|
||||||
|
|> Repo.insert()
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Updates a prompt_request.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
iex> update_prompt_request(prompt_request, %{field: new_value})
|
||||||
|
{:ok, %PromptRequest{}}
|
||||||
|
|
||||||
|
iex> update_prompt_request(prompt_request, %{field: bad_value})
|
||||||
|
{:error, %Ecto.Changeset{}}
|
||||||
|
|
||||||
|
"""
|
||||||
|
def update_prompt_request(%PromptRequest{} = prompt_request, attrs) do
|
||||||
|
prompt_request
|
||||||
|
|> PromptRequest.changeset(attrs)
|
||||||
|
|> Repo.update()
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Deletes a prompt_request.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
iex> delete_prompt_request(prompt_request)
|
||||||
|
{:ok, %PromptRequest{}}
|
||||||
|
|
||||||
|
iex> delete_prompt_request(prompt_request)
|
||||||
|
{:error, %Ecto.Changeset{}}
|
||||||
|
|
||||||
|
"""
|
||||||
|
def delete_prompt_request(%PromptRequest{} = prompt_request) do
|
||||||
|
Repo.delete(prompt_request)
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Returns an `%Ecto.Changeset{}` for tracking prompt_request changes.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
iex> change_prompt_request(prompt_request)
|
||||||
|
%Ecto.Changeset{data: %PromptRequest{}}
|
||||||
|
|
||||||
|
"""
|
||||||
|
def change_prompt_request(%PromptRequest{} = prompt_request, attrs \\ %{}) do
|
||||||
|
PromptRequest.changeset(prompt_request, attrs)
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_prompt_request_result(prompt_request_id, image) do
|
||||||
|
%PromptRequestResult{}
|
||||||
|
|> PromptRequestResult.changeset(%{
|
||||||
|
image: image,
|
||||||
|
prompt_request_id: prompt_request_id
|
||||||
|
})
|
||||||
|
|> Repo.insert()
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_prompt_request_results(prompt_request_id, images) do
|
||||||
|
Enum.each(images, fn %{file_name: file_name, binary: binary} ->
|
||||||
|
create_prompt_request_result(prompt_request_id, %{
|
||||||
|
file_name: file_name,
|
||||||
|
filename: file_name,
|
||||||
|
binary: binary,
|
||||||
|
updated_at: DateTime.utc_now()
|
||||||
|
})
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,23 @@
|
||||||
|
defmodule Diffuser.Generator.PromptRequest do
|
||||||
|
use Ecto.Schema
|
||||||
|
use Waffle.Ecto.Schema
|
||||||
|
import Ecto.Changeset
|
||||||
|
alias Diffuser.Generator.PromptRequestResult
|
||||||
|
|
||||||
|
@primary_key {:id, Ecto.UUID, autogenerate: true}
|
||||||
|
schema "prompt_requests" do
|
||||||
|
field :prompt, :string
|
||||||
|
field :status, :string, default: "queued"
|
||||||
|
|
||||||
|
has_many :images, PromptRequestResult, on_delete: :delete_all
|
||||||
|
|
||||||
|
timestamps()
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc false
|
||||||
|
def changeset(prompt_request, attrs) do
|
||||||
|
prompt_request
|
||||||
|
|> cast(attrs, [:prompt, :status])
|
||||||
|
|> validate_required([:prompt])
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,98 @@
|
||||||
|
defmodule Diffuser.Generator.PromptRequestGenserver do
|
||||||
|
use GenServer
|
||||||
|
alias Diffuser.Generator
|
||||||
|
alias Diffuser.Generator.PromptRequest
|
||||||
|
alias DiffuserWeb.Endpoint
|
||||||
|
alias Diffuser.PythonHelper, as: Helper
|
||||||
|
|
||||||
|
@path 'lib/diffuser/python'
|
||||||
|
|
||||||
|
def new(%{prompt_request: %PromptRequest{} = prompt_request}) do
|
||||||
|
GenServer.start_link(
|
||||||
|
__MODULE__,
|
||||||
|
%{prompt_request: prompt_request},
|
||||||
|
name: name_for(prompt_request)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def name_for(%PromptRequest{id: prompt_request_id}),
|
||||||
|
do: {:global, "prompt_request:#{prompt_request_id}"}
|
||||||
|
|
||||||
|
def init(%{prompt_request: %PromptRequest{} = prompt_request}) do
|
||||||
|
send(self(), :start_prompt)
|
||||||
|
|
||||||
|
{:ok,
|
||||||
|
%{
|
||||||
|
prompt_request: prompt_request
|
||||||
|
}}
|
||||||
|
end
|
||||||
|
|
||||||
|
def handle_info(:start_prompt, %{prompt_request: prompt_request} = state) do
|
||||||
|
with {:ok, %{prompt: prompt} = active_prompt} <-
|
||||||
|
update_and_broadcast_progress(prompt_request, "in_progress"),
|
||||||
|
:ok <- call_python(:test_script, :test_func, prompt),
|
||||||
|
%PromptRequest{} = prompt_request_with_results <- write_and_save_images(active_prompt),
|
||||||
|
{:ok, completed_prompt} <-
|
||||||
|
update_and_broadcast_progress(prompt_request_with_results, "finished") do
|
||||||
|
IO.inspect(completed_prompt)
|
||||||
|
{:noreply, state}
|
||||||
|
else
|
||||||
|
nil ->
|
||||||
|
raise("prompt not found")
|
||||||
|
|
||||||
|
{:error, message} ->
|
||||||
|
raise(message)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp update_and_broadcast_progress(%PromptRequest{id: id} = prompt_request, new_status) do
|
||||||
|
{:ok, new_prompt} = Generator.update_prompt_request(prompt_request, %{status: new_status})
|
||||||
|
:ok = Endpoint.broadcast("request:#{id}", "request", %{prompt_request: new_prompt})
|
||||||
|
|
||||||
|
{:ok, new_prompt}
|
||||||
|
end
|
||||||
|
|
||||||
|
defp call_python(_module, _func, prompt) do
|
||||||
|
Port.open(
|
||||||
|
{:spawn, "python #{@path}/stable_diffusion.py --prompt #{prompt}"},
|
||||||
|
[:binary, {:packet, 4}]
|
||||||
|
)
|
||||||
|
|
||||||
|
# TODO: We will want to flush, and get the image data from the script
|
||||||
|
# then write it to PromptResult
|
||||||
|
|
||||||
|
# pid = Helper.py_instance(Path.absname(@path))
|
||||||
|
# :python.call(pid, module, func, args)
|
||||||
|
|
||||||
|
# pid
|
||||||
|
# |> :python.stop()
|
||||||
|
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
|
||||||
|
defp write_and_save_images(%PromptRequest{id: id, prompt: prompt}) do
|
||||||
|
height = :rand.uniform(512)
|
||||||
|
width = :rand.uniform(512)
|
||||||
|
IO.inspect(height)
|
||||||
|
|
||||||
|
{:ok, resp} =
|
||||||
|
:httpc.request(
|
||||||
|
:get,
|
||||||
|
{'http://placekitten.com/#{height}/#{width}', []},
|
||||||
|
[],
|
||||||
|
body_format: :binary
|
||||||
|
)
|
||||||
|
|
||||||
|
{{_, 200, 'OK'}, _headers, body} = resp
|
||||||
|
|
||||||
|
Generator.create_prompt_request_results(id, [
|
||||||
|
%{
|
||||||
|
file_name: "#{prompt}.jpg",
|
||||||
|
filename: "#{prompt}.jpg",
|
||||||
|
binary: body
|
||||||
|
}
|
||||||
|
])
|
||||||
|
|
||||||
|
Generator.get_prompt_request!(id)
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,22 @@
|
||||||
|
defmodule Diffuser.Generator.PromptRequestResult do
|
||||||
|
use Ecto.Schema
|
||||||
|
use Waffle.Ecto.Schema
|
||||||
|
import Ecto.Changeset
|
||||||
|
alias Diffuser.Generator.PromptRequest
|
||||||
|
|
||||||
|
@primary_key {:id, Ecto.UUID, autogenerate: true}
|
||||||
|
schema "prompt_request_results" do
|
||||||
|
field :image, Diffuser.Uploaders.Image.Type
|
||||||
|
belongs_to :prompt_request, PromptRequest, type: :binary_id
|
||||||
|
|
||||||
|
timestamps()
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc false
|
||||||
|
def changeset(prompt_request, attrs) do
|
||||||
|
prompt_request
|
||||||
|
|> cast(attrs, [:prompt_request_id])
|
||||||
|
|> cast_attachments(attrs, [:image])
|
||||||
|
|> validate_required([:prompt_request_id, :image])
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,27 @@
|
||||||
|
defmodule Diffuser.Generator.PromptRequestSupervisor do
|
||||||
|
use DynamicSupervisor
|
||||||
|
alias Diffuser.Generator.PromptRequest
|
||||||
|
|
||||||
|
def start_link(init_arg) do
|
||||||
|
DynamicSupervisor.start_link(__MODULE__, init_arg, name: __MODULE__)
|
||||||
|
end
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def init(_init_arg) do
|
||||||
|
DynamicSupervisor.init(strategy: :one_for_one)
|
||||||
|
end
|
||||||
|
|
||||||
|
def start_prompt_request(%PromptRequest{} = prompt_request) do
|
||||||
|
Task.Supervisor.start_child(
|
||||||
|
__MODULE__,
|
||||||
|
Diffuser.Generator.PromptRequestGenserver,
|
||||||
|
:new,
|
||||||
|
[
|
||||||
|
%{
|
||||||
|
prompt_request: prompt_request
|
||||||
|
}
|
||||||
|
],
|
||||||
|
restart: :transient
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,3 @@
|
||||||
|
defmodule Diffuser.Mailer do
|
||||||
|
use Swoosh.Mailer, otp_app: :diffuser
|
||||||
|
end
|
|
@ -0,0 +1,201 @@
|
||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright [yyyy] [name of copyright owner]
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
|
@ -0,0 +1,82 @@
|
||||||
|
Copyright (c) 2022 Robin Rombach and Patrick Esser and contributors
|
||||||
|
|
||||||
|
CreativeML Open RAIL-M
|
||||||
|
dated August 22, 2022
|
||||||
|
|
||||||
|
Section I: PREAMBLE
|
||||||
|
|
||||||
|
Multimodal generative models are being widely adopted and used, and have the potential to transform the way artists, among other individuals, conceive and benefit from AI or ML technologies as a tool for content creation.
|
||||||
|
|
||||||
|
Notwithstanding the current and potential benefits that these artifacts can bring to society at large, there are also concerns about potential misuses of them, either due to their technical limitations or ethical considerations.
|
||||||
|
|
||||||
|
In short, this license strives for both the open and responsible downstream use of the accompanying model. When it comes to the open character, we took inspiration from open source permissive licenses regarding the grant of IP rights. Referring to the downstream responsible use, we added use-based restrictions not permitting the use of the Model in very specific scenarios, in order for the licensor to be able to enforce the license in case potential misuses of the Model may occur. At the same time, we strive to promote open and responsible research on generative models for art and content generation.
|
||||||
|
|
||||||
|
Even though downstream derivative versions of the model could be released under different licensing terms, the latter will always have to include - at minimum - the same use-based restrictions as the ones in the original license (this license). We believe in the intersection between open and responsible AI development; thus, this License aims to strike a balance between both in order to enable responsible open-science in the field of AI.
|
||||||
|
|
||||||
|
This License governs the use of the model (and its derivatives) and is informed by the model card associated with the model.
|
||||||
|
|
||||||
|
NOW THEREFORE, You and Licensor agree as follows:
|
||||||
|
|
||||||
|
1. Definitions
|
||||||
|
|
||||||
|
- "License" means the terms and conditions for use, reproduction, and Distribution as defined in this document.
|
||||||
|
- "Data" means a collection of information and/or content extracted from the dataset used with the Model, including to train, pretrain, or otherwise evaluate the Model. The Data is not licensed under this License.
|
||||||
|
- "Output" means the results of operating a Model as embodied in informational content resulting therefrom.
|
||||||
|
- "Model" means any accompanying machine-learning based assemblies (including checkpoints), consisting of learnt weights, parameters (including optimizer states), corresponding to the model architecture as embodied in the Complementary Material, that have been trained or tuned, in whole or in part on the Data, using the Complementary Material.
|
||||||
|
- "Derivatives of the Model" means all modifications to the Model, works based on the Model, or any other model which is created or initialized by transfer of patterns of the weights, parameters, activations or output of the Model, to the other model, in order to cause the other model to perform similarly to the Model, including - but not limited to - distillation methods entailing the use of intermediate data representations or methods based on the generation of synthetic data by the Model for training the other model.
|
||||||
|
- "Complementary Material" means the accompanying source code and scripts used to define, run, load, benchmark or evaluate the Model, and used to prepare data for training or evaluation, if any. This includes any accompanying documentation, tutorials, examples, etc, if any.
|
||||||
|
- "Distribution" means any transmission, reproduction, publication or other sharing of the Model or Derivatives of the Model to a third party, including providing the Model as a hosted service made available by electronic or other remote means - e.g. API-based or web access.
|
||||||
|
- "Licensor" means the copyright owner or entity authorized by the copyright owner that is granting the License, including the persons or entities that may have rights in the Model and/or distributing the Model.
|
||||||
|
- "You" (or "Your") means an individual or Legal Entity exercising permissions granted by this License and/or making use of the Model for whichever purpose and in any field of use, including usage of the Model in an end-use application - e.g. chatbot, translator, image generator.
|
||||||
|
- "Third Parties" means individuals or legal entities that are not under common control with Licensor or You.
|
||||||
|
- "Contribution" means any work of authorship, including the original version of the Model and any modifications or additions to that Model or Derivatives of the Model thereof, that is intentionally submitted to Licensor for inclusion in the Model by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Model, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
- "Contributor" means Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Model.
|
||||||
|
|
||||||
|
Section II: INTELLECTUAL PROPERTY RIGHTS
|
||||||
|
|
||||||
|
Both copyright and patent grants apply to the Model, Derivatives of the Model and Complementary Material. The Model and Derivatives of the Model are subject to additional terms as described in Section III.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare, publicly display, publicly perform, sublicense, and distribute the Complementary Material, the Model, and Derivatives of the Model.
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of this License and where and as applicable, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this paragraph) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Model and the Complementary Material, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Model to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Model and/or Complementary Material or a Contribution incorporated within the Model and/or Complementary Material constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for the Model and/or Work shall terminate as of the date such litigation is asserted or filed.
|
||||||
|
|
||||||
|
Section III: CONDITIONS OF USAGE, DISTRIBUTION AND REDISTRIBUTION
|
||||||
|
|
||||||
|
4. Distribution and Redistribution. You may host for Third Party remote access purposes (e.g. software-as-a-service), reproduce and distribute copies of the Model or Derivatives of the Model thereof in any medium, with or without modifications, provided that You meet the following conditions:
|
||||||
|
Use-based restrictions as referenced in paragraph 5 MUST be included as an enforceable provision by You in any type of legal agreement (e.g. a license) governing the use and/or distribution of the Model or Derivatives of the Model, and You shall give notice to subsequent users You Distribute to, that the Model or Derivatives of the Model are subject to paragraph 5. This provision does not apply to the use of Complementary Material.
|
||||||
|
You must give any Third Party recipients of the Model or Derivatives of the Model a copy of this License;
|
||||||
|
You must cause any modified files to carry prominent notices stating that You changed the files;
|
||||||
|
You must retain all copyright, patent, trademark, and attribution notices excluding those notices that do not pertain to any part of the Model, Derivatives of the Model.
|
||||||
|
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions - respecting paragraph 4.a. - for use, reproduction, or Distribution of Your modifications, or for any such Derivatives of the Model as a whole, provided Your use, reproduction, and Distribution of the Model otherwise complies with the conditions stated in this License.
|
||||||
|
5. Use-based restrictions. The restrictions set forth in Attachment A are considered Use-based restrictions. Therefore You cannot use the Model and the Derivatives of the Model for the specified restricted uses. You may use the Model subject to this License, including only for lawful purposes and in accordance with the License. Use may include creating any content with, finetuning, updating, running, training, evaluating and/or reparametrizing the Model. You shall require all of Your users who use the Model or a Derivative of the Model to comply with the terms of this paragraph (paragraph 5).
|
||||||
|
6. The Output You Generate. Except as set forth herein, Licensor claims no rights in the Output You generate using the Model. You are accountable for the Output you generate and its subsequent uses. No use of the output can contravene any provision as stated in the License.
|
||||||
|
|
||||||
|
Section IV: OTHER PROVISIONS
|
||||||
|
|
||||||
|
7. Updates and Runtime Restrictions. To the maximum extent permitted by law, Licensor reserves the right to restrict (remotely or otherwise) usage of the Model in violation of this License, update the Model through electronic means, or modify the Output of the Model based on updates. You shall undertake reasonable efforts to use the latest version of the Model.
|
||||||
|
8. Trademarks and related. Nothing in this License permits You to make use of Licensors’ trademarks, trade names, logos or to otherwise suggest endorsement or misrepresent the relationship between the parties; and any rights not expressly granted herein are reserved by the Licensors.
|
||||||
|
9. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Model and the Complementary Material (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Model, Derivatives of the Model, and the Complementary Material and assume any risks associated with Your exercise of permissions under this License.
|
||||||
|
10. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Model and the Complementary Material (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
||||||
|
11. Accepting Warranty or Additional Liability. While redistributing the Model, Derivatives of the Model and the Complementary Material thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
||||||
|
12. If any provision of this License is held to be invalid, illegal or unenforceable, the remaining provisions shall be unaffected thereby and remain valid as if such provision had not been set forth herein.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Attachment A
|
||||||
|
|
||||||
|
Use Restrictions
|
||||||
|
|
||||||
|
You agree not to use the Model or Derivatives of the Model:
|
||||||
|
- In any way that violates any applicable national, federal, state, local or international law or regulation;
|
||||||
|
- For the purpose of exploiting, harming or attempting to exploit or harm minors in any way;
|
||||||
|
- To generate or disseminate verifiably false information and/or content with the purpose of harming others;
|
||||||
|
- To generate or disseminate personal identifiable information that can be used to harm an individual;
|
||||||
|
- To defame, disparage or otherwise harass others;
|
||||||
|
- For fully automated decision making that adversely impacts an individual’s legal rights or otherwise creates or modifies a binding, enforceable obligation;
|
||||||
|
- For any use intended to or which has the effect of discriminating against or harming individuals or groups based on online or offline social behavior or known or predicted personal or personality characteristics;
|
||||||
|
- To exploit any of the vulnerabilities of a specific group of persons based on their age, social, physical or mental characteristics, in order to materially distort the behavior of a person pertaining to that group in a manner that causes or is likely to cause that person or another person physical or psychological harm;
|
||||||
|
- For any use intended to or which has the effect of discriminating against individuals or groups based on legally protected characteristics or categories;
|
||||||
|
- To provide medical advice and medical results interpretation;
|
||||||
|
- To generate or disseminate information for the purpose to be used for administration of justice, law enforcement, immigration or asylum processes, such as predicting an individual will commit fraud/crime commitment (e.g. by text profiling, drawing causal relationships between assertions made in documents, indiscriminate and arbitrarily-targeted use).
|
|
@ -0,0 +1,59 @@
|
||||||
|
# stable_diffusion.openvino
|
||||||
|
|
||||||
|
Implementation of Text-To-Image generation using Stable Diffusion on Intel CPU.
|
||||||
|
<p align="center">
|
||||||
|
<img src="data/title.png"/>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
* Linux, Windows, MacOS
|
||||||
|
* Python 3.8.+
|
||||||
|
* CPU compatible with OpenVINO.
|
||||||
|
|
||||||
|
## Install requirements
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install -r requirements.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
## Generate image from text description
|
||||||
|
|
||||||
|
```bash
|
||||||
|
usage: stable_diffusion.py [-h] [--models-cfg MODELS_CFG] [--beta-start BETA_START] [--beta-end BETA_END] [--beta-schedule BETA_SCHEDULE] [--num-inference-steps NUM_INFERENCE_STEPS]
|
||||||
|
[--guidance-scale GUIDANCE_SCALE] [--eta ETA] [--tokenizer TOKENIZER] [--prompt PROMPT] [--output OUTPUT]
|
||||||
|
|
||||||
|
optional arguments:
|
||||||
|
-h, --help show this help message and exit
|
||||||
|
--models-cfg MODELS_CFG
|
||||||
|
path to models config
|
||||||
|
--beta-start BETA_START
|
||||||
|
LMSDiscreteScheduler::beta_start
|
||||||
|
--beta-end BETA_END LMSDiscreteScheduler::beta_end
|
||||||
|
--beta-schedule BETA_SCHEDULE
|
||||||
|
LMSDiscreteScheduler::beta_schedule
|
||||||
|
--num-inference-steps NUM_INFERENCE_STEPS
|
||||||
|
num inference steps
|
||||||
|
--guidance-scale GUIDANCE_SCALE
|
||||||
|
guidance scale
|
||||||
|
--eta ETA eta
|
||||||
|
--tokenizer TOKENIZER
|
||||||
|
tokenizer
|
||||||
|
--prompt PROMPT prompt
|
||||||
|
--output OUTPUT output image name
|
||||||
|
```
|
||||||
|
|
||||||
|
### Example
|
||||||
|
```bash
|
||||||
|
python stable_diffusion.py --prompt "Street-art painting of Emilia Clarke in style of Banksy, photorealism"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Acknowledgements
|
||||||
|
|
||||||
|
* Original implementation of Stable Diffusion: https://github.com/CompVis/stable-diffusion
|
||||||
|
* diffusers library: https://github.com/huggingface/diffusers
|
||||||
|
|
||||||
|
## Disclaimer
|
||||||
|
|
||||||
|
The authors are not responsible for the content generated using this project.
|
||||||
|
Please, don't use this project to produce illegal, harmful, offensive etc. content.
|
|
@ -0,0 +1,26 @@
|
||||||
|
{
|
||||||
|
"text_encoder.xml": {
|
||||||
|
"url": "https://drive.google.com/uc?id=1VXPpeieEkFbSkxbmga32DebTsf8E8NN4",
|
||||||
|
"md5": "d5c6dd1e3ea5b8412b4434863877dfc9"
|
||||||
|
},
|
||||||
|
"text_encoder.bin": {
|
||||||
|
"url": "https://drive.google.com/uc?id=1r09rTco5FtIP0IPzJTompAN8YAu2doGG",
|
||||||
|
"md5": "ba70816e82b49b33ca292d46a787975f"
|
||||||
|
},
|
||||||
|
"unet.xml": {
|
||||||
|
"url": "https://drive.google.com/uc?id=1md8Eur0AUWyEciWO-NCQ5gqpsHC7p_gD",
|
||||||
|
"md5": "2d9e95da71447a81e07559de8b6df6f3"
|
||||||
|
},
|
||||||
|
"unet.bin": {
|
||||||
|
"url": "https://drive.google.com/uc?id=1aCEXRLPK7vjABaD4ZC-SGtpT5kgyTcMo",
|
||||||
|
"md5": "b0ffbc118ed32532172ad60bb1cc2a71"
|
||||||
|
},
|
||||||
|
"vae.xml": {
|
||||||
|
"url": "https://drive.google.com/uc?id=1MblgqTMooC6N5jq5s_69k02G4evRlST1",
|
||||||
|
"md5": "281704d317c33b06e96bb54b2d546efe"
|
||||||
|
},
|
||||||
|
"vae.bin": {
|
||||||
|
"url": "https://drive.google.com/uc?id=1g9cFqb0qcr4nEBrLk_mlWBl5Lu_ggIfA",
|
||||||
|
"md5": "15c7db7f79059553b7d8381815347c03"
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 484 KiB |
|
@ -0,0 +1,8 @@
|
||||||
|
numpy==1.19.5
|
||||||
|
opencv-python==4.5.5.64
|
||||||
|
transformers==4.16.2
|
||||||
|
diffusers==0.2.4
|
||||||
|
tqdm==4.64.0
|
||||||
|
openvino==2022.1.0
|
||||||
|
huggingface_hub==0.9.0
|
||||||
|
scipy==1.9.0
|
|
@ -0,0 +1,173 @@
|
||||||
|
import argparse
|
||||||
|
import os
|
||||||
|
import inspect
|
||||||
|
import numpy as np
|
||||||
|
# openvino
|
||||||
|
from openvino.runtime import Core
|
||||||
|
# tokenizer
|
||||||
|
from transformers import CLIPTokenizer
|
||||||
|
# scheduler
|
||||||
|
from diffusers import LMSDiscreteScheduler
|
||||||
|
# utils
|
||||||
|
from tqdm import tqdm
|
||||||
|
import cv2
|
||||||
|
from huggingface_hub import hf_hub_download
|
||||||
|
|
||||||
|
|
||||||
|
class StableDiffusion:
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
scheduler,
|
||||||
|
model="bes-dev/stable-diffusion-v1-4-openvino",
|
||||||
|
tokenizer="openai/clip-vit-large-patch14",
|
||||||
|
device="CPU"
|
||||||
|
):
|
||||||
|
self.tokenizer = CLIPTokenizer.from_pretrained(tokenizer)
|
||||||
|
self.scheduler = scheduler
|
||||||
|
# models
|
||||||
|
self.core = Core()
|
||||||
|
# text features
|
||||||
|
self._text_encoder = self.core.read_model(
|
||||||
|
hf_hub_download(repo_id=model, filename="text_encoder.xml"),
|
||||||
|
hf_hub_download(repo_id=model, filename="text_encoder.bin")
|
||||||
|
)
|
||||||
|
self.text_encoder = self.core.compile_model(self._text_encoder, device)
|
||||||
|
# diffusion
|
||||||
|
self._unet = self.core.read_model(
|
||||||
|
hf_hub_download(repo_id=model, filename="unet.xml"),
|
||||||
|
hf_hub_download(repo_id=model, filename="unet.bin")
|
||||||
|
)
|
||||||
|
self.unet = self.core.compile_model(self._unet, device)
|
||||||
|
self.latent_shape = tuple(self._unet.inputs[0].shape)[1:]
|
||||||
|
# decoder
|
||||||
|
self._vae = self.core.read_model(
|
||||||
|
hf_hub_download(repo_id=model, filename="vae.xml"),
|
||||||
|
hf_hub_download(repo_id=model, filename="vae.bin")
|
||||||
|
)
|
||||||
|
self.vae = self.core.compile_model(self._vae, device)
|
||||||
|
|
||||||
|
def __call__(self, prompt, num_inference_steps = 32, guidance_scale = 7.5, eta = 0.0):
|
||||||
|
result = lambda var: next(iter(var.values()))
|
||||||
|
|
||||||
|
# extract condition
|
||||||
|
tokens = self.tokenizer(
|
||||||
|
prompt,
|
||||||
|
padding="max_length",
|
||||||
|
max_length=self.tokenizer.model_max_length,
|
||||||
|
truncation=True
|
||||||
|
).input_ids
|
||||||
|
text_embeddings = result(
|
||||||
|
self.text_encoder.infer_new_request({"tokens": np.array([tokens])})
|
||||||
|
)
|
||||||
|
|
||||||
|
# do classifier free guidance
|
||||||
|
if guidance_scale > 1.0:
|
||||||
|
tokens_uncond = self.tokenizer(
|
||||||
|
"",
|
||||||
|
padding="max_length",
|
||||||
|
max_length=self.tokenizer.model_max_length,
|
||||||
|
truncation=True
|
||||||
|
).input_ids
|
||||||
|
uncond_embeddings = result(
|
||||||
|
self.text_encoder.infer_new_request({"tokens": np.array([tokens_uncond])})
|
||||||
|
)
|
||||||
|
text_embeddings = np.concatenate((uncond_embeddings, text_embeddings), axis=0)
|
||||||
|
|
||||||
|
# make noise
|
||||||
|
latents = np.random.randn(*self.latent_shape)
|
||||||
|
|
||||||
|
# set timesteps
|
||||||
|
accepts_offset = "offset" in set(inspect.signature(self.scheduler.set_timesteps).parameters.keys())
|
||||||
|
extra_set_kwargs = {}
|
||||||
|
if accepts_offset:
|
||||||
|
extra_set_kwargs["offset"] = 1
|
||||||
|
|
||||||
|
self.scheduler.set_timesteps(num_inference_steps, **extra_set_kwargs)
|
||||||
|
|
||||||
|
# if we use LMSDiscreteScheduler, let's make sure latents are mulitplied by sigmas
|
||||||
|
if isinstance(self.scheduler, LMSDiscreteScheduler):
|
||||||
|
latents = latents * self.scheduler.sigmas[0]
|
||||||
|
|
||||||
|
# prepare extra kwargs for the scheduler step, since not all schedulers have the same signature
|
||||||
|
# eta (η) is only used with the DDIMScheduler, it will be ignored for other schedulers.
|
||||||
|
# eta corresponds to η in DDIM paper: https://arxiv.org/abs/2010.02502
|
||||||
|
# and should be between [0, 1]
|
||||||
|
accepts_eta = "eta" in set(inspect.signature(self.scheduler.step).parameters.keys())
|
||||||
|
extra_step_kwargs = {}
|
||||||
|
if accepts_eta:
|
||||||
|
extra_step_kwargs["eta"] = eta
|
||||||
|
|
||||||
|
for i, t in tqdm(enumerate(self.scheduler.timesteps)):
|
||||||
|
# expand the latents if we are doing classifier free guidance
|
||||||
|
latent_model_input = np.stack([latents, latents], 0) if guidance_scale > 1.0 else latents
|
||||||
|
if isinstance(self.scheduler, LMSDiscreteScheduler):
|
||||||
|
sigma = self.scheduler.sigmas[i]
|
||||||
|
latent_model_input = latent_model_input / ((sigma**2 + 1) ** 0.5)
|
||||||
|
|
||||||
|
# predict the noise residual
|
||||||
|
noise_pred = result(self.unet.infer_new_request({
|
||||||
|
"latent_model_input": latent_model_input,
|
||||||
|
"t": t,
|
||||||
|
"encoder_hidden_states": text_embeddings
|
||||||
|
}))
|
||||||
|
|
||||||
|
# perform guidance
|
||||||
|
if guidance_scale > 1.0:
|
||||||
|
noise_pred = noise_pred[0] + guidance_scale * (noise_pred[1] - noise_pred[0])
|
||||||
|
|
||||||
|
# compute the previous noisy sample x_t -> x_t-1
|
||||||
|
if isinstance(self.scheduler, LMSDiscreteScheduler):
|
||||||
|
latents = self.scheduler.step(noise_pred, i, latents, **extra_step_kwargs)["prev_sample"]
|
||||||
|
else:
|
||||||
|
latents = self.scheduler.step(noise_pred, t, latents, **extra_step_kwargs)["prev_sample"]
|
||||||
|
|
||||||
|
image = result(self.vae.infer_new_request({
|
||||||
|
"latents": np.expand_dims(latents, 0)
|
||||||
|
}))
|
||||||
|
|
||||||
|
# convert tensor to opencv's image format
|
||||||
|
image = (image / 2 + 0.5).clip(0, 1)
|
||||||
|
image = (image[0].transpose(1, 2, 0)[:, :, ::-1] * 255).astype(np.uint8)
|
||||||
|
return image
|
||||||
|
|
||||||
|
def main(args):
|
||||||
|
scheduler = LMSDiscreteScheduler(
|
||||||
|
beta_start=args.beta_start,
|
||||||
|
beta_end=args.beta_end,
|
||||||
|
beta_schedule=args.beta_schedule,
|
||||||
|
tensor_format="np"
|
||||||
|
)
|
||||||
|
stable_diffusion = StableDiffusion(
|
||||||
|
model = args.model,
|
||||||
|
scheduler = scheduler,
|
||||||
|
tokenizer = args.tokenizer
|
||||||
|
)
|
||||||
|
image = stable_diffusion(
|
||||||
|
prompt = args.prompt,
|
||||||
|
num_inference_steps = args.num_inference_steps,
|
||||||
|
guidance_scale = args.guidance_scale,
|
||||||
|
eta = args.eta
|
||||||
|
)
|
||||||
|
cv2.imwrite(args.output, image)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
# pipeline configure
|
||||||
|
parser.add_argument("--model", type=str, default="bes-dev/stable-diffusion-v1-4-openvino", help="model name")
|
||||||
|
# scheduler params
|
||||||
|
parser.add_argument("--beta-start", type=float, default=0.00085, help="LMSDiscreteScheduler::beta_start")
|
||||||
|
parser.add_argument("--beta-end", type=float, default=0.012, help="LMSDiscreteScheduler::beta_end")
|
||||||
|
parser.add_argument("--beta-schedule", type=str, default="scaled_linear", help="LMSDiscreteScheduler::beta_schedule")
|
||||||
|
# diffusion params
|
||||||
|
parser.add_argument("--num-inference-steps", type=int, default=32, help="num inference steps")
|
||||||
|
parser.add_argument("--guidance-scale", type=float, default=7.5, help="guidance scale")
|
||||||
|
parser.add_argument("--eta", type=float, default=0.0, help="eta")
|
||||||
|
# tokenizer
|
||||||
|
parser.add_argument("--tokenizer", type=str, default="openai/clip-vit-large-patch14", help="tokenizer")
|
||||||
|
# prompt
|
||||||
|
parser.add_argument("--prompt", type=str, default="Street-art painting of Emilia Clarke in style of Banksy, photorealism", help="prompt")
|
||||||
|
# output name
|
||||||
|
parser.add_argument("--output", type=str, default="output.png", help="output image name")
|
||||||
|
args = parser.parse_args()
|
||||||
|
main(args)
|
|
@ -0,0 +1,17 @@
|
||||||
|
import time
|
||||||
|
import asyncio
|
||||||
|
from stable_diffusion import StableDiffusion
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print("starting")
|
||||||
|
|
||||||
|
def test_func(args):
|
||||||
|
i = 0
|
||||||
|
print("running diffuser")
|
||||||
|
# asyncio.create_task(StableDiffusion(args))
|
||||||
|
StableDiffusion(args)
|
||||||
|
print("done running")
|
||||||
|
# while i<3:
|
||||||
|
# print("hi")
|
||||||
|
# time.sleep(1)
|
||||||
|
# i = i + 1
|
|
@ -0,0 +1,19 @@
|
||||||
|
defmodule Diffuser.PythonHelper do
|
||||||
|
@moduledoc false
|
||||||
|
|
||||||
|
def py_instance(path) when is_binary(path) do
|
||||||
|
# pybinpath = '/path/to/Anaconda/Anaconda3/bin/python'
|
||||||
|
# :python.start([python_path: pypath, python: pybinpath])
|
||||||
|
{:ok, pid} = :python.start([{:python_path, to_charlist(path)}])
|
||||||
|
pid
|
||||||
|
end
|
||||||
|
|
||||||
|
def py_call(pid, module, func, args \\ []) do
|
||||||
|
pid
|
||||||
|
|> :python.call(module, func, args)
|
||||||
|
end
|
||||||
|
|
||||||
|
def py_stop(pid) do
|
||||||
|
:python.stop(pid)
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,5 @@
|
||||||
|
defmodule Diffuser.Repo do
|
||||||
|
use Ecto.Repo,
|
||||||
|
otp_app: :diffuser,
|
||||||
|
adapter: Ecto.Adapters.Postgres
|
||||||
|
end
|
|
@ -0,0 +1,111 @@
|
||||||
|
defmodule DiffuserWeb do
|
||||||
|
@moduledoc """
|
||||||
|
The entrypoint for defining your web interface, such
|
||||||
|
as controllers, views, channels and so on.
|
||||||
|
|
||||||
|
This can be used in your application as:
|
||||||
|
|
||||||
|
use DiffuserWeb, :controller
|
||||||
|
use DiffuserWeb, :view
|
||||||
|
|
||||||
|
The definitions below will be executed for every view,
|
||||||
|
controller, etc, so keep them short and clean, focused
|
||||||
|
on imports, uses and aliases.
|
||||||
|
|
||||||
|
Do NOT define functions inside the quoted expressions
|
||||||
|
below. Instead, define any helper function in modules
|
||||||
|
and import those modules here.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def controller do
|
||||||
|
quote do
|
||||||
|
use Phoenix.Controller, namespace: DiffuserWeb
|
||||||
|
|
||||||
|
import Plug.Conn
|
||||||
|
import DiffuserWeb.Gettext
|
||||||
|
alias DiffuserWeb.Router.Helpers, as: Routes
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def view do
|
||||||
|
quote do
|
||||||
|
use Phoenix.View,
|
||||||
|
root: "lib/diffuser_web/templates",
|
||||||
|
namespace: DiffuserWeb
|
||||||
|
|
||||||
|
# Import convenience functions from controllers
|
||||||
|
import Phoenix.Controller,
|
||||||
|
only: [get_flash: 1, get_flash: 2, view_module: 1, view_template: 1]
|
||||||
|
|
||||||
|
# Include shared imports and aliases for views
|
||||||
|
unquote(view_helpers())
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def live_view do
|
||||||
|
quote do
|
||||||
|
use Phoenix.LiveView,
|
||||||
|
layout: {DiffuserWeb.LayoutView, "live.html"}
|
||||||
|
|
||||||
|
unquote(view_helpers())
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def live_component do
|
||||||
|
quote do
|
||||||
|
use Phoenix.LiveComponent
|
||||||
|
|
||||||
|
unquote(view_helpers())
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def component do
|
||||||
|
quote do
|
||||||
|
use Phoenix.Component
|
||||||
|
|
||||||
|
unquote(view_helpers())
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def router do
|
||||||
|
quote do
|
||||||
|
use Phoenix.Router
|
||||||
|
|
||||||
|
import Plug.Conn
|
||||||
|
import Phoenix.Controller
|
||||||
|
import Phoenix.LiveView.Router
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def channel do
|
||||||
|
quote do
|
||||||
|
use Phoenix.Channel
|
||||||
|
import DiffuserWeb.Gettext
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp view_helpers do
|
||||||
|
quote do
|
||||||
|
# Use all HTML functionality (forms, tags, etc)
|
||||||
|
use Phoenix.HTML
|
||||||
|
|
||||||
|
# Import LiveView and .heex helpers (live_render, live_patch, <.form>, etc)
|
||||||
|
import Phoenix.LiveView.Helpers
|
||||||
|
import DiffuserWeb.LiveHelpers
|
||||||
|
|
||||||
|
# Import basic rendering functionality (render, render_layout, etc)
|
||||||
|
import Phoenix.View
|
||||||
|
|
||||||
|
import DiffuserWeb.ErrorHelpers
|
||||||
|
import DiffuserWeb.Gettext
|
||||||
|
alias DiffuserWeb.Router.Helpers, as: Routes
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
When used, dispatch to the appropriate controller/view/etc.
|
||||||
|
"""
|
||||||
|
defmacro __using__(which) when is_atom(which) do
|
||||||
|
apply(__MODULE__, which, [])
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,8 @@
|
||||||
|
defmodule DiffuserWeb.RequestChannel do
|
||||||
|
use Phoenix.Channel
|
||||||
|
|
||||||
|
def join("request:" <> room_id, _message, socket) do
|
||||||
|
IO.inspect(room_id)
|
||||||
|
{:ok, socket}
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,46 @@
|
||||||
|
defmodule DiffuserWeb.RequestSocket do
|
||||||
|
use Phoenix.Socket
|
||||||
|
|
||||||
|
# A Socket handler
|
||||||
|
#
|
||||||
|
# It's possible to control the websocket connection and
|
||||||
|
# assign values that can be accessed by your channel topics.
|
||||||
|
|
||||||
|
channel "request:*", DiffuserWeb.RequestChannel
|
||||||
|
#
|
||||||
|
# To create a channel file, use the mix task:
|
||||||
|
#
|
||||||
|
# mix phx.gen.channel Room
|
||||||
|
#
|
||||||
|
# See the [`Channels guide`](https://hexdocs.pm/phoenix/channels.html)
|
||||||
|
# for further details.
|
||||||
|
|
||||||
|
# Socket params are passed from the client and can
|
||||||
|
# be used to verify and authenticate a user. After
|
||||||
|
# verification, you can put default assigns into
|
||||||
|
# the socket that will be set for all channels, ie
|
||||||
|
#
|
||||||
|
# {:ok, assign(socket, :user_id, verified_user_id)}
|
||||||
|
#
|
||||||
|
# To deny connection, return `:error`.
|
||||||
|
#
|
||||||
|
# See `Phoenix.Token` documentation for examples in
|
||||||
|
# performing token verification on connect.
|
||||||
|
@impl true
|
||||||
|
def connect(_params, socket, _connect_info) do
|
||||||
|
{:ok, socket}
|
||||||
|
end
|
||||||
|
|
||||||
|
# Socket id's are topics that allow you to identify all sockets for a given user:
|
||||||
|
#
|
||||||
|
# def id(socket), do: "user_socket:#{socket.assigns.user_id}"
|
||||||
|
#
|
||||||
|
# Would allow you to broadcast a "disconnect" event and terminate
|
||||||
|
# all active sockets and channels for a given user:
|
||||||
|
#
|
||||||
|
# Elixir.DiffuserWeb.Endpoint.broadcast("user_socket:#{user.id}", "disconnect", %{})
|
||||||
|
#
|
||||||
|
# Returning `nil` makes this socket anonymous.
|
||||||
|
@impl true
|
||||||
|
def id(_socket), do: nil
|
||||||
|
end
|
|
@ -0,0 +1,7 @@
|
||||||
|
defmodule DiffuserWeb.PageController do
|
||||||
|
use DiffuserWeb, :controller
|
||||||
|
|
||||||
|
def index(conn, _params) do
|
||||||
|
render(conn, "index.html")
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,56 @@
|
||||||
|
defmodule DiffuserWeb.Endpoint do
|
||||||
|
use Phoenix.Endpoint, otp_app: :diffuser
|
||||||
|
|
||||||
|
# The session will be stored in the cookie and signed,
|
||||||
|
# this means its contents can be read but not tampered with.
|
||||||
|
# Set :encryption_salt if you would also like to encrypt it.
|
||||||
|
@session_options [
|
||||||
|
store: :cookie,
|
||||||
|
key: "_diffuser_key",
|
||||||
|
signing_salt: "NZfusVTj"
|
||||||
|
]
|
||||||
|
|
||||||
|
socket "/live", Phoenix.LiveView.Socket, websocket: [connect_info: [session: @session_options]]
|
||||||
|
|
||||||
|
socket "/socket", DiffuserWeb.RequestSocket,
|
||||||
|
websocket: true,
|
||||||
|
longpoll: false
|
||||||
|
|
||||||
|
# Serve at "/" the static files from "priv/static" directory.
|
||||||
|
#
|
||||||
|
# You should set gzip to true if you are running phx.digest
|
||||||
|
# when deploying your static files in production.
|
||||||
|
plug Plug.Static,
|
||||||
|
at: "/",
|
||||||
|
from: :diffuser,
|
||||||
|
gzip: false,
|
||||||
|
only: ~w(assets fonts images favicon.ico robots.txt)
|
||||||
|
|
||||||
|
plug Plug.Static, at: "/uploads", from: Path.expand('./uploads'), gzip: false
|
||||||
|
|
||||||
|
# Code reloading can be explicitly enabled under the
|
||||||
|
# :code_reloader configuration of your endpoint.
|
||||||
|
if code_reloading? do
|
||||||
|
socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket
|
||||||
|
plug Phoenix.LiveReloader
|
||||||
|
plug Phoenix.CodeReloader
|
||||||
|
plug Phoenix.Ecto.CheckRepoStatus, otp_app: :diffuser
|
||||||
|
end
|
||||||
|
|
||||||
|
plug Phoenix.LiveDashboard.RequestLogger,
|
||||||
|
param_key: "request_logger",
|
||||||
|
cookie_key: "request_logger"
|
||||||
|
|
||||||
|
plug Plug.RequestId
|
||||||
|
plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint]
|
||||||
|
|
||||||
|
plug Plug.Parsers,
|
||||||
|
parsers: [:urlencoded, :multipart, :json],
|
||||||
|
pass: ["*/*"],
|
||||||
|
json_decoder: Phoenix.json_library()
|
||||||
|
|
||||||
|
plug Plug.MethodOverride
|
||||||
|
plug Plug.Head
|
||||||
|
plug Plug.Session, @session_options
|
||||||
|
plug DiffuserWeb.Router
|
||||||
|
end
|
|
@ -0,0 +1,24 @@
|
||||||
|
defmodule DiffuserWeb.Gettext do
|
||||||
|
@moduledoc """
|
||||||
|
A module providing Internationalization with a gettext-based API.
|
||||||
|
|
||||||
|
By using [Gettext](https://hexdocs.pm/gettext),
|
||||||
|
your module gains a set of macros for translations, for example:
|
||||||
|
|
||||||
|
import DiffuserWeb.Gettext
|
||||||
|
|
||||||
|
# Simple translation
|
||||||
|
gettext("Here is the string to translate")
|
||||||
|
|
||||||
|
# Plural translation
|
||||||
|
ngettext("Here is the string to translate",
|
||||||
|
"Here are the strings to translate",
|
||||||
|
3)
|
||||||
|
|
||||||
|
# Domain-based translation
|
||||||
|
dgettext("errors", "Here is the error message to translate")
|
||||||
|
|
||||||
|
See the [Gettext Docs](https://hexdocs.pm/gettext) for detailed usage.
|
||||||
|
"""
|
||||||
|
use Gettext, otp_app: :diffuser
|
||||||
|
end
|
|
@ -0,0 +1,60 @@
|
||||||
|
defmodule DiffuserWeb.LiveHelpers do
|
||||||
|
import Phoenix.LiveView
|
||||||
|
import Phoenix.LiveView.Helpers
|
||||||
|
|
||||||
|
alias Phoenix.LiveView.JS
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Renders a live component inside a modal.
|
||||||
|
|
||||||
|
The rendered modal receives a `:return_to` option to properly update
|
||||||
|
the URL when the modal is closed.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
<.modal return_to={Routes.prompt_request_index_path(@socket, :index)}>
|
||||||
|
<.live_component
|
||||||
|
module={DiffuserWeb.PromptRequestLive.FormComponent}
|
||||||
|
id={@prompt_request.id || :new}
|
||||||
|
title={@page_title}
|
||||||
|
action={@live_action}
|
||||||
|
return_to={Routes.prompt_request_index_path(@socket, :index)}
|
||||||
|
prompt_request: @prompt_request
|
||||||
|
/>
|
||||||
|
</.modal>
|
||||||
|
"""
|
||||||
|
def modal(assigns) do
|
||||||
|
assigns = assign_new(assigns, :return_to, fn -> nil end)
|
||||||
|
|
||||||
|
~H"""
|
||||||
|
<div id="modal" class="phx-modal fade-in" phx-remove={hide_modal()}>
|
||||||
|
<div
|
||||||
|
id="modal-content"
|
||||||
|
class="phx-modal-content fade-in-scale"
|
||||||
|
phx-click-away={JS.dispatch("click", to: "#close")}
|
||||||
|
phx-window-keydown={JS.dispatch("click", to: "#close")}
|
||||||
|
phx-key="escape"
|
||||||
|
>
|
||||||
|
<%= if @return_to do %>
|
||||||
|
<%= live_patch "✖",
|
||||||
|
to: @return_to,
|
||||||
|
id: "close",
|
||||||
|
class: "phx-modal-close",
|
||||||
|
phx_click: hide_modal()
|
||||||
|
%>
|
||||||
|
<% else %>
|
||||||
|
<a id="close" href="#" class="phx-modal-close" phx-click={hide_modal()}>✖</a>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= render_slot(@inner_block) %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
"""
|
||||||
|
end
|
||||||
|
|
||||||
|
defp hide_modal(js \\ %JS{}) do
|
||||||
|
js
|
||||||
|
|> JS.hide(to: "#modal", transition: "fade-out")
|
||||||
|
|> JS.hide(to: "#modal-content", transition: "fade-out-scale")
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,57 @@
|
||||||
|
defmodule DiffuserWeb.PromptRequestLive.FormComponent do
|
||||||
|
use DiffuserWeb, :live_component
|
||||||
|
|
||||||
|
alias Diffuser.Generator
|
||||||
|
alias Diffuser.Generator.PromptRequest
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def update(%{prompt_request: prompt_request} = assigns, socket) do
|
||||||
|
changeset = Generator.change_prompt_request(prompt_request)
|
||||||
|
|
||||||
|
{:ok,
|
||||||
|
socket
|
||||||
|
|> assign(assigns)
|
||||||
|
|> assign(:changeset, changeset)}
|
||||||
|
end
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def handle_event("validate", %{"prompt_request" => prompt_request_params}, socket) do
|
||||||
|
changeset =
|
||||||
|
socket.assigns.prompt_request
|
||||||
|
|> Generator.change_prompt_request(prompt_request_params)
|
||||||
|
|> Map.put(:action, :validate)
|
||||||
|
|
||||||
|
{:noreply, assign(socket, :changeset, changeset)}
|
||||||
|
end
|
||||||
|
|
||||||
|
def handle_event("save", %{"prompt_request" => prompt_request_params}, socket) do
|
||||||
|
save_prompt_request(socket, socket.assigns.action, prompt_request_params)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp save_prompt_request(socket, :edit, prompt_request_params) do
|
||||||
|
case Generator.update_prompt_request(socket.assigns.prompt_request, prompt_request_params) do
|
||||||
|
{:ok, %PromptRequest{} = prompt_request} ->
|
||||||
|
{:noreply,
|
||||||
|
socket
|
||||||
|
|> put_flash(:info, "Prompt request updated successfully")
|
||||||
|
|> push_redirect(to: Routes.prompt_request_show_path(socket, :show, prompt_request))}
|
||||||
|
|
||||||
|
{:error, %Ecto.Changeset{} = changeset} ->
|
||||||
|
{:noreply, assign(socket, :changeset, changeset)}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp save_prompt_request(socket, :new, prompt_request_params) do
|
||||||
|
with {:ok, prompt_request} <- Generator.create_prompt_request(prompt_request_params),
|
||||||
|
{:ok, _pid} <-
|
||||||
|
Diffuser.Generator.PromptRequestSupervisor.start_prompt_request(prompt_request) do
|
||||||
|
{:noreply,
|
||||||
|
socket
|
||||||
|
|> put_flash(:info, "Prompt request created successfully")
|
||||||
|
|> push_redirect(to: Routes.prompt_request_show_path(socket, :show, prompt_request))}
|
||||||
|
else
|
||||||
|
{:error, %Ecto.Changeset{} = changeset} ->
|
||||||
|
{:noreply, assign(socket, changeset: changeset)}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,20 @@
|
||||||
|
<div>
|
||||||
|
<h2><%= @title %></h2>
|
||||||
|
|
||||||
|
<.form
|
||||||
|
let={f}
|
||||||
|
for={@changeset}
|
||||||
|
id="prompt_request-form"
|
||||||
|
phx-target={@myself}
|
||||||
|
phx-change="validate"
|
||||||
|
phx-submit="save">
|
||||||
|
|
||||||
|
<%= label f, :prompt %>
|
||||||
|
<%= text_input f, :prompt %>
|
||||||
|
<%= error_tag f, :prompt %>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<%= submit "Save", phx_disable_with: "Saving..." %>
|
||||||
|
</div>
|
||||||
|
</.form>
|
||||||
|
</div>
|
|
@ -0,0 +1,46 @@
|
||||||
|
defmodule DiffuserWeb.PromptRequestLive.Index do
|
||||||
|
use DiffuserWeb, :live_view
|
||||||
|
|
||||||
|
alias Diffuser.Generator
|
||||||
|
alias Diffuser.Generator.PromptRequest
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def mount(_params, _session, socket) do
|
||||||
|
{:ok, assign(socket, :prompt_requests, list_prompt_requests())}
|
||||||
|
end
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def handle_params(params, _url, socket) do
|
||||||
|
{:noreply, apply_action(socket, socket.assigns.live_action, params)}
|
||||||
|
end
|
||||||
|
|
||||||
|
defp apply_action(socket, :edit, %{"id" => id}) do
|
||||||
|
socket
|
||||||
|
|> assign(:page_title, "Edit Prompt request")
|
||||||
|
|> assign(:prompt_request, Generator.get_prompt_request!(id))
|
||||||
|
end
|
||||||
|
|
||||||
|
defp apply_action(socket, :new, _params) do
|
||||||
|
socket
|
||||||
|
|> assign(:page_title, "New Prompt request")
|
||||||
|
|> assign(:prompt_request, %PromptRequest{})
|
||||||
|
end
|
||||||
|
|
||||||
|
defp apply_action(socket, :index, _params) do
|
||||||
|
socket
|
||||||
|
|> assign(:page_title, "Listing Prompt requests")
|
||||||
|
|> assign(:prompt_request, nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def handle_event("delete", %{"id" => id}, socket) do
|
||||||
|
prompt_request = Generator.get_prompt_request!(id)
|
||||||
|
{:ok, _} = Generator.delete_prompt_request(prompt_request)
|
||||||
|
|
||||||
|
{:noreply, assign(socket, :prompt_requests, list_prompt_requests())}
|
||||||
|
end
|
||||||
|
|
||||||
|
defp list_prompt_requests do
|
||||||
|
Generator.list_prompt_requests()
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,38 @@
|
||||||
|
<h1>Listing Prompt requests</h1>
|
||||||
|
|
||||||
|
<%= if @live_action in [:new, :edit] do %>
|
||||||
|
<.modal return_to={Routes.prompt_request_index_path(@socket, :index)}>
|
||||||
|
<.live_component
|
||||||
|
module={DiffuserWeb.PromptRequestLive.FormComponent}
|
||||||
|
id={@prompt_request.id || :new}
|
||||||
|
title={@page_title}
|
||||||
|
action={@live_action}
|
||||||
|
prompt_request={@prompt_request}}
|
||||||
|
/>
|
||||||
|
</.modal>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Prompt</th>
|
||||||
|
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="prompt_requests">
|
||||||
|
<%= for prompt_request <- @prompt_requests do %>
|
||||||
|
<tr id={"prompt_request-#{prompt_request.id}"}>
|
||||||
|
<td><%= prompt_request.prompt %></td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
<span><%= live_redirect "Show", to: Routes.prompt_request_show_path(@socket, :show, prompt_request) %></span>
|
||||||
|
<span><%= live_patch "Edit", to: Routes.prompt_request_index_path(@socket, :edit, prompt_request) %></span>
|
||||||
|
<span><%= link "Delete", to: "#", phx_click: "delete", phx_value_id: prompt_request.id, data: [confirm: "Are you sure?"] %></span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<span><%= live_patch "New Prompt request", to: Routes.prompt_request_index_path(@socket, :new) %></span>
|
|
@ -0,0 +1,43 @@
|
||||||
|
defmodule DiffuserWeb.PromptRequestLive.Show do
|
||||||
|
use DiffuserWeb, :live_view
|
||||||
|
import Ecto.Query
|
||||||
|
|
||||||
|
alias Diffuser.Generator
|
||||||
|
alias Diffuser.Generator.{Image, PromptRequest}
|
||||||
|
alias Diffuser.Repo
|
||||||
|
alias Phoenix.Socket.Broadcast
|
||||||
|
alias DiffuserWeb.Endpoint
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def mount(%{"id" => id}, _session, socket) do
|
||||||
|
Endpoint.subscribe("request:#{id}")
|
||||||
|
|
||||||
|
{:ok, socket |> assign(:prompt_request, Generator.get_prompt_request!(id))}
|
||||||
|
end
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def handle_params(%{"id" => id}, _, socket) do
|
||||||
|
{:noreply,
|
||||||
|
socket
|
||||||
|
|> assign(:page_title, page_title(socket.assigns.live_action))
|
||||||
|
|> assign(:prompt_request, Generator.get_prompt_request!(id))}
|
||||||
|
end
|
||||||
|
|
||||||
|
defp page_title(:show), do: "Show Prompt request"
|
||||||
|
defp page_title(:edit), do: "Edit Prompt request"
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def handle_info(
|
||||||
|
%Broadcast{
|
||||||
|
topic: _,
|
||||||
|
event: "request",
|
||||||
|
payload: %{prompt_request: %PromptRequest{} = prompt_request}
|
||||||
|
},
|
||||||
|
socket
|
||||||
|
),
|
||||||
|
do:
|
||||||
|
{:noreply,
|
||||||
|
assign(socket, %{
|
||||||
|
prompt_request: prompt_request
|
||||||
|
})}
|
||||||
|
end
|
|
@ -0,0 +1,38 @@
|
||||||
|
<h1>Show Prompt request</h1>
|
||||||
|
|
||||||
|
<%= if @live_action in [:edit] do %>
|
||||||
|
<.modal return_to={Routes.prompt_request_show_path(@socket, :show, @prompt_request)}>
|
||||||
|
<.live_component
|
||||||
|
module={DiffuserWeb.PromptRequestLive.FormComponent}
|
||||||
|
id={@prompt_request.id}
|
||||||
|
title={@page_title}
|
||||||
|
action={@live_action}
|
||||||
|
prompt_request={@prompt_request}
|
||||||
|
return_to={Routes.prompt_request_show_path(@socket, :show, @prompt_request)}
|
||||||
|
/>
|
||||||
|
</.modal>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
|
||||||
|
<li>
|
||||||
|
<strong>Prompt:</strong>
|
||||||
|
<%= @prompt_request.prompt %>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<strong>Status:</strong>
|
||||||
|
<%= @prompt_request.status %>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<strong>Images:</strong>
|
||||||
|
<%= if @prompt_request.images do %>
|
||||||
|
<%= for result <- @prompt_request.images do %>
|
||||||
|
<img src={"#{Diffuser.Uploaders.Image.url({result.image, result})}"} />
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<span><%= live_patch "Edit", to: Routes.prompt_request_show_path(@socket, :edit, @prompt_request), class: "button" %></span> |
|
||||||
|
<span><%= live_redirect "Back", to: Routes.prompt_request_index_path(@socket, :index) %></span>
|
|
@ -0,0 +1,63 @@
|
||||||
|
defmodule DiffuserWeb.Router do
|
||||||
|
use DiffuserWeb, :router
|
||||||
|
|
||||||
|
pipeline :browser do
|
||||||
|
plug :accepts, ["html"]
|
||||||
|
plug :fetch_session
|
||||||
|
plug :fetch_live_flash
|
||||||
|
plug :put_root_layout, {DiffuserWeb.LayoutView, :root}
|
||||||
|
plug :protect_from_forgery
|
||||||
|
plug :put_secure_browser_headers
|
||||||
|
end
|
||||||
|
|
||||||
|
pipeline :api do
|
||||||
|
plug :accepts, ["json"]
|
||||||
|
end
|
||||||
|
|
||||||
|
scope "/", DiffuserWeb do
|
||||||
|
pipe_through :browser
|
||||||
|
|
||||||
|
get "/", PageController, :index
|
||||||
|
|
||||||
|
live "/prompt_requests", PromptRequestLive.Index, :index
|
||||||
|
live "/prompt_requests/new", PromptRequestLive.Index, :new
|
||||||
|
live "/prompt_requests/:id/edit", PromptRequestLive.Index, :edit
|
||||||
|
|
||||||
|
live "/prompt_requests/:id", PromptRequestLive.Show, :show
|
||||||
|
live "/prompt_requests/:id/show/edit", PromptRequestLive.Show, :edit
|
||||||
|
end
|
||||||
|
|
||||||
|
# Other scopes may use custom stacks.
|
||||||
|
# scope "/api", DiffuserWeb do
|
||||||
|
# pipe_through :api
|
||||||
|
# end
|
||||||
|
|
||||||
|
# Enables LiveDashboard only for development
|
||||||
|
#
|
||||||
|
# If you want to use the LiveDashboard in production, you should put
|
||||||
|
# it behind authentication and allow only admins to access it.
|
||||||
|
# If your application does not have an admins-only section yet,
|
||||||
|
# you can use Plug.BasicAuth to set up some basic authentication
|
||||||
|
# as long as you are also using SSL (which you should anyway).
|
||||||
|
if Mix.env() in [:dev, :test] do
|
||||||
|
import Phoenix.LiveDashboard.Router
|
||||||
|
|
||||||
|
scope "/" do
|
||||||
|
pipe_through :browser
|
||||||
|
|
||||||
|
live_dashboard "/dashboard", metrics: DiffuserWeb.Telemetry
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Enables the Swoosh mailbox preview in development.
|
||||||
|
#
|
||||||
|
# Note that preview only shows emails that were sent by the same
|
||||||
|
# node running the Phoenix server.
|
||||||
|
if Mix.env() == :dev do
|
||||||
|
scope "/dev" do
|
||||||
|
pipe_through :browser
|
||||||
|
|
||||||
|
forward "/mailbox", Plug.Swoosh.MailboxPreview
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,71 @@
|
||||||
|
defmodule DiffuserWeb.Telemetry do
|
||||||
|
use Supervisor
|
||||||
|
import Telemetry.Metrics
|
||||||
|
|
||||||
|
def start_link(arg) do
|
||||||
|
Supervisor.start_link(__MODULE__, arg, name: __MODULE__)
|
||||||
|
end
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def init(_arg) do
|
||||||
|
children = [
|
||||||
|
# Telemetry poller will execute the given period measurements
|
||||||
|
# every 10_000ms. Learn more here: https://hexdocs.pm/telemetry_metrics
|
||||||
|
{:telemetry_poller, measurements: periodic_measurements(), period: 10_000}
|
||||||
|
# Add reporters as children of your supervision tree.
|
||||||
|
# {Telemetry.Metrics.ConsoleReporter, metrics: metrics()}
|
||||||
|
]
|
||||||
|
|
||||||
|
Supervisor.init(children, strategy: :one_for_one)
|
||||||
|
end
|
||||||
|
|
||||||
|
def metrics do
|
||||||
|
[
|
||||||
|
# Phoenix Metrics
|
||||||
|
summary("phoenix.endpoint.stop.duration",
|
||||||
|
unit: {:native, :millisecond}
|
||||||
|
),
|
||||||
|
summary("phoenix.router_dispatch.stop.duration",
|
||||||
|
tags: [:route],
|
||||||
|
unit: {:native, :millisecond}
|
||||||
|
),
|
||||||
|
|
||||||
|
# Database Metrics
|
||||||
|
summary("diffuser.repo.query.total_time",
|
||||||
|
unit: {:native, :millisecond},
|
||||||
|
description: "The sum of the other measurements"
|
||||||
|
),
|
||||||
|
summary("diffuser.repo.query.decode_time",
|
||||||
|
unit: {:native, :millisecond},
|
||||||
|
description: "The time spent decoding the data received from the database"
|
||||||
|
),
|
||||||
|
summary("diffuser.repo.query.query_time",
|
||||||
|
unit: {:native, :millisecond},
|
||||||
|
description: "The time spent executing the query"
|
||||||
|
),
|
||||||
|
summary("diffuser.repo.query.queue_time",
|
||||||
|
unit: {:native, :millisecond},
|
||||||
|
description: "The time spent waiting for a database connection"
|
||||||
|
),
|
||||||
|
summary("diffuser.repo.query.idle_time",
|
||||||
|
unit: {:native, :millisecond},
|
||||||
|
description:
|
||||||
|
"The time the connection spent waiting before being checked out for the query"
|
||||||
|
),
|
||||||
|
|
||||||
|
# VM Metrics
|
||||||
|
summary("vm.memory.total", unit: {:byte, :kilobyte}),
|
||||||
|
summary("vm.total_run_queue_lengths.total"),
|
||||||
|
summary("vm.total_run_queue_lengths.cpu"),
|
||||||
|
summary("vm.total_run_queue_lengths.io")
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
defp periodic_measurements do
|
||||||
|
[
|
||||||
|
# A module, function and arguments to be invoked periodically.
|
||||||
|
# This function must call :telemetry.execute/3 and a metric must be added above.
|
||||||
|
# {DiffuserWeb, :count_users, []}
|
||||||
|
]
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,5 @@
|
||||||
|
<main class="container">
|
||||||
|
<p class="alert alert-info" role="alert"><%= get_flash(@conn, :info) %></p>
|
||||||
|
<p class="alert alert-danger" role="alert"><%= get_flash(@conn, :error) %></p>
|
||||||
|
<%= @inner_content %>
|
||||||
|
</main>
|
|
@ -0,0 +1,11 @@
|
||||||
|
<main class="container">
|
||||||
|
<p class="alert alert-info" role="alert"
|
||||||
|
phx-click="lv:clear-flash"
|
||||||
|
phx-value-key="info"><%= live_flash(@flash, :info) %></p>
|
||||||
|
|
||||||
|
<p class="alert alert-danger" role="alert"
|
||||||
|
phx-click="lv:clear-flash"
|
||||||
|
phx-value-key="error"><%= live_flash(@flash, :error) %></p>
|
||||||
|
|
||||||
|
<%= @inner_content %>
|
||||||
|
</main>
|
|
@ -0,0 +1,30 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
|
<meta name="csrf-token" content={csrf_token_value()}>
|
||||||
|
<%= live_title_tag assigns[:page_title] || "Diffuser", suffix: " · Phoenix Framework" %>
|
||||||
|
<link phx-track-static rel="stylesheet" href={Routes.static_path(@conn, "/assets/app.css")}/>
|
||||||
|
<script defer phx-track-static type="text/javascript" src={Routes.static_path(@conn, "/assets/app.js")}></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<header>
|
||||||
|
<section class="container">
|
||||||
|
<nav>
|
||||||
|
<ul>
|
||||||
|
<li><a href="https://hexdocs.pm/phoenix/overview.html">Get Started</a></li>
|
||||||
|
<%= if function_exported?(Routes, :live_dashboard_path, 2) do %>
|
||||||
|
<li><%= link "LiveDashboard", to: Routes.live_dashboard_path(@conn, :home) %></li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
<a href="https://phoenixframework.org/" class="phx-logo">
|
||||||
|
<img src={Routes.static_path(@conn, "/images/phoenix.png")} alt="Phoenix Framework Logo"/>
|
||||||
|
</a>
|
||||||
|
</section>
|
||||||
|
</header>
|
||||||
|
<%= @inner_content %>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,41 @@
|
||||||
|
<section class="phx-hero">
|
||||||
|
<h1><%= gettext "Welcome to %{name}!", name: "Phoenix" %></h1>
|
||||||
|
<p>Peace of mind from prototype to production</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="row">
|
||||||
|
<article class="column">
|
||||||
|
<h2>Resources</h2>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<a href="https://hexdocs.pm/phoenix/overview.html">Guides & Docs</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="https://github.com/phoenixframework/phoenix">Source</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="https://github.com/phoenixframework/phoenix/blob/v1.6/CHANGELOG.md">v1.6 Changelog</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</article>
|
||||||
|
<article class="column">
|
||||||
|
<h2>Help</h2>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<a href="https://elixirforum.com/c/phoenix-forum">Forum</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="https://web.libera.chat/#elixir">#elixir on Libera Chat (IRC)</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="https://twitter.com/elixirphoenix">Twitter @elixirphoenix</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="https://elixir-slackin.herokuapp.com/">Elixir on Slack</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="https://discord.gg/elixir">Elixir on Discord</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</article>
|
||||||
|
</section>
|
|
@ -0,0 +1,60 @@
|
||||||
|
defmodule Diffuser.Uploaders.Image do
|
||||||
|
use Waffle.Definition
|
||||||
|
use Waffle.Ecto.Definition
|
||||||
|
|
||||||
|
# Include ecto support (requires package waffle_ecto installed):
|
||||||
|
# use Waffle.Ecto.Definition
|
||||||
|
|
||||||
|
@versions [:original]
|
||||||
|
|
||||||
|
# To add a thumbnail version:
|
||||||
|
# @versions [:original, :thumb]
|
||||||
|
|
||||||
|
# Override the bucket on a per definition basis:
|
||||||
|
# def bucket do
|
||||||
|
# :custom_bucket_name
|
||||||
|
# end
|
||||||
|
|
||||||
|
# def bucket({_file, scope}) do
|
||||||
|
# scope.bucket || bucket()
|
||||||
|
# end
|
||||||
|
|
||||||
|
# Whitelist file extensions:
|
||||||
|
# def validate({file, _}) do
|
||||||
|
# file_extension = file.file_name |> Path.extname() |> String.downcase()
|
||||||
|
#
|
||||||
|
# case Enum.member?(~w(.jpg .jpeg .gif .png), file_extension) do
|
||||||
|
# true -> :ok
|
||||||
|
# false -> {:error, "invalid file type"}
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
|
||||||
|
# Define a thumbnail transformation:
|
||||||
|
# def transform(:thumb, _) do
|
||||||
|
# {:convert, "-strip -thumbnail 250x250^ -gravity center -extent 250x250 -format png", :png}
|
||||||
|
# end
|
||||||
|
|
||||||
|
# Override the persisted filenames:
|
||||||
|
# def filename(version, _) do
|
||||||
|
# version
|
||||||
|
# end
|
||||||
|
|
||||||
|
# Override the storage directory:
|
||||||
|
# def storage_dir(version, {file, scope}) do
|
||||||
|
# "uploads/user/avatars/#{scope.id}"
|
||||||
|
# end
|
||||||
|
|
||||||
|
# Provide a default URL if there hasn't been a file uploaded
|
||||||
|
# def default_url(version, scope) do
|
||||||
|
# "/images/avatars/default_#{version}.png"
|
||||||
|
# end
|
||||||
|
|
||||||
|
# Specify custom headers for s3 objects
|
||||||
|
# Available options are [:cache_control, :content_disposition,
|
||||||
|
# :content_encoding, :content_length, :content_type,
|
||||||
|
# :expect, :expires, :storage_class, :website_redirect_location]
|
||||||
|
#
|
||||||
|
# def s3_object_headers(version, {file, scope}) do
|
||||||
|
# [content_type: MIME.from_path(file.file_name)]
|
||||||
|
# end
|
||||||
|
end
|
|
@ -0,0 +1,47 @@
|
||||||
|
defmodule DiffuserWeb.ErrorHelpers do
|
||||||
|
@moduledoc """
|
||||||
|
Conveniences for translating and building error messages.
|
||||||
|
"""
|
||||||
|
|
||||||
|
use Phoenix.HTML
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Generates tag for inlined form input errors.
|
||||||
|
"""
|
||||||
|
def error_tag(form, field) do
|
||||||
|
Enum.map(Keyword.get_values(form.errors, field), fn error ->
|
||||||
|
content_tag(:span, translate_error(error),
|
||||||
|
class: "invalid-feedback",
|
||||||
|
phx_feedback_for: input_name(form, field)
|
||||||
|
)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Translates an error message using gettext.
|
||||||
|
"""
|
||||||
|
def translate_error({msg, opts}) do
|
||||||
|
# When using gettext, we typically pass the strings we want
|
||||||
|
# to translate as a static argument:
|
||||||
|
#
|
||||||
|
# # Translate "is invalid" in the "errors" domain
|
||||||
|
# dgettext("errors", "is invalid")
|
||||||
|
#
|
||||||
|
# # Translate the number of files with plural rules
|
||||||
|
# dngettext("errors", "1 file", "%{count} files", count)
|
||||||
|
#
|
||||||
|
# Because the error messages we show in our forms and APIs
|
||||||
|
# are defined inside Ecto, we need to translate them dynamically.
|
||||||
|
# This requires us to call the Gettext module passing our gettext
|
||||||
|
# backend as first argument.
|
||||||
|
#
|
||||||
|
# Note we use the "errors" domain, which means translations
|
||||||
|
# should be written to the errors.po file. The :count option is
|
||||||
|
# set by Ecto and indicates we should also apply plural rules.
|
||||||
|
if count = opts[:count] do
|
||||||
|
Gettext.dngettext(DiffuserWeb.Gettext, "errors", msg, msg, count, opts)
|
||||||
|
else
|
||||||
|
Gettext.dgettext(DiffuserWeb.Gettext, "errors", msg, opts)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,16 @@
|
||||||
|
defmodule DiffuserWeb.ErrorView do
|
||||||
|
use DiffuserWeb, :view
|
||||||
|
|
||||||
|
# If you want to customize a particular status code
|
||||||
|
# for a certain format, you may uncomment below.
|
||||||
|
# def render("500.html", _assigns) do
|
||||||
|
# "Internal Server Error"
|
||||||
|
# end
|
||||||
|
|
||||||
|
# By default, Phoenix returns the status message from
|
||||||
|
# the template name. For example, "404.html" becomes
|
||||||
|
# "Not Found".
|
||||||
|
def template_not_found(template, _assigns) do
|
||||||
|
Phoenix.Controller.status_message_from_template(template)
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,7 @@
|
||||||
|
defmodule DiffuserWeb.LayoutView do
|
||||||
|
use DiffuserWeb, :view
|
||||||
|
|
||||||
|
# Phoenix LiveDashboard is available only in development by default,
|
||||||
|
# so we instruct Elixir to not warn if the dashboard route is missing.
|
||||||
|
@compile {:no_warn_undefined, {Routes, :live_dashboard_path, 2}}
|
||||||
|
end
|
|
@ -0,0 +1,3 @@
|
||||||
|
defmodule DiffuserWeb.PageView do
|
||||||
|
use DiffuserWeb, :view
|
||||||
|
end
|
|
@ -0,0 +1,74 @@
|
||||||
|
defmodule Diffuser.MixProject do
|
||||||
|
use Mix.Project
|
||||||
|
|
||||||
|
def project do
|
||||||
|
[
|
||||||
|
app: :diffuser,
|
||||||
|
version: "0.1.0",
|
||||||
|
elixir: "~> 1.12",
|
||||||
|
elixirc_paths: elixirc_paths(Mix.env()),
|
||||||
|
compilers: Mix.compilers(),
|
||||||
|
start_permanent: Mix.env() == :prod,
|
||||||
|
aliases: aliases(),
|
||||||
|
deps: deps()
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
# Configuration for the OTP application.
|
||||||
|
#
|
||||||
|
# Type `mix help compile.app` for more information.
|
||||||
|
def application do
|
||||||
|
[
|
||||||
|
mod: {Diffuser.Application, []},
|
||||||
|
extra_applications: [:logger, :runtime_tools, :inets]
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
# Specifies which paths to compile per environment.
|
||||||
|
defp elixirc_paths(:test), do: ["lib", "test/support"]
|
||||||
|
defp elixirc_paths(_), do: ["lib"]
|
||||||
|
|
||||||
|
# Specifies your project dependencies.
|
||||||
|
#
|
||||||
|
# Type `mix help deps` for examples and options.
|
||||||
|
defp deps do
|
||||||
|
[
|
||||||
|
{:phoenix, "~> 1.6.10"},
|
||||||
|
{:phoenix_ecto, "~> 4.4"},
|
||||||
|
{:ecto_sql, "~> 3.6"},
|
||||||
|
{:postgrex, ">= 0.0.0"},
|
||||||
|
{:phoenix_html, "~> 3.0"},
|
||||||
|
{:phoenix_live_reload, "~> 1.2", only: :dev},
|
||||||
|
{:phoenix_live_view, "~> 0.17.5"},
|
||||||
|
{:floki, ">= 0.30.0", only: :test},
|
||||||
|
{:phoenix_live_dashboard, "~> 0.6"},
|
||||||
|
{:esbuild, "~> 0.4", runtime: Mix.env() == :dev},
|
||||||
|
{:swoosh, "~> 1.3"},
|
||||||
|
{:telemetry_metrics, "~> 0.6"},
|
||||||
|
{:telemetry_poller, "~> 1.0"},
|
||||||
|
{:gettext, "~> 0.18"},
|
||||||
|
{:jason, "~> 1.2"},
|
||||||
|
{:plug_cowboy, "~> 2.5"},
|
||||||
|
# non phoenix default dependencies
|
||||||
|
{:erlport, "~> 0.10.1"},
|
||||||
|
{:waffle, "~> 1.1"},
|
||||||
|
{:waffle_ecto, "~> 0.0.11"}
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
# Aliases are shortcuts or tasks specific to the current project.
|
||||||
|
# For example, to install project dependencies and perform other setup tasks, run:
|
||||||
|
#
|
||||||
|
# $ mix setup
|
||||||
|
#
|
||||||
|
# See the documentation for `Mix` for more info on aliases.
|
||||||
|
defp aliases do
|
||||||
|
[
|
||||||
|
setup: ["deps.get", "ecto.setup"],
|
||||||
|
"ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
|
||||||
|
"ecto.reset": ["ecto.drop", "ecto.setup"],
|
||||||
|
test: ["ecto.create --quiet", "ecto.migrate --quiet", "test"],
|
||||||
|
"assets.deploy": ["esbuild default --minify", "phx.digest"]
|
||||||
|
]
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,46 @@
|
||||||
|
%{
|
||||||
|
"castore": {:hex, :castore, "0.1.18", "deb5b9ab02400561b6f5708f3e7660fc35ca2d51bfc6a940d2f513f89c2975fc", [:mix], [], "hexpm", "61bbaf6452b782ef80b33cdb45701afbcf0a918a45ebe7e73f1130d661e66a06"},
|
||||||
|
"certifi": {:hex, :certifi, "2.9.0", "6f2a475689dd47f19fb74334859d460a2dc4e3252a3324bd2111b8f0429e7e21", [:rebar3], [], "hexpm", "266da46bdb06d6c6d35fde799bcb28d36d985d424ad7c08b5bb48f5b5cdd4641"},
|
||||||
|
"connection": {:hex, :connection, "1.1.0", "ff2a49c4b75b6fb3e674bfc5536451607270aac754ffd1bdfe175abe4a6d7a68", [:mix], [], "hexpm", "722c1eb0a418fbe91ba7bd59a47e28008a189d47e37e0e7bb85585a016b2869c"},
|
||||||
|
"cowboy": {:hex, :cowboy, "2.9.0", "865dd8b6607e14cf03282e10e934023a1bd8be6f6bacf921a7e2a96d800cd452", [:make, :rebar3], [{:cowlib, "2.11.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "2c729f934b4e1aa149aff882f57c6372c15399a20d54f65c8d67bef583021bde"},
|
||||||
|
"cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"},
|
||||||
|
"cowlib": {:hex, :cowlib, "2.11.0", "0b9ff9c346629256c42ebe1eeb769a83c6cb771a6ee5960bd110ab0b9b872063", [:make, :rebar3], [], "hexpm", "2b3e9da0b21c4565751a6d4901c20d1b4cc25cbb7fd50d91d2ab6dd287bc86a9"},
|
||||||
|
"db_connection": {:hex, :db_connection, "2.4.2", "f92e79aff2375299a16bcb069a14ee8615c3414863a6fef93156aee8e86c2ff3", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "4fe53ca91b99f55ea249693a0229356a08f4d1a7931d8ffa79289b145fe83668"},
|
||||||
|
"decimal": {:hex, :decimal, "2.0.0", "a78296e617b0f5dd4c6caf57c714431347912ffb1d0842e998e9792b5642d697", [:mix], [], "hexpm", "34666e9c55dea81013e77d9d87370fe6cb6291d1ef32f46a1600230b1d44f577"},
|
||||||
|
"ecto": {:hex, :ecto, "3.8.4", "e06b8b87e62b27fea17fd2ff6041572ddd10339fd16cdf58446e402c6c90a74b", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "f9244288b8d42db40515463a008cf3f4e0e564bb9c249fe87bf28a6d79fe82d4"},
|
||||||
|
"ecto_sql": {:hex, :ecto_sql, "3.8.3", "a7d22c624202546a39d615ed7a6b784580391e65723f2d24f65941b4dd73d471", [:mix], [{:db_connection, "~> 2.5 or ~> 2.4.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.8.4", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.6.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0 or ~> 0.16.0 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "348cb17fb9e6daf6f251a87049eafcb57805e2892e5e6a0f5dea0985d367329b"},
|
||||||
|
"erlport": {:hex, :erlport, "0.10.1", "c96ffa51bbcab0298232fcdfe8c3e110f1598011de71ae6b9082b80c9e2e476a", [:rebar3], [], "hexpm", "34931e8cb62a131d1bc8a2bd04d4007c73c03e4f10e22ee4a218e7172227a918"},
|
||||||
|
"esbuild": {:hex, :esbuild, "0.5.0", "d5bb08ff049d7880ee3609ed5c4b864bd2f46445ea40b16b4acead724fb4c4a3", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}], "hexpm", "f183a0b332d963c4cfaf585477695ea59eef9a6f2204fdd0efa00e099694ffe5"},
|
||||||
|
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
|
||||||
|
"floki": {:hex, :floki, "0.33.1", "f20f1eb471e726342b45ccb68edb9486729e7df94da403936ea94a794f072781", [:mix], [{:html_entities, "~> 0.5.0", [hex: :html_entities, repo: "hexpm", optional: false]}], "hexpm", "461035fd125f13fdf30f243c85a0b1e50afbec876cbf1ceefe6fddd2e6d712c6"},
|
||||||
|
"gettext": {:hex, :gettext, "0.20.0", "75ad71de05f2ef56991dbae224d35c68b098dd0e26918def5bb45591d5c8d429", [:mix], [], "hexpm", "1c03b177435e93a47441d7f681a7040bd2a816ece9e2666d1c9001035121eb3d"},
|
||||||
|
"hackney": {:hex, :hackney, "1.18.1", "f48bf88f521f2a229fc7bae88cf4f85adc9cd9bcf23b5dc8eb6a1788c662c4f6", [:rebar3], [{:certifi, "~>2.9.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~>6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~>1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.3.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~>1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "a4ecdaff44297e9b5894ae499e9a070ea1888c84afdd1fd9b7b2bc384950128e"},
|
||||||
|
"html_entities": {:hex, :html_entities, "0.5.2", "9e47e70598da7de2a9ff6af8758399251db6dbb7eebe2b013f2bbd2515895c3c", [:mix], [], "hexpm", "c53ba390403485615623b9531e97696f076ed415e8d8058b1dbaa28181f4fdcc"},
|
||||||
|
"idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"},
|
||||||
|
"jason": {:hex, :jason, "1.3.0", "fa6b82a934feb176263ad2df0dbd91bf633d4a46ebfdffea0c8ae82953714946", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "53fc1f51255390e0ec7e50f9cb41e751c260d065dcba2bf0d08dc51a4002c2ac"},
|
||||||
|
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"},
|
||||||
|
"mime": {:hex, :mime, "2.0.3", "3676436d3d1f7b81b5a2d2bd8405f412c677558c81b1c92be58c00562bb59095", [:mix], [], "hexpm", "27a30bf0db44d25eecba73755acf4068cbfe26a4372f9eb3e4ea3a45956bff6b"},
|
||||||
|
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"},
|
||||||
|
"parse_trans": {:hex, :parse_trans, "3.3.1", "16328ab840cc09919bd10dab29e431da3af9e9e7e7e6f0089dd5a2d2820011d8", [:rebar3], [], "hexpm", "07cd9577885f56362d414e8c4c4e6bdf10d43a8767abb92d24cbe8b24c54888b"},
|
||||||
|
"phoenix": {:hex, :phoenix, "1.6.11", "29f3c0fd12fa1fc4d4b05e341578e55bc78d96ea83a022587a7e276884d397e4", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 1.0", [hex: :phoenix_view, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "1664e34f80c25ea4918fbadd957f491225ef601c0e00b4e644b1a772864bfbc2"},
|
||||||
|
"phoenix_ecto": {:hex, :phoenix_ecto, "4.4.0", "0672ed4e4808b3fbed494dded89958e22fb882de47a97634c0b13e7b0b5f7720", [:mix], [{:ecto, "~> 3.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "09864e558ed31ee00bd48fcc1d4fc58ae9678c9e81649075431e69dbabb43cc1"},
|
||||||
|
"phoenix_html": {:hex, :phoenix_html, "3.2.0", "1c1219d4b6cb22ac72f12f73dc5fad6c7563104d083f711c3fcd8551a1f4ae11", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "36ec97ba56d25c0136ef1992c37957e4246b649d620958a1f9fa86165f8bc54f"},
|
||||||
|
"phoenix_live_dashboard": {:hex, :phoenix_live_dashboard, "0.6.5", "1495bb014be12c9a9252eca04b9af54246f6b5c1e4cd1f30210cd00ec540cf8e", [:mix], [{:ecto, "~> 3.6.2 or ~> 3.7", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_mysql_extras, "~> 0.3", [hex: :ecto_mysql_extras, repo: "hexpm", optional: true]}, {:ecto_psql_extras, "~> 0.7", [hex: :ecto_psql_extras, repo: "hexpm", optional: true]}, {:mime, "~> 1.6 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 0.17.7", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:telemetry_metrics, "~> 0.6.0", [hex: :telemetry_metrics, repo: "hexpm", optional: false]}], "hexpm", "ef4fa50dd78364409039c99cf6f98ab5209b4c5f8796c17f4db118324f0db852"},
|
||||||
|
"phoenix_live_reload": {:hex, :phoenix_live_reload, "1.3.3", "3a53772a6118d5679bf50fc1670505a290e32a1d195df9e069d8c53ab040c054", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm", "766796676e5f558dbae5d1bdb066849673e956005e3730dfd5affd7a6da4abac"},
|
||||||
|
"phoenix_live_view": {:hex, :phoenix_live_view, "0.17.11", "205f6aa5405648c76f2abcd57716f42fc07d8f21dd8ea7b262dd12b324b50c95", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.6.0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 3.1", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7177791944b7f90ed18f5935a6a5f07f760b36f7b3bdfb9d28c57440a3c43f99"},
|
||||||
|
"phoenix_pubsub": {:hex, :phoenix_pubsub, "2.1.1", "ba04e489ef03763bf28a17eb2eaddc2c20c6d217e2150a61e3298b0f4c2012b5", [:mix], [], "hexpm", "81367c6d1eea5878ad726be80808eb5a787a23dee699f96e72b1109c57cdd8d9"},
|
||||||
|
"phoenix_view": {:hex, :phoenix_view, "1.1.2", "1b82764a065fb41051637872c7bd07ed2fdb6f5c3bd89684d4dca6e10115c95a", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "7ae90ad27b09091266f6adbb61e1d2516a7c3d7062c6789d46a7554ec40f3a56"},
|
||||||
|
"plug": {:hex, :plug, "1.13.6", "187beb6b67c6cec50503e940f0434ea4692b19384d47e5fdfd701e93cadb4cc2", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "02b9c6b9955bce92c829f31d6284bf53c591ca63c4fb9ff81dfd0418667a34ff"},
|
||||||
|
"plug_cowboy": {:hex, :plug_cowboy, "2.5.2", "62894ccd601cf9597e2c23911ff12798a8a18d237e9739f58a6b04e4988899fe", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "ea6e87f774c8608d60c8d34022a7d073bd7680a0a013f049fc62bf35efea1044"},
|
||||||
|
"plug_crypto": {:hex, :plug_crypto, "1.2.3", "8f77d13aeb32bfd9e654cb68f0af517b371fb34c56c9f2b58fe3df1235c1251a", [:mix], [], "hexpm", "b5672099c6ad5c202c45f5a403f21a3411247f164e4a8fab056e5cd8a290f4a2"},
|
||||||
|
"postgrex": {:hex, :postgrex, "0.16.4", "26d998467b4a22252285e728a29d341e08403d084e44674784975bb1cd00d2cb", [:mix], [{:connection, "~> 1.1", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "3234d1a70cb7b1e0c95d2e242785ec2a7a94a092bbcef4472320b950cfd64c5f"},
|
||||||
|
"ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"},
|
||||||
|
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"},
|
||||||
|
"swoosh": {:hex, :swoosh, "1.7.4", "f967d9b2659e81bab241b96267aae1001d35c2beea2df9c03dcf47b007bf566f", [:mix], [{:cowboy, "~> 1.1 or ~> 2.4", [hex: :cowboy, repo: "hexpm", optional: true]}, {:ex_aws, "~> 2.1", [hex: :ex_aws, repo: "hexpm", optional: true]}, {:finch, "~> 0.6", [hex: :finch, repo: "hexpm", optional: true]}, {:gen_smtp, "~> 0.13 or ~> 1.0", [hex: :gen_smtp, repo: "hexpm", optional: true]}, {:hackney, "~> 1.9", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mail, "~> 0.2", [hex: :mail, repo: "hexpm", optional: true]}, {:mime, "~> 1.1 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_cowboy, ">= 1.0.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "1553d994b4cf069162965e63de1e1c53d8236e127118d21e56ce2abeaa3f25b4"},
|
||||||
|
"telemetry": {:hex, :telemetry, "1.1.0", "a589817034a27eab11144ad24d5c0f9fab1f58173274b1e9bae7074af9cbee51", [:rebar3], [], "hexpm", "b727b2a1f75614774cff2d7565b64d0dfa5bd52ba517f16543e6fc7efcc0df48"},
|
||||||
|
"telemetry_metrics": {:hex, :telemetry_metrics, "0.6.1", "315d9163a1d4660aedc3fee73f33f1d355dcc76c5c3ab3d59e76e3edf80eef1f", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7be9e0871c41732c233be71e4be11b96e56177bf15dde64a8ac9ce72ac9834c6"},
|
||||||
|
"telemetry_poller": {:hex, :telemetry_poller, "1.0.0", "db91bb424e07f2bb6e73926fcafbfcbcb295f0193e0a00e825e589a0a47e8453", [:rebar3], [{:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "b3a24eafd66c3f42da30fc3ca7dda1e9d546c12250a2d60d7b81d264fbec4f6e"},
|
||||||
|
"unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"},
|
||||||
|
"waffle": {:hex, :waffle, "1.1.6", "e944b31f8a3f3b15b8ce5c6ca315cecbcbfab354c2bb83f5980c79728cf422c0", [:mix], [{:ex_aws, "~> 2.1", [hex: :ex_aws, repo: "hexpm", optional: true]}, {:ex_aws_s3, "~> 2.1", [hex: :ex_aws_s3, repo: "hexpm", optional: true]}, {:hackney, "~> 1.9", [hex: :hackney, repo: "hexpm", optional: false]}, {:sweet_xml, "~> 0.6", [hex: :sweet_xml, repo: "hexpm", optional: true]}], "hexpm", "deecbf205acc5b6d0bc23d3813fa384486606a50d82b803edbd29e2a46258d4d"},
|
||||||
|
"waffle_ecto": {:hex, :waffle_ecto, "0.0.11", "3d9581b3dfc83964ad968ef6bbf31132b5e6959c542a74c49e2a2245a9521048", [:mix], [{:ecto, "~> 3.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:waffle, "~> 1.0", [hex: :waffle, repo: "hexpm", optional: false]}], "hexpm", "626c2832ba94e20840532e609d3af70526d18ff9dfe1b352afb3fbabedb31a7e"},
|
||||||
|
}
|
|
@ -0,0 +1,112 @@
|
||||||
|
## `msgid`s in this file come from POT (.pot) files.
|
||||||
|
##
|
||||||
|
## Do not add, change, or remove `msgid`s manually here as
|
||||||
|
## they're tied to the ones in the corresponding POT file
|
||||||
|
## (with the same domain).
|
||||||
|
##
|
||||||
|
## Use `mix gettext.extract --merge` or `mix gettext.merge`
|
||||||
|
## to merge POT files into PO files.
|
||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Language: en\n"
|
||||||
|
|
||||||
|
## From Ecto.Changeset.cast/4
|
||||||
|
msgid "can't be blank"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.unique_constraint/3
|
||||||
|
msgid "has already been taken"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.put_change/3
|
||||||
|
msgid "is invalid"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.validate_acceptance/3
|
||||||
|
msgid "must be accepted"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.validate_format/3
|
||||||
|
msgid "has invalid format"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.validate_subset/3
|
||||||
|
msgid "has an invalid entry"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.validate_exclusion/3
|
||||||
|
msgid "is reserved"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.validate_confirmation/3
|
||||||
|
msgid "does not match confirmation"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.no_assoc_constraint/3
|
||||||
|
msgid "is still associated with this entry"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "are still associated with this entry"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.validate_length/3
|
||||||
|
msgid "should have %{count} item(s)"
|
||||||
|
msgid_plural "should have %{count} item(s)"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
|
msgid "should be %{count} character(s)"
|
||||||
|
msgid_plural "should be %{count} character(s)"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
|
msgid "should be %{count} byte(s)"
|
||||||
|
msgid_plural "should be %{count} byte(s)"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
|
msgid "should have at least %{count} item(s)"
|
||||||
|
msgid_plural "should have at least %{count} item(s)"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
|
msgid "should be at least %{count} character(s)"
|
||||||
|
msgid_plural "should be at least %{count} character(s)"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
|
msgid "should be at least %{count} byte(s)"
|
||||||
|
msgid_plural "should be at least %{count} byte(s)"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
|
msgid "should have at most %{count} item(s)"
|
||||||
|
msgid_plural "should have at most %{count} item(s)"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
|
msgid "should be at most %{count} character(s)"
|
||||||
|
msgid_plural "should be at most %{count} character(s)"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
|
msgid "should be at most %{count} byte(s)"
|
||||||
|
msgid_plural "should be at most %{count} byte(s)"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.validate_number/3
|
||||||
|
msgid "must be less than %{number}"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "must be greater than %{number}"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "must be less than or equal to %{number}"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "must be greater than or equal to %{number}"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "must be equal to %{number}"
|
||||||
|
msgstr ""
|
|
@ -0,0 +1,95 @@
|
||||||
|
## This is a PO Template file.
|
||||||
|
##
|
||||||
|
## `msgid`s here are often extracted from source code.
|
||||||
|
## Add new translations manually only if they're dynamic
|
||||||
|
## translations that can't be statically extracted.
|
||||||
|
##
|
||||||
|
## Run `mix gettext.extract` to bring this file up to
|
||||||
|
## date. Leave `msgstr`s empty as changing them here has no
|
||||||
|
## effect: edit them in PO (`.po`) files instead.
|
||||||
|
|
||||||
|
## From Ecto.Changeset.cast/4
|
||||||
|
msgid "can't be blank"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.unique_constraint/3
|
||||||
|
msgid "has already been taken"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.put_change/3
|
||||||
|
msgid "is invalid"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.validate_acceptance/3
|
||||||
|
msgid "must be accepted"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.validate_format/3
|
||||||
|
msgid "has invalid format"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.validate_subset/3
|
||||||
|
msgid "has an invalid entry"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.validate_exclusion/3
|
||||||
|
msgid "is reserved"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.validate_confirmation/3
|
||||||
|
msgid "does not match confirmation"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.no_assoc_constraint/3
|
||||||
|
msgid "is still associated with this entry"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "are still associated with this entry"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.validate_length/3
|
||||||
|
msgid "should be %{count} character(s)"
|
||||||
|
msgid_plural "should be %{count} character(s)"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
|
msgid "should have %{count} item(s)"
|
||||||
|
msgid_plural "should have %{count} item(s)"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
|
msgid "should be at least %{count} character(s)"
|
||||||
|
msgid_plural "should be at least %{count} character(s)"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
|
msgid "should have at least %{count} item(s)"
|
||||||
|
msgid_plural "should have at least %{count} item(s)"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
|
msgid "should be at most %{count} character(s)"
|
||||||
|
msgid_plural "should be at most %{count} character(s)"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
|
msgid "should have at most %{count} item(s)"
|
||||||
|
msgid_plural "should have at most %{count} item(s)"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.validate_number/3
|
||||||
|
msgid "must be less than %{number}"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "must be greater than %{number}"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "must be less than or equal to %{number}"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "must be greater than or equal to %{number}"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "must be equal to %{number}"
|
||||||
|
msgstr ""
|
|
@ -0,0 +1,4 @@
|
||||||
|
[
|
||||||
|
import_deps: [:ecto_sql],
|
||||||
|
inputs: ["*.exs"]
|
||||||
|
]
|
|
@ -0,0 +1,13 @@
|
||||||
|
defmodule Diffuser.Repo.Migrations.CreatePromptRequests do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def change do
|
||||||
|
create table(:prompt_requests, primary_key: false) do
|
||||||
|
add :id, :uuid, primary_key: true, null: false
|
||||||
|
|
||||||
|
add :prompt, :string
|
||||||
|
|
||||||
|
timestamps()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,9 @@
|
||||||
|
defmodule Diffuser.Repo.Migrations.AddStatusToPromptRequest do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def change do
|
||||||
|
alter table(:prompt_requests) do
|
||||||
|
add :status, :string
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,13 @@
|
||||||
|
defmodule Diffuser.Repo.Migrations.CreatePromptRequestResult do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def change do
|
||||||
|
create table(:prompt_request_results, primary_key: false) do
|
||||||
|
add :id, :uuid, primary_key: true, null: false
|
||||||
|
add :image, :string
|
||||||
|
add :prompt_request_id, references(:prompt_requests, type: :uuid)
|
||||||
|
|
||||||
|
timestamps()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,11 @@
|
||||||
|
# Script for populating the database. You can run it as:
|
||||||
|
#
|
||||||
|
# mix run priv/repo/seeds.exs
|
||||||
|
#
|
||||||
|
# Inside the script, you can read and write to any of your
|
||||||
|
# repositories directly:
|
||||||
|
#
|
||||||
|
# Diffuser.Repo.insert!(%Diffuser.SomeSchema{})
|
||||||
|
#
|
||||||
|
# We recommend using the bang functions (`insert!`, `update!`
|
||||||
|
# and so on) as they will fail if something goes wrong.
|
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
|
@ -0,0 +1,5 @@
|
||||||
|
# See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
|
||||||
|
#
|
||||||
|
# To ban all spiders from the entire site uncomment the next two lines:
|
||||||
|
# User-agent: *
|
||||||
|
# Disallow: /
|
|
@ -0,0 +1,48 @@
|
||||||
|
defmodule Diffuser.Generator.PromptRequestTest do
|
||||||
|
use Diffuser.DataCase
|
||||||
|
import Diffuser.GeneratorFixtures
|
||||||
|
alias Diffuser.Generator
|
||||||
|
alias Diffuser.Generator.PromptRequest
|
||||||
|
alias DiffuserWeb.Endpoint
|
||||||
|
|
||||||
|
import Phoenix.ChannelTest
|
||||||
|
|
||||||
|
# The default endpoint for testing
|
||||||
|
# @endpoint DiffuserWeb.Endpoint
|
||||||
|
|
||||||
|
# TODO: Write mock that calls python script that only sleeps for 300 milliseconds
|
||||||
|
test "starts a new prompt and can query status while it's running" do
|
||||||
|
prompt_request = prompt_request_fixture()
|
||||||
|
|
||||||
|
assert {:ok, _pid} =
|
||||||
|
Diffuser.Generator.PromptRequestGenserver.new(%{prompt_request: prompt_request})
|
||||||
|
|
||||||
|
:timer.sleep(1000)
|
||||||
|
|
||||||
|
assert %{status: "in_progress"} = Generator.get_prompt_request!(prompt_request.id)
|
||||||
|
|
||||||
|
:timer.sleep(3000)
|
||||||
|
|
||||||
|
assert %{status: "finished"} = Diffuser.Generator.get_prompt_request!(prompt_request.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "properly updates when prompt is finished via websocket" do
|
||||||
|
%{id: id} = prompt_request = prompt_request_fixture()
|
||||||
|
|
||||||
|
Endpoint.subscribe("request:#{id}")
|
||||||
|
|
||||||
|
Diffuser.Generator.PromptRequestGenserver.new(%{prompt_request: prompt_request})
|
||||||
|
|
||||||
|
:timer.sleep(1000)
|
||||||
|
|
||||||
|
assert_broadcast("request", %{
|
||||||
|
prompt_request: %PromptRequest{id: ^id}
|
||||||
|
})
|
||||||
|
|
||||||
|
:timer.sleep(3000)
|
||||||
|
|
||||||
|
assert_broadcast("request", %{
|
||||||
|
prompt_request: %PromptRequest{id: ^id}
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,92 @@
|
||||||
|
defmodule Diffuser.GeneratorTest do
|
||||||
|
use Diffuser.DataCase
|
||||||
|
|
||||||
|
alias Diffuser.Generator
|
||||||
|
alias Diffuser.Test.FileHelper
|
||||||
|
alias Diffuser.Repo
|
||||||
|
|
||||||
|
describe "prompt_requests" do
|
||||||
|
alias Diffuser.Generator.PromptRequest
|
||||||
|
|
||||||
|
import Diffuser.GeneratorFixtures
|
||||||
|
|
||||||
|
@invalid_attrs %{prompt: nil}
|
||||||
|
|
||||||
|
test "list_prompt_requests/0 returns all prompt_requests" do
|
||||||
|
prompt_request = prompt_request_fixture()
|
||||||
|
assert Generator.list_prompt_requests() == [prompt_request]
|
||||||
|
end
|
||||||
|
|
||||||
|
test "get_prompt_request!/1 returns the prompt_request with given id" do
|
||||||
|
prompt_request = prompt_request_fixture()
|
||||||
|
assert Generator.get_prompt_request!(prompt_request.id) == prompt_request
|
||||||
|
end
|
||||||
|
|
||||||
|
test "create_prompt_request/1 with valid data creates a prompt_request" do
|
||||||
|
valid_attrs = %{prompt: "some prompt"}
|
||||||
|
|
||||||
|
assert {:ok, %PromptRequest{} = prompt_request} =
|
||||||
|
Generator.create_prompt_request(valid_attrs)
|
||||||
|
|
||||||
|
assert prompt_request.prompt == "some prompt"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "create_prompt_request/1 with invalid data returns error changeset" do
|
||||||
|
assert {:error, %Ecto.Changeset{}} = Generator.create_prompt_request(@invalid_attrs)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "update_prompt_request/2 with valid data updates the prompt_request" do
|
||||||
|
prompt_request = prompt_request_fixture()
|
||||||
|
|
||||||
|
update_attrs = %{
|
||||||
|
prompt: "some updated prompt"
|
||||||
|
}
|
||||||
|
|
||||||
|
assert {:ok, %PromptRequest{} = prompt_request} =
|
||||||
|
Generator.update_prompt_request(prompt_request, update_attrs)
|
||||||
|
|
||||||
|
assert prompt_request.prompt == "some updated prompt"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "update_prompt_request/2 with invalid data returns error changeset" do
|
||||||
|
prompt_request = prompt_request_fixture()
|
||||||
|
|
||||||
|
assert {:error, %Ecto.Changeset{}} =
|
||||||
|
Generator.update_prompt_request(prompt_request, @invalid_attrs)
|
||||||
|
|
||||||
|
assert prompt_request == Generator.get_prompt_request!(prompt_request.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "delete_prompt_request/1 deletes the prompt_request" do
|
||||||
|
prompt_request = prompt_request_fixture()
|
||||||
|
assert {:ok, %PromptRequest{}} = Generator.delete_prompt_request(prompt_request)
|
||||||
|
assert_raise Ecto.NoResultsError, fn -> Generator.get_prompt_request!(prompt_request.id) end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "change_prompt_request/1 returns a prompt_request changeset" do
|
||||||
|
prompt_request = prompt_request_fixture()
|
||||||
|
assert %Ecto.Changeset{} = Generator.change_prompt_request(prompt_request)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "begin_prompt_request/1 returns pid of a prompt request generator" do
|
||||||
|
prompt_request = prompt_request_fixture()
|
||||||
|
assert {:ok, _pid} = Generator.begin_prompt_request(prompt_request)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "create_prompt_request_results/2 properly associates images to prompt request" do
|
||||||
|
%{id: prompt_request_id} = prompt_request_fixture()
|
||||||
|
|
||||||
|
images = [
|
||||||
|
%{file_name: "cat.jpg", binary: FileHelper.binary_image()},
|
||||||
|
%{file_name: "dog.jpg", binary: FileHelper.binary_image()},
|
||||||
|
%{file_name: "horse.jpg", binary: FileHelper.binary_image()}
|
||||||
|
]
|
||||||
|
|
||||||
|
Generator.create_prompt_request_results(prompt_request_id, images)
|
||||||
|
|
||||||
|
%PromptRequest{images: images} = Generator.get_prompt_request!(prompt_request_id)
|
||||||
|
assert images |> length() > 0
|
||||||
|
# assert images |> Enum.all?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,8 @@
|
||||||
|
defmodule DiffuserWeb.PageControllerTest do
|
||||||
|
use DiffuserWeb.ConnCase
|
||||||
|
|
||||||
|
test "GET /", %{conn: conn} do
|
||||||
|
conn = get(conn, "/")
|
||||||
|
assert html_response(conn, 200) =~ "Welcome to Phoenix!"
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,110 @@
|
||||||
|
defmodule DiffuserWeb.PromptRequestLiveTest do
|
||||||
|
use DiffuserWeb.ConnCase
|
||||||
|
|
||||||
|
import Phoenix.LiveViewTest
|
||||||
|
import Diffuser.GeneratorFixtures
|
||||||
|
|
||||||
|
@create_attrs %{prompt: "some prompt"}
|
||||||
|
@update_attrs %{prompt: "some updated prompt"}
|
||||||
|
@invalid_attrs %{prompt: nil}
|
||||||
|
|
||||||
|
defp create_prompt_request(_) do
|
||||||
|
prompt_request = prompt_request_fixture()
|
||||||
|
%{prompt_request: prompt_request}
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "Index" do
|
||||||
|
setup [:create_prompt_request]
|
||||||
|
|
||||||
|
test "lists all prompt_requests", %{conn: conn, prompt_request: prompt_request} do
|
||||||
|
{:ok, _index_live, html} = live(conn, Routes.prompt_request_index_path(conn, :index))
|
||||||
|
|
||||||
|
assert html =~ "Listing Prompt requests"
|
||||||
|
assert html =~ prompt_request.prompt
|
||||||
|
end
|
||||||
|
|
||||||
|
test "saves new prompt_request", %{conn: conn} do
|
||||||
|
{:ok, index_live, _html} = live(conn, Routes.prompt_request_index_path(conn, :index))
|
||||||
|
|
||||||
|
assert index_live |> element("a", "New Prompt request") |> render_click() =~
|
||||||
|
"New Prompt request"
|
||||||
|
|
||||||
|
assert_patch(index_live, Routes.prompt_request_index_path(conn, :new))
|
||||||
|
|
||||||
|
assert index_live
|
||||||
|
|> form("#prompt_request-form", prompt_request: @invalid_attrs)
|
||||||
|
|> render_change() =~ "can't be blank"
|
||||||
|
|
||||||
|
{:ok, _, html} =
|
||||||
|
index_live
|
||||||
|
|> form("#prompt_request-form", prompt_request: @create_attrs)
|
||||||
|
|> render_submit()
|
||||||
|
|> follow_redirect(conn, Routes.prompt_request_index_path(conn, :index))
|
||||||
|
|
||||||
|
assert html =~ "Prompt request created successfully"
|
||||||
|
assert html =~ "some prompt"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "updates prompt_request in listing", %{conn: conn, prompt_request: prompt_request} do
|
||||||
|
{:ok, index_live, _html} = live(conn, Routes.prompt_request_index_path(conn, :index))
|
||||||
|
|
||||||
|
assert index_live |> element("#prompt_request-#{prompt_request.id} a", "Edit") |> render_click() =~
|
||||||
|
"Edit Prompt request"
|
||||||
|
|
||||||
|
assert_patch(index_live, Routes.prompt_request_index_path(conn, :edit, prompt_request))
|
||||||
|
|
||||||
|
assert index_live
|
||||||
|
|> form("#prompt_request-form", prompt_request: @invalid_attrs)
|
||||||
|
|> render_change() =~ "can't be blank"
|
||||||
|
|
||||||
|
{:ok, _, html} =
|
||||||
|
index_live
|
||||||
|
|> form("#prompt_request-form", prompt_request: @update_attrs)
|
||||||
|
|> render_submit()
|
||||||
|
|> follow_redirect(conn, Routes.prompt_request_index_path(conn, :index))
|
||||||
|
|
||||||
|
assert html =~ "Prompt request updated successfully"
|
||||||
|
assert html =~ "some updated prompt"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "deletes prompt_request in listing", %{conn: conn, prompt_request: prompt_request} do
|
||||||
|
{:ok, index_live, _html} = live(conn, Routes.prompt_request_index_path(conn, :index))
|
||||||
|
|
||||||
|
assert index_live |> element("#prompt_request-#{prompt_request.id} a", "Delete") |> render_click()
|
||||||
|
refute has_element?(index_live, "#prompt_request-#{prompt_request.id}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "Show" do
|
||||||
|
setup [:create_prompt_request]
|
||||||
|
|
||||||
|
test "displays prompt_request", %{conn: conn, prompt_request: prompt_request} do
|
||||||
|
{:ok, _show_live, html} = live(conn, Routes.prompt_request_show_path(conn, :show, prompt_request))
|
||||||
|
|
||||||
|
assert html =~ "Show Prompt request"
|
||||||
|
assert html =~ prompt_request.prompt
|
||||||
|
end
|
||||||
|
|
||||||
|
test "updates prompt_request within modal", %{conn: conn, prompt_request: prompt_request} do
|
||||||
|
{:ok, show_live, _html} = live(conn, Routes.prompt_request_show_path(conn, :show, prompt_request))
|
||||||
|
|
||||||
|
assert show_live |> element("a", "Edit") |> render_click() =~
|
||||||
|
"Edit Prompt request"
|
||||||
|
|
||||||
|
assert_patch(show_live, Routes.prompt_request_show_path(conn, :edit, prompt_request))
|
||||||
|
|
||||||
|
assert show_live
|
||||||
|
|> form("#prompt_request-form", prompt_request: @invalid_attrs)
|
||||||
|
|> render_change() =~ "can't be blank"
|
||||||
|
|
||||||
|
{:ok, _, html} =
|
||||||
|
show_live
|
||||||
|
|> form("#prompt_request-form", prompt_request: @update_attrs)
|
||||||
|
|> render_submit()
|
||||||
|
|> follow_redirect(conn, Routes.prompt_request_show_path(conn, :show, prompt_request))
|
||||||
|
|
||||||
|
assert html =~ "Prompt request updated successfully"
|
||||||
|
assert html =~ "some updated prompt"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,14 @@
|
||||||
|
defmodule DiffuserWeb.ErrorViewTest do
|
||||||
|
use DiffuserWeb.ConnCase, async: true
|
||||||
|
|
||||||
|
# Bring render/3 and render_to_string/3 for testing custom views
|
||||||
|
import Phoenix.View
|
||||||
|
|
||||||
|
test "renders 404.html" do
|
||||||
|
assert render_to_string(DiffuserWeb.ErrorView, "404.html", []) == "Not Found"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "renders 500.html" do
|
||||||
|
assert render_to_string(DiffuserWeb.ErrorView, "500.html", []) == "Internal Server Error"
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,8 @@
|
||||||
|
defmodule DiffuserWeb.LayoutViewTest do
|
||||||
|
use DiffuserWeb.ConnCase, async: true
|
||||||
|
|
||||||
|
# When testing helpers, you may want to import Phoenix.HTML and
|
||||||
|
# use functions such as safe_to_string() to convert the helper
|
||||||
|
# result into an HTML string.
|
||||||
|
# import Phoenix.HTML
|
||||||
|
end
|
|
@ -0,0 +1,3 @@
|
||||||
|
defmodule DiffuserWeb.PageViewTest do
|
||||||
|
use DiffuserWeb.ConnCase, async: true
|
||||||
|
end
|
Binary file not shown.
After Width: | Height: | Size: 6.4 KiB |
|
@ -0,0 +1,38 @@
|
||||||
|
defmodule DiffuserWeb.ConnCase do
|
||||||
|
@moduledoc """
|
||||||
|
This module defines the test case to be used by
|
||||||
|
tests that require setting up a connection.
|
||||||
|
|
||||||
|
Such tests rely on `Phoenix.ConnTest` and also
|
||||||
|
import other functionality to make it easier
|
||||||
|
to build common data structures and query the data layer.
|
||||||
|
|
||||||
|
Finally, if the test case interacts with the database,
|
||||||
|
we enable the SQL sandbox, so changes done to the database
|
||||||
|
are reverted at the end of every test. If you are using
|
||||||
|
PostgreSQL, you can even run database tests asynchronously
|
||||||
|
by setting `use DiffuserWeb.ConnCase, async: true`, although
|
||||||
|
this option is not recommended for other databases.
|
||||||
|
"""
|
||||||
|
|
||||||
|
use ExUnit.CaseTemplate
|
||||||
|
|
||||||
|
using do
|
||||||
|
quote do
|
||||||
|
# Import conveniences for testing with connections
|
||||||
|
import Plug.Conn
|
||||||
|
import Phoenix.ConnTest
|
||||||
|
import DiffuserWeb.ConnCase
|
||||||
|
|
||||||
|
alias DiffuserWeb.Router.Helpers, as: Routes
|
||||||
|
|
||||||
|
# The default endpoint for testing
|
||||||
|
@endpoint DiffuserWeb.Endpoint
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
setup tags do
|
||||||
|
Diffuser.DataCase.setup_sandbox(tags)
|
||||||
|
{:ok, conn: Phoenix.ConnTest.build_conn()}
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,58 @@
|
||||||
|
defmodule Diffuser.DataCase do
|
||||||
|
@moduledoc """
|
||||||
|
This module defines the setup for tests requiring
|
||||||
|
access to the application's data layer.
|
||||||
|
|
||||||
|
You may define functions here to be used as helpers in
|
||||||
|
your tests.
|
||||||
|
|
||||||
|
Finally, if the test case interacts with the database,
|
||||||
|
we enable the SQL sandbox, so changes done to the database
|
||||||
|
are reverted at the end of every test. If you are using
|
||||||
|
PostgreSQL, you can even run database tests asynchronously
|
||||||
|
by setting `use Diffuser.DataCase, async: true`, although
|
||||||
|
this option is not recommended for other databases.
|
||||||
|
"""
|
||||||
|
|
||||||
|
use ExUnit.CaseTemplate
|
||||||
|
|
||||||
|
using do
|
||||||
|
quote do
|
||||||
|
alias Diffuser.Repo
|
||||||
|
|
||||||
|
import Ecto
|
||||||
|
import Ecto.Changeset
|
||||||
|
import Ecto.Query
|
||||||
|
import Diffuser.DataCase
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
setup tags do
|
||||||
|
Diffuser.DataCase.setup_sandbox(tags)
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Sets up the sandbox based on the test tags.
|
||||||
|
"""
|
||||||
|
def setup_sandbox(tags) do
|
||||||
|
pid = Ecto.Adapters.SQL.Sandbox.start_owner!(Diffuser.Repo, shared: not tags[:async])
|
||||||
|
on_exit(fn -> Ecto.Adapters.SQL.Sandbox.stop_owner(pid) end)
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
A helper that transforms changeset errors into a map of messages.
|
||||||
|
|
||||||
|
assert {:error, changeset} = Accounts.create_user(%{password: "short"})
|
||||||
|
assert "password is too short" in errors_on(changeset).password
|
||||||
|
assert %{password: ["password is too short"]} = errors_on(changeset)
|
||||||
|
|
||||||
|
"""
|
||||||
|
def errors_on(changeset) do
|
||||||
|
Ecto.Changeset.traverse_errors(changeset, fn {message, opts} ->
|
||||||
|
Regex.replace(~r"%{(\w+)}", message, fn _, key ->
|
||||||
|
opts |> Keyword.get(String.to_existing_atom(key), key) |> to_string()
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,14 @@
|
||||||
|
defmodule Diffuser.Test.FileHelper do
|
||||||
|
def base64_image() do
|
||||||
|
binary_image() |> Base.encode64()
|
||||||
|
end
|
||||||
|
|
||||||
|
def binary_image() do
|
||||||
|
"#{__DIR__}/../fixtures/image.png"
|
||||||
|
|> File.read!()
|
||||||
|
end
|
||||||
|
|
||||||
|
def base64_image(_), do: {:ok, image: base64_image()}
|
||||||
|
|
||||||
|
def image_path(), do: "#{__DIR__}/../fixtures/image.png"
|
||||||
|
end
|
|
@ -0,0 +1,20 @@
|
||||||
|
defmodule Diffuser.GeneratorFixtures do
|
||||||
|
@moduledoc """
|
||||||
|
This module defines test helpers for creating
|
||||||
|
entities via the `Diffuser.Generator` context.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Generate a prompt_request.
|
||||||
|
"""
|
||||||
|
def prompt_request_fixture(attrs \\ %{}) do
|
||||||
|
{:ok, prompt_request} =
|
||||||
|
attrs
|
||||||
|
|> Enum.into(%{
|
||||||
|
prompt: "some prompt"
|
||||||
|
})
|
||||||
|
|> Diffuser.Generator.create_prompt_request()
|
||||||
|
|
||||||
|
prompt_request
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,2 @@
|
||||||
|
ExUnit.start()
|
||||||
|
Ecto.Adapters.SQL.Sandbox.mode(Diffuser.Repo, :manual)
|
Loading…
Reference in New Issue