rajesh1729 commited on
Commit
7030463
1 Parent(s): 7671896

Upload gan1.ipynb

Browse files
Files changed (1) hide show
  1. gan1.ipynb +133 -0
gan1.ipynb ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "raw",
5
+ "id": "c6be22eb",
6
+ "metadata": {},
7
+ "source": [
8
+ "---\n",
9
+ "title: Toonify your Pics\n",
10
+ "description: Creates a cartoon version of your pic(with download option)\n",
11
+ "show-code: False\n",
12
+ "params:\n",
13
+ " image_path:\n",
14
+ " input: file\n",
15
+ " label: Please upload a photo\n",
16
+ " output_dir:\n",
17
+ " output: dir\n",
18
+ "---"
19
+ ]
20
+ },
21
+ {
22
+ "cell_type": "code",
23
+ "execution_count": null,
24
+ "id": "c4481a3c",
25
+ "metadata": {},
26
+ "outputs": [],
27
+ "source": [
28
+ "image_path = 'trump.jpg'\n",
29
+ "output_dir = \"output_images\""
30
+ ]
31
+ },
32
+ {
33
+ "cell_type": "code",
34
+ "execution_count": null,
35
+ "id": "a8803760",
36
+ "metadata": {},
37
+ "outputs": [],
38
+ "source": [
39
+ "import os\n",
40
+ "import torch\n",
41
+ "from PIL import Image\n",
42
+ "import warnings\n",
43
+ "warnings.filterwarnings(\"ignore\")"
44
+ ]
45
+ },
46
+ {
47
+ "cell_type": "markdown",
48
+ "id": "56e86849",
49
+ "metadata": {},
50
+ "source": [
51
+ "## This is the Toonify app that creates a cartoon version of any image you upload. \n",
52
+ "## Upload an image by clicking the 'Browse' button or by 'Drag & Drop' and click 'Run' to toonify your image.\n"
53
+ ]
54
+ },
55
+ {
56
+ "cell_type": "code",
57
+ "execution_count": null,
58
+ "id": "ddb89e68",
59
+ "metadata": {},
60
+ "outputs": [],
61
+ "source": [
62
+ "model = torch.hub.load(\"bryandlee/animegan2-pytorch:main\", \"generator\", pretrained=\"paprika\")\n",
63
+ "face2paint = torch.hub.load(\"bryandlee/animegan2-pytorch:main\", \"face2paint\", size=512)"
64
+ ]
65
+ },
66
+ {
67
+ "cell_type": "code",
68
+ "execution_count": null,
69
+ "id": "43dccffa",
70
+ "metadata": {},
71
+ "outputs": [],
72
+ "source": [
73
+ "def toonify(img):\n",
74
+ " out = face2paint(model, img)\n",
75
+ " return out"
76
+ ]
77
+ },
78
+ {
79
+ "cell_type": "code",
80
+ "execution_count": null,
81
+ "id": "71e9255d",
82
+ "metadata": {},
83
+ "outputs": [],
84
+ "source": [
85
+ "im = Image.open(image_path).convert('RGB')"
86
+ ]
87
+ },
88
+ {
89
+ "cell_type": "code",
90
+ "execution_count": null,
91
+ "id": "a31f4c2c",
92
+ "metadata": {
93
+ "scrolled": false
94
+ },
95
+ "outputs": [],
96
+ "source": [
97
+ "toonify(im)"
98
+ ]
99
+ },
100
+ {
101
+ "cell_type": "code",
102
+ "execution_count": null,
103
+ "id": "33c1461a",
104
+ "metadata": {},
105
+ "outputs": [],
106
+ "source": [
107
+ "#toonify(im).save(f\"{output_dir}/toonify.jpg\")\n",
108
+ "#print(\"To download your toonified image, click the output files option at the top and click download\")"
109
+ ]
110
+ }
111
+ ],
112
+ "metadata": {
113
+ "kernelspec": {
114
+ "display_name": "Python 3 (ipykernel)",
115
+ "language": "python",
116
+ "name": "python3"
117
+ },
118
+ "language_info": {
119
+ "codemirror_mode": {
120
+ "name": "ipython",
121
+ "version": 3
122
+ },
123
+ "file_extension": ".py",
124
+ "mimetype": "text/x-python",
125
+ "name": "python",
126
+ "nbconvert_exporter": "python",
127
+ "pygments_lexer": "ipython3",
128
+ "version": "3.8.13"
129
+ }
130
+ },
131
+ "nbformat": 4,
132
+ "nbformat_minor": 5
133
+ }