-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtest.py
More file actions
97 lines (72 loc) · 2.51 KB
/
test.py
File metadata and controls
97 lines (72 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# queries local miner for images
import bittensor as bt
from protocol import TextToImage, ImageToImage
import asyncio
import torchvision.transforms as transforms
import time
from PIL import Image
wallet = bt.wallet()
dendrite = bt.dendrite(wallet=wallet)
bt.trace()
# metagraph
metagraph = bt.metagraph(5, network="finney")
metagraph.sync()
axons = metagraph.axons
myaxonid = -1 # set this to be your axon id
if myaxonid == -1:
print("Please set myaxonid in test.py:19 to be your axon id")
exit()
query = TextToImage(
text="an (anime:1.2) beautiful autumn forest scenery with the wind blowing the leaves",
negative_prompt="worst quality, nsfw, xxx",
width=768,
height=768,
num_images_per_prompt=1,
seed=-1
)
call_single_uid = dendrite(
axons[myaxonid],
synapse=query,
timeout=30.0
)
# await call_single_uid
async def query_async(call_single_uid):
corutines = [call_single_uid]
return await asyncio.gather(*corutines)
x = asyncio.run(query_async(call_single_uid))
_img = None
for image in x[0].images:
# Convert the raw tensor from the Synapse into a PIL image and display it.
transforms.ToPILImage()( bt.Tensor.deserialize(image) ).show()
if(_img is None):
_img = image
if(_img is None):
bt.logging.warning("No image found")
exit()
def i2i(t2i: TextToImage, **kwargs) -> ImageToImage:
params = {
'text': t2i.text,
'negative_prompt': t2i.negative_prompt,
'height': t2i.height,
'width': t2i.width,
'num_images_per_prompt': t2i.num_images_per_prompt,
'seed': 696969,
}
# Update the parameters with the provided kwargs
params.update(kwargs)
print(params)
query = ImageToImage(**params)
call_single_uid = dendrite(
axons[myaxonid],
synapse=query,
timeout=30.0
)
queried_async = asyncio.run(query_async(call_single_uid))
return queried_async[0]
def show_images(i2i_result: ImageToImage) -> None:
for image in i2i_result.images:
# Convert the raw tensor from the Synapse into a PIL image and display it.
transforms.ToPILImage()( bt.Tensor.deserialize(image) ).show()
show_images(i2i(query, image=_img, similarity="high", text="an (anime:1.2) woman walking on a path in an autumn forest"))
show_images(i2i(query, image=_img, similarity="medium", text="an (anime:1.2) woman walking on a path in an autumn forest"))
show_images(i2i(query, image=_img, similarity="low", text="an (anime:1.2) woman walking on a path in an autumn forest"))