infernet-1.0.0 update
This commit is contained in:
@ -7,12 +7,15 @@ ENV PYTHONDONTWRITEBYTECODE 1
|
||||
ENV PIP_NO_CACHE_DIR 1
|
||||
ENV RUNTIME docker
|
||||
ENV PYTHONPATH src
|
||||
ARG index_url
|
||||
ENV UV_EXTRA_INDEX_URL ${index_url}
|
||||
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y git curl
|
||||
|
||||
# install uv
|
||||
ADD --chmod=755 https://astral.sh/uv/install.sh /install.sh
|
||||
ADD https://astral.sh/uv/install.sh /install.sh
|
||||
RUN chmod 755 /install.sh
|
||||
RUN /install.sh && rm /install.sh
|
||||
|
||||
COPY src/requirements.txt .
|
||||
|
@ -9,7 +9,7 @@ ifdef CI
|
||||
mkdir -p wallet # in CI we don't have a wallet directory. This enables to bypass that and ensure that the image
|
||||
# is built successfully
|
||||
endif
|
||||
@docker build -t $(TAG) .
|
||||
@docker build -t $(TAG) --build-arg index_url=$(index_url) .
|
||||
|
||||
wallet_dir ?= /app/wallet
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
"enabled": true,
|
||||
"trail_head_blocks": 0,
|
||||
"rpc_url": "http://host.docker.internal:8545",
|
||||
"coordinator_address": "0x5FbDB2315678afecb367f032d93F642f64180aa3",
|
||||
"registry_address": "0x663F3ad617193148711d28f5334eE4Ed07016602",
|
||||
"wallet": {
|
||||
"max_gas_limit": 4000000,
|
||||
"private_key": "0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d"
|
||||
@ -23,6 +23,10 @@
|
||||
"port": 6379
|
||||
},
|
||||
"forward_stats": true,
|
||||
"snapshot_sync": {
|
||||
"sleep": 3,
|
||||
"batch_size": 100
|
||||
},
|
||||
"containers": [
|
||||
{
|
||||
"id": "prompt-to-nft",
|
||||
@ -36,18 +40,8 @@
|
||||
"env": {
|
||||
"ARWEAVE_WALLET_FILE_PATH": "wallet/keyfile-arweave.json",
|
||||
"IMAGE_GEN_SERVICE_URL": "http://your.services.ip:port"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "anvil-node",
|
||||
"image": "ritualnetwork/infernet-anvil:0.0.0",
|
||||
"external": true,
|
||||
"port": "8545",
|
||||
"allowed_delegate_addresses": [],
|
||||
"allowed_addresses": [],
|
||||
"allowed_ips": [],
|
||||
"command": "",
|
||||
"env": {}
|
||||
},
|
||||
"accepted_payments": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -5,9 +5,9 @@ from typing import Any, cast
|
||||
|
||||
import aiohttp
|
||||
from eth_abi import decode, encode # type: ignore
|
||||
from infernet_ml.utils.arweave import upload, load_wallet
|
||||
from infernet_ml.utils.service_models import InfernetInput, InfernetInputSource
|
||||
from infernet_ml.utils.service_models import InfernetInput, JobLocation
|
||||
from quart import Quart, request
|
||||
from ritual_arweave.file_manager import FileManager
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@ -29,7 +29,6 @@ async def run_inference(prompt: str, output_path: str) -> None:
|
||||
def ensure_env_vars() -> None:
|
||||
if not os.getenv("IMAGE_GEN_SERVICE_URL"):
|
||||
raise ValueError("IMAGE_GEN_SERVICE_URL environment variable not set")
|
||||
load_wallet()
|
||||
|
||||
|
||||
def create_app() -> Quart:
|
||||
@ -54,50 +53,59 @@ def create_app() -> Quart:
|
||||
infernet_input: InfernetInput = InfernetInput(**req_data)
|
||||
temp_file = "image.png"
|
||||
|
||||
if infernet_input.source == InfernetInputSource.OFFCHAIN:
|
||||
prompt: str = cast(dict[str, str], infernet_input.data)["prompt"]
|
||||
else:
|
||||
# On-chain requests are sent as a generalized hex-string which we will
|
||||
# decode to the appropriate format.
|
||||
(prompt, mintTo) = decode(
|
||||
["string", "address"], bytes.fromhex(cast(str, infernet_input.data))
|
||||
)
|
||||
log.info("mintTo: %s", mintTo)
|
||||
log.info("prompt: %s", prompt)
|
||||
match infernet_input:
|
||||
case InfernetInput(source=JobLocation.OFFCHAIN):
|
||||
prompt: str = cast(dict[str, str], infernet_input.data)["prompt"]
|
||||
case InfernetInput(source=JobLocation.ONCHAIN):
|
||||
# On-chain requests are sent as a generalized hex-string which we will
|
||||
# decode to the appropriate format.
|
||||
(prompt, mintTo) = decode(
|
||||
["string", "address"], bytes.fromhex(cast(str, infernet_input.data))
|
||||
)
|
||||
log.info("mintTo: %s", mintTo)
|
||||
log.info("prompt: %s", prompt)
|
||||
case _:
|
||||
raise ValueError("Invalid source")
|
||||
|
||||
# run the inference and download the image to a temp file
|
||||
await run_inference(prompt, temp_file)
|
||||
|
||||
tx = upload(Path(temp_file), {"Content-Type": "image/png"})
|
||||
tx = FileManager(wallet_path=os.environ["ARWEAVE_WALLET_FILE_PATH"]).upload(
|
||||
Path(temp_file), {"Content-Type": "image/png"}
|
||||
)
|
||||
|
||||
if infernet_input.source == InfernetInputSource.OFFCHAIN:
|
||||
"""
|
||||
In case of an off-chain request, the result is returned as is.
|
||||
"""
|
||||
return {
|
||||
"prompt": prompt,
|
||||
"hash": tx.id,
|
||||
"image_url": f"https://arweave.net/{tx.id}",
|
||||
}
|
||||
else:
|
||||
"""
|
||||
In case of an on-chain request, the result is returned in the format:
|
||||
{
|
||||
"raw_input": str,
|
||||
"processed_input": str,
|
||||
"raw_output": str,
|
||||
"processed_output": str,
|
||||
"proof": str,
|
||||
}
|
||||
refer to: https://docs.ritual.net/infernet/node/containers for more info.
|
||||
"""
|
||||
return {
|
||||
"raw_input": infernet_input.data,
|
||||
"processed_input": "",
|
||||
"raw_output": encode(["string"], [tx.id]).hex(),
|
||||
"processed_output": "",
|
||||
"proof": "",
|
||||
}
|
||||
match infernet_input:
|
||||
case InfernetInput(destination=JobLocation.OFFCHAIN):
|
||||
"""
|
||||
In case of an off-chain request, the result is returned as is.
|
||||
"""
|
||||
return {
|
||||
"prompt": prompt,
|
||||
"hash": tx.id,
|
||||
"image_url": f"https://arweave.net/{tx.id}",
|
||||
}
|
||||
case InfernetInput(destination=JobLocation.ONCHAIN):
|
||||
"""
|
||||
In case of an on-chain request, the result is returned in the format:
|
||||
{
|
||||
"raw_input": str,
|
||||
"processed_input": str,
|
||||
"raw_output": str,
|
||||
"processed_output": str,
|
||||
"proof": str,
|
||||
}
|
||||
refer to: https://docs.ritual.net/infernet/node/containers for more
|
||||
info.
|
||||
"""
|
||||
return {
|
||||
"raw_input": infernet_input.data,
|
||||
"processed_input": "",
|
||||
"raw_output": encode(["string"], [tx.id]).hex(),
|
||||
"processed_output": "",
|
||||
"proof": "",
|
||||
}
|
||||
case _:
|
||||
raise ValueError("Invalid destination")
|
||||
|
||||
return app
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
quart==0.19.4
|
||||
infernet_ml==0.1.0
|
||||
PyArweave @ git+https://github.com/ritual-net/pyarweave.git
|
||||
infernet-ml==1.0.0
|
||||
web3==6.15.0
|
||||
tqdm==4.66.1
|
||||
tqdm==4.66.3
|
||||
|
Submodule projects/prompt-to-nft/contracts/lib/forge-std updated: e4aef94c17...52715a217d
Submodule projects/prompt-to-nft/contracts/lib/infernet-sdk updated: 2d04a7f5ed...8e6cd6f5cb
@ -5,7 +5,8 @@ import {Script, console2} from "forge-std/Script.sol";
|
||||
import {DiffusionNFT} from "../src/DiffusionNFT.sol";
|
||||
|
||||
contract CallContract is Script {
|
||||
string defaultPrompt = "A picture of a shrimp dunking a basketball";
|
||||
string defaultPrompt = "A picture of a shrimp dunking a basketball";
|
||||
|
||||
function run() public {
|
||||
// Setup wallet
|
||||
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
|
||||
@ -13,7 +14,7 @@ string defaultPrompt = "A picture of a shrimp dunking a basketball";
|
||||
string memory prompt = vm.envOr("prompt", defaultPrompt);
|
||||
vm.startBroadcast(deployerPrivateKey);
|
||||
|
||||
DiffusionNFT nft = DiffusionNFT(0x663F3ad617193148711d28f5334eE4Ed07016602);
|
||||
DiffusionNFT nft = DiffusionNFT(0x13D69Cf7d6CE4218F646B759Dcf334D82c023d8e);
|
||||
|
||||
nft.mint(prompt, mintTo);
|
||||
|
||||
|
@ -14,9 +14,9 @@ contract Deploy is Script {
|
||||
address deployerAddress = vm.addr(deployerPrivateKey);
|
||||
console2.log("Loaded deployer: ", deployerAddress);
|
||||
|
||||
address coordinator = 0x5FbDB2315678afecb367f032d93F642f64180aa3;
|
||||
address registry = 0x663F3ad617193148711d28f5334eE4Ed07016602;
|
||||
// Create consumer
|
||||
DiffusionNFT nft = new DiffusionNFT(coordinator);
|
||||
DiffusionNFT nft = new DiffusionNFT(registry);
|
||||
console2.log("Deployed IrisClassifier: ", address(nft));
|
||||
|
||||
// Execute
|
||||
|
@ -11,10 +11,18 @@ contract DiffusionNFT is CallbackConsumer, ERC721 {
|
||||
"| _ / | | | | | | | |/ /\\ \\ | |\n" "| | \\ \\ _| |_ | | | |__| / ____ \\| |____\n"
|
||||
"|_| \\_\\_____| |_| \\____/_/ \\_\\______|\n\n";
|
||||
|
||||
constructor(address coordinator) CallbackConsumer(coordinator) ERC721("DiffusionNFT", "DN") {}
|
||||
constructor(address registry) CallbackConsumer(registry) ERC721("DiffusionNFT", "DN") {}
|
||||
|
||||
function mint(string memory prompt, address to) public {
|
||||
_requestCompute("prompt-to-nft", abi.encode(prompt, to), 20 gwei, 1_000_000, 1);
|
||||
_requestCompute(
|
||||
"prompt-to-nft",
|
||||
abi.encode(prompt, to),
|
||||
1, // redundancy
|
||||
address(0), // paymentToken
|
||||
0, // paymentAmount
|
||||
address(0), // wallet
|
||||
address(0) // prover
|
||||
);
|
||||
}
|
||||
|
||||
uint256 public counter = 0;
|
||||
@ -38,7 +46,6 @@ contract DiffusionNFT is CallbackConsumer, ERC721 {
|
||||
return collection;
|
||||
}
|
||||
|
||||
|
||||
function _receiveCompute(
|
||||
uint32 subscriptionId,
|
||||
uint32 interval,
|
||||
@ -46,7 +53,9 @@ contract DiffusionNFT is CallbackConsumer, ERC721 {
|
||||
address node,
|
||||
bytes calldata input,
|
||||
bytes calldata output,
|
||||
bytes calldata proof
|
||||
bytes calldata proof,
|
||||
bytes32 containerId,
|
||||
uint256 index
|
||||
) internal override {
|
||||
console2.log(EXTREMELY_COOL_BANNER);
|
||||
(bytes memory raw_output, bytes memory processed_output) = abi.decode(output, (bytes, bytes));
|
||||
|
@ -262,7 +262,7 @@ Notice that in [one of the steps above](#check-the-running-containers) we have a
|
||||
|
||||
By default, the [`anvil-node`](https://hub.docker.com/r/ritualnetwork/infernet-anvil) image used deploys the
|
||||
[Infernet SDK](https://docs.ritual.net/infernet/sdk/introduction) and other relevant contracts for you:
|
||||
- Coordinator: `0x5FbDB2315678afecb367f032d93F642f64180aa3`
|
||||
- Registry: `0x663F3ad617193148711d28f5334eE4Ed07016602`
|
||||
- Primary node: `0x70997970C51812dc3A010C7d01b50e0d17dc79C8`
|
||||
|
||||
### Deploy our NFT Consumer contract
|
||||
@ -296,7 +296,7 @@ You should expect to see similar Anvil logs:
|
||||
eth_getTransactionReceipt
|
||||
|
||||
Transaction: 0x0577dc98192d971bafb30d53cb217c9a9c16f92ab435d20a697024a4f122c048
|
||||
Contract created: 0x663f3ad617193148711d28f5334ee4ed07016602
|
||||
Contract created: 0x13D69Cf7d6CE4218F646B759Dcf334D82c023d8e
|
||||
Gas used: 1582129
|
||||
|
||||
Block Number: 1
|
||||
@ -307,7 +307,7 @@ eth_getTransactionByHash
|
||||
```
|
||||
|
||||
From our logs, we can see that the `DiffusionNFT` contract has been deployed to address
|
||||
`0x663f3ad617193148711d28f5334ee4ed07016602`.
|
||||
`0x13D69Cf7d6CE4218F646B759Dcf334D82c023d8e`.
|
||||
|
||||
### Call the contract
|
||||
|
||||
|
@ -5,6 +5,8 @@ WORKDIR /app
|
||||
ENV PYTHONUNBUFFERED 1
|
||||
ENV PYTHONDONTWRITEBYTECODE 1
|
||||
ENV PYTHONPATH src
|
||||
ARG index_url
|
||||
ENV UV_EXTRA_INDEX_URL ${index_url}
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
@ -12,7 +14,8 @@ RUN apt-get update
|
||||
RUN apt-get install -y git curl ffmpeg libsm6 libxext6
|
||||
|
||||
# install uv
|
||||
ADD --chmod=755 https://astral.sh/uv/install.sh /install.sh
|
||||
ADD https://astral.sh/uv/install.sh /install.sh
|
||||
RUN chmod 755 /install.sh
|
||||
RUN /install.sh && rm /install.sh
|
||||
|
||||
COPY src/requirements.txt .
|
||||
|
@ -5,7 +5,7 @@ TAG := $(DOCKER_ORG)/example-$(EXAMPLE_NAME)-infernet:latest
|
||||
.phony: build run build-multiplatform
|
||||
|
||||
build:
|
||||
@docker build -t $(TAG) .
|
||||
@docker build -t $(TAG) --build-arg index_url=$(index_url) .
|
||||
|
||||
port_mapping ?= 0.0.0.0:3002:3000
|
||||
|
||||
|
@ -1,10 +1,9 @@
|
||||
diffusers~=0.19
|
||||
invisible_watermark~=0.1
|
||||
transformers==4.36
|
||||
transformers==4.38.0
|
||||
accelerate~=0.21
|
||||
safetensors~=0.3
|
||||
Quart==0.19.4
|
||||
jmespath==1.0.1
|
||||
huggingface-hub==0.20.3
|
||||
infernet_ml==0.1.0
|
||||
PyArweave @ git+https://github.com/ritual-net/pyarweave.git
|
||||
infernet-ml==1.0.0
|
||||
|
@ -11,7 +11,7 @@
|
||||
"dependencies": {
|
||||
"@rainbow-me/rainbowkit": "^2.0.0",
|
||||
"@tanstack/react-query": "^5.22.2",
|
||||
"next": "14.1.0",
|
||||
"next": "14.1.1",
|
||||
"prettier": "^3.2.5",
|
||||
"react": "^18",
|
||||
"react-dom": "^18",
|
||||
@ -27,6 +27,6 @@
|
||||
"postcss": "^8",
|
||||
"tailwindcss": "^3.3.0",
|
||||
"eslint": "^8",
|
||||
"eslint-config-next": "14.1.0"
|
||||
"eslint-config-next": "14.1.1"
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user