Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
animegan2-pytorch
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
git
animegan2-pytorch
Commits
88f75498
Unverified
Commit
88f75498
authored
Nov 17, 2021
by
bryandlee
Committed by
GitHub
Nov 17, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #28 from xhlulu/main
Fix uploader issues in colab_demo.ipynb
parents
cd65ad5c
927c6c14
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
14 deletions
+8
-14
colab_demo.ipynb
colab_demo.ipynb
+8
-14
No files found.
colab_demo.ipynb
View file @
88f75498
...
@@ -74,6 +74,8 @@
...
@@ -74,6 +74,8 @@
},
},
"outputs": [],
"outputs": [],
"source": [
"source": [
"#@title Anime FaceGAN Colab app\n",
"\n",
"from io import BytesIO\n",
"from io import BytesIO\n",
"import torch\n",
"import torch\n",
"from PIL import Image\n",
"from PIL import Image\n",
...
@@ -85,38 +87,30 @@
...
@@ -85,38 +87,30 @@
"device = \"cuda\" if torch.cuda.is_available() else \"cpu\"\n",
"device = \"cuda\" if torch.cuda.is_available() else \"cpu\"\n",
"model = torch.hub.load(\"bryandlee/animegan2-pytorch:main\", \"generator\", device=device).eval()\n",
"model = torch.hub.load(\"bryandlee/animegan2-pytorch:main\", \"generator\", device=device).eval()\n",
"face2paint = torch.hub.load(\"bryandlee/animegan2-pytorch:main\", \"face2paint\", device=device)\n",
"face2paint = torch.hub.load(\"bryandlee/animegan2-pytorch:main\", \"face2paint\", device=device)\n",
"\n",
"image_format = \"png\" #@param [\"jpeg\", \"png\"]\n",
"#@title Anime FaceGAN Colab app\n",
"image_format = \"jpeg\" #@param [\"jpeg\", \"png\"]\n",
"\n",
"\n",
"\n",
"button = widgets.Button(description=\"Start\")\n",
"button = widgets.Button(description=\"Start\")\n",
"output = widgets.Output()\n",
"output = widgets.Output()\n",
"\n",
"\n",
"uploader = widgets.FileUpload(\n",
" accept='image/*', # Accepted file extension e.g. '.txt', '.pdf', 'image/*', 'image/*,.pdf'\n",
" multiple=False # True to accept multiple files upload else False\n",
")\n",
"\n",
"\n",
"def run(b):\n",
"def run(b):\n",
" button.disabled = True\n",
" button.disabled = True\n",
"\n",
"\n",
" with output:\n",
" with output:\n",
" display.clear_output()\n",
" display.clear_output()\n",
" \n",
" uploaded = files.upload()\n",
"\n",
"\n",
" for fname in uploade
r.value
:\n",
" for fname in uploade
d
:\n",
" bytes_in = uploade
r.value[fname]['content'
]\n",
" bytes_in = uploade
d[fname
]\n",
"\n",
"\n",
" im_in = Image.open(BytesIO(bytes_in)).convert(\"RGB\")\n",
" im_in = Image.open(BytesIO(bytes_in)).convert(\"RGB\")\n",
" im_out = face2paint(model, im_in, side_by_side=False)\n",
" im_out = face2paint(model, im_in, side_by_side=False)\n",
"\n",
" buffer_out = BytesIO()\n",
" buffer_out = BytesIO()\n",
" im_out.save(buffer_out, format=image_format)\n",
" im_out.save(buffer_out, format=image_format)\n",
"\n",
" bytes_out = buffer_out.getvalue()\n",
" bytes_out = buffer_out.getvalue()\n",
" wi1 = widgets.Image(value=bytes_in, format=image_format)\n",
" wi1 = widgets.Image(value=bytes_in, format=image_format)\n",
" wi2 = widgets.Image(value=bytes_out, format=image_format)\n",
" wi2 = widgets.Image(value=bytes_out, format=image_format)\n",
"\n",
" wi1.layout.max_width = '500px'\n",
" wi1.layout.max_width = '500px'\n",
" wi1.layout.max_height = '500px'\n",
" wi1.layout.max_height = '500px'\n",
" wi2.layout.max_width = '500px'\n",
" wi2.layout.max_width = '500px'\n",
...
@@ -131,7 +125,7 @@
...
@@ -131,7 +125,7 @@
" button.disabled = False\n",
" button.disabled = False\n",
"\n",
"\n",
"button.on_click(run)\n",
"button.on_click(run)\n",
"display.display(
uploader,
button, output)"
"display.display(button, output)"
]
]
}
}
],
],
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment