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
|
||||
|
Reference in New Issue
Block a user