Spaces:
Runtime error
Runtime error
Add debugging for image generation
Browse files
app.py
CHANGED
|
@@ -15,6 +15,9 @@ from transformers import GPT2TokenizerFast
|
|
| 15 |
# update requirements.txt with:
|
| 16 |
# C:\Users\Grant\PycharmProjects\test_space\venv\Scripts\pip3.exe freeze > requirements.txt
|
| 17 |
|
|
|
|
|
|
|
|
|
|
| 18 |
pretrained_weights = 'gpt2'
|
| 19 |
tokenizer = GPT2TokenizerFast.from_pretrained(pretrained_weights)
|
| 20 |
|
|
@@ -47,6 +50,7 @@ model = MinDalle(
|
|
| 47 |
|
| 48 |
|
| 49 |
def gen_image(prompt):
|
|
|
|
| 50 |
images = model.generate_images(
|
| 51 |
text=prompt,
|
| 52 |
seed=-1,
|
|
@@ -57,28 +61,29 @@ def gen_image(prompt):
|
|
| 57 |
supercondition_factor=16,
|
| 58 |
is_verbose=False
|
| 59 |
)
|
|
|
|
| 60 |
images = images.to('cpu').numpy()
|
| 61 |
images = images.astype(np.uint8)
|
| 62 |
return Image.fromarray(images[0])
|
| 63 |
|
| 64 |
|
| 65 |
-
gpu = False
|
| 66 |
-
# init only once
|
| 67 |
-
learner = load_learner('export.pkl',
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
def run_model(name):
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
|
| 83 |
|
| 84 |
iface = gr.Interface(fn=gen_image, inputs="text", outputs="pil")
|
|
|
|
| 15 |
# update requirements.txt with:
|
| 16 |
# C:\Users\Grant\PycharmProjects\test_space\venv\Scripts\pip3.exe freeze > requirements.txt
|
| 17 |
|
| 18 |
+
# Huggingface Spaces have 16GB RAM and 8 CPU cores
|
| 19 |
+
# See https://huggingface.co/docs/hub/spaces-overview#hardware-resources
|
| 20 |
+
|
| 21 |
pretrained_weights = 'gpt2'
|
| 22 |
tokenizer = GPT2TokenizerFast.from_pretrained(pretrained_weights)
|
| 23 |
|
|
|
|
| 50 |
|
| 51 |
|
| 52 |
def gen_image(prompt):
|
| 53 |
+
print(f'RUNNING gen_image with pronpt: {prompt}')
|
| 54 |
images = model.generate_images(
|
| 55 |
text=prompt,
|
| 56 |
seed=-1,
|
|
|
|
| 61 |
supercondition_factor=16,
|
| 62 |
is_verbose=False
|
| 63 |
)
|
| 64 |
+
print('COMPLETED GENERATION')
|
| 65 |
images = images.to('cpu').numpy()
|
| 66 |
images = images.astype(np.uint8)
|
| 67 |
return Image.fromarray(images[0])
|
| 68 |
|
| 69 |
|
| 70 |
+
# gpu = False
|
| 71 |
+
# # init only once
|
| 72 |
+
# learner = load_learner('export.pkl',
|
| 73 |
+
# cpu=not gpu) # cpu=False uses GPU; make sure installed torch is GPU e.g. `pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu116`
|
| 74 |
+
#
|
| 75 |
+
#
|
| 76 |
+
# def run_model(name):
|
| 77 |
+
# prompt = f"Name: {name}\r\n"
|
| 78 |
+
# prompt_ids = tokenizer.encode(prompt)
|
| 79 |
+
# if gpu:
|
| 80 |
+
# inp = tensor(prompt_ids)[None].cuda() # Use .cuda() for torch GPU
|
| 81 |
+
# else:
|
| 82 |
+
# inp = tensor(prompt_ids)[None]
|
| 83 |
+
# preds = learner.model.generate(inp, max_length=1024, num_beams=5, temperature=1.5, do_sample=True)
|
| 84 |
+
# result = tokenizer.decode(preds[0].cpu().numpy())
|
| 85 |
+
# result = result.split('###')[0].replace(r'\r\n', '\n')
|
| 86 |
+
# return result
|
| 87 |
|
| 88 |
|
| 89 |
iface = gr.Interface(fn=gen_image, inputs="text", outputs="pil")
|