pbudzyns commited on
Commit
25fa405
·
1 Parent(s): b3cfaa5

Add application file

Browse files
Files changed (5) hide show
  1. .gitignore +4 -0
  2. README.md +2 -2
  3. app.py +55 -0
  4. install.sh +21 -0
  5. requirements.txt +6 -0
.gitignore ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ .idea
2
+ PAMA/
3
+ samples/
4
+ flagged/
README.md CHANGED
@@ -7,7 +7,7 @@ sdk: gradio
7
  sdk_version: 3.18.0
8
  app_file: app.py
9
  pinned: false
10
- license: mit
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
7
  sdk_version: 3.18.0
8
  app_file: app.py
9
  pinned: false
10
+ license: MIT
11
  ---
12
 
13
+ Based on [https://huggingface.co/spaces/akhaliq/PAMA](https://huggingface.co/spaces/akhaliq/PAMA).
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ import gradio as gr
4
+
5
+ os.system("bash install.sh")
6
+
7
+
8
+ def inference(content: str, style: str) -> str:
9
+ os.system("cd PAMA && python main.py eval --content " + content + " --style " + style)
10
+ return "PAMA/ics.jpg"
11
+
12
+
13
+ title = "PAMA"
14
+ description = (
15
+ "<p style='text-align: center'>"
16
+ "PAMA: Consistent Style Transfer. </br> To use it, simply upload "
17
+ "your images, or click one of the examples to load them.</p>"
18
+ )
19
+
20
+ article = (
21
+ "<p style='text-align: center'>"
22
+ "<a href='https://arxiv.org/abs/2201.02233' target='_blank'>"
23
+ "Consistent Style Transfer</a> | "
24
+ "<a href='https://github.com/luoxuan-cs/PAMA' target='_blank'>"
25
+ "Github Repo</a></p>"
26
+ )
27
+
28
+ examples = [
29
+ ['samples/800px-Hoover_Tower_Stanford_January_2013.jpg',
30
+ 'samples/Leger_railway_crossing.jpg'],
31
+ ['samples/800px-Robert_Downey_Jr_2014_Comic_Con_(cropped).jpg',
32
+ 'samples/1280px-El_Tres_de_Mayo,_by_Francisco_de_Goya,_from_Prado_thin_black_margin.jpg'],
33
+ ['samples/800px-Taylor_Swift_2_-_2019_by_Glenn_Francis_(cropped)_3.jpg',
34
+ 'samples/WLANL_-_andrevanb_-_Falaises_près_de_Pourville,_Claude_Monet,_1882.jpg'],
35
+ ]
36
+
37
+
38
+ def build_interface() -> gr.Interface:
39
+ return gr.Interface(
40
+ inference,
41
+ inputs=[
42
+ gr.Image(type="filepath", label="Content"),
43
+ gr.Image(type="filepath", label="Style"),
44
+ ],
45
+ outputs=gr.Image(type="filepath", label="Output"),
46
+ title=title,
47
+ description=description,
48
+ article=article,
49
+ examples=examples,
50
+ )
51
+
52
+
53
+ if __name__ == "__main__":
54
+ interface = build_interface()
55
+ interface.launch()
install.sh ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ echo "--- Cloning PAMA git repository"
2
+ git clone https://github.com/AK391/PAMA.git
3
+
4
+ echo "--- Download sample images"
5
+ mkdir -p samples && cd samples
6
+ wget "https://upload.wikimedia.org/wikipedia/commons/thumb/1/1e/Hoover_Tower_Stanford_January_2013.jpg/800px-Hoover_Tower_Stanford_January_2013.jpg"
7
+ wget "https://upload.wikimedia.org/wikipedia/commons/thumb/e/ea/Van_Gogh_-_Starry_Night_-_Google_Art_Project.jpg/1920px-Van_Gogh_-_Starry_Night_-_Google_Art_Project.jpg"
8
+ wget "https://upload.wikimedia.org/wikipedia/commons/8/8e/WLANL_-_andrevanb_-_Falaises_pr%C3%A8s_de_Pourville%2C_Claude_Monet%2C_1882.jpg"
9
+ wget "https://upload.wikimedia.org/wikipedia/en/f/f7/Leger_railway_crossing.jpg"
10
+ wget "https://upload.wikimedia.org/wikipedia/commons/thumb/f/fb/Taylor_Swift_2_-_2019_by_Glenn_Francis_%28cropped%29_3.jpg/800px-Taylor_Swift_2_-_2019_by_Glenn_Francis_%28cropped%29_3.jpg"
11
+ wget "https://upload.wikimedia.org/wikipedia/commons/thumb/f/fd/El_Tres_de_Mayo%2C_by_Francisco_de_Goya%2C_from_Prado_thin_black_margin.jpg/1280px-El_Tres_de_Mayo%2C_by_Francisco_de_Goya%2C_from_Prado_thin_black_margin.jpg"
12
+ wget "https://upload.wikimedia.org/wikipedia/commons/thumb/9/94/Robert_Downey_Jr_2014_Comic_Con_%28cropped%29.jpg/800px-Robert_Downey_Jr_2014_Comic_Con_%28cropped%29.jpg"
13
+
14
+ echo "--- Download pretrained model"
15
+ cd ../PAMA
16
+ gdown "https://drive.google.com/uc?id=1rPB_qnelVVSad6CtadmhRFi0PMI_RKdy"
17
+
18
+ mkdir -p checkpoints
19
+ echo "--- Unpacking"
20
+ unzip -j original_PAMA.zip -d checkpoints/
21
+ echo "--- Done"
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ gdown
2
+ numpy
3
+ matplotlib
4
+ Pillow
5
+ torch>1.12
6
+ torchvision