forked from callaunchpad/Lunchpad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
97 lines (61 loc) · 2.77 KB
/
main.py
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
import torch
import numpy as np
import argparse
#FIXME: Set up argparser + arguments
def main():
img_path = '~/data/1.png'
#FIXME: Run model inference on original image
for i in range(numgens):
with torch.no_grad():
outputs = model.sample(image_tensor, greedy=greedy[i],
temperature=temperature, beam=beam[i], true_ingrs=None)
ingr_ids = outputs['ingr_ids'].cpu().numpy()
recipe_ids = outputs['recipe_ids'].cpu().numpy()
outs, valid = prepare_output(recipe_ids[0], ingr_ids[0], ingrs_vocab, vocab)
if valid['is_valid'] or show_anyways:
print ('RECIPE', num_valid)
num_valid+=1
#print ("greedy:", greedy[i], "beam:", beam[i])
BOLD = '\033[1m'
END = '\033[0m'
print (BOLD + '\nTitle:' + END,outs['title'])
print (BOLD + '\nIngredients:'+ END)
print (', '.join(outs['ingrs']))
print (BOLD + '\nInstructions:'+END)
print ('-'+'\n-'.join(outs['recipe']))
print ('='*20)
else:
pass
print ("Not a valid recipe!")
print ("Reason: ", valid['reason'])
igr = outs['ingrs']
#FIXME: Create hardcoded StableDiffusion prompt
prompt = "Fancy + " + ingr + "alisdhfjklsajdg"
#FIXME: Use StableDiffusion to generate new image
new_image = StableDiffusionPipeline(prompt, image)
#FIXME: Run model inference on new image
for i in range(numgens):
with torch.no_grad():
outputs = model.sample(image_tensor, greedy=greedy[i],
temperature=temperature, beam=beam[i], true_ingrs=None)
ingr_ids = outputs['ingr_ids'].cpu().numpy()
recipe_ids = outputs['recipe_ids'].cpu().numpy()
outs, valid = prepare_output(recipe_ids[0], ingr_ids[0], ingrs_vocab, vocab)
if valid['is_valid'] or show_anyways:
print ('RECIPE', num_valid)
num_valid+=1
#print ("greedy:", greedy[i], "beam:", beam[i])
BOLD = '\033[1m'
END = '\033[0m'
print (BOLD + '\nTitle:' + END,outs['title'])
print (BOLD + '\nIngredients:'+ END)
print (', '.join(outs['ingrs']))
print (BOLD + '\nInstructions:'+END)
print ('-'+'\n-'.join(outs['recipe']))
print ('='*20)
else:
pass
print ("Not a valid recipe!")
print ("Reason: ", valid['reason'])
#FIXME: Print out output/display new image onto terminal
pass