gigend andzhk commited on
Commit
c3cda93
·
0 Parent(s):

Duplicate from andzhk/PNGInfo

Browse files

Co-authored-by: Andrei Zhytkevich <[email protected]>

Files changed (6) hide show
  1. .gitignore +129 -0
  2. LICENSE +21 -0
  3. README.md +57 -0
  4. app.py +52 -0
  5. nodemon.json +6 -0
  6. requirements.txt +3 -0
.gitignore ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ pip-wheel-metadata/
24
+ share/python-wheels/
25
+ *.egg-info/
26
+ .installed.cfg
27
+ *.egg
28
+ MANIFEST
29
+
30
+ # PyInstaller
31
+ # Usually these files are written by a python script from a template
32
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
33
+ *.manifest
34
+ *.spec
35
+
36
+ # Installer logs
37
+ pip-log.txt
38
+ pip-delete-this-directory.txt
39
+
40
+ # Unit test / coverage reports
41
+ htmlcov/
42
+ .tox/
43
+ .nox/
44
+ .coverage
45
+ .coverage.*
46
+ .cache
47
+ nosetests.xml
48
+ coverage.xml
49
+ *.cover
50
+ *.py,cover
51
+ .hypothesis/
52
+ .pytest_cache/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ target/
76
+
77
+ # Jupyter Notebook
78
+ .ipynb_checkpoints
79
+
80
+ # IPython
81
+ profile_default/
82
+ ipython_config.py
83
+
84
+ # pyenv
85
+ .python-version
86
+
87
+ # pipenv
88
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
90
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
91
+ # install all needed dependencies.
92
+ #Pipfile.lock
93
+
94
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow
95
+ __pypackages__/
96
+
97
+ # Celery stuff
98
+ celerybeat-schedule
99
+ celerybeat.pid
100
+
101
+ # SageMath parsed files
102
+ *.sage.py
103
+
104
+ # Environments
105
+ .env
106
+ .venv
107
+ env/
108
+ venv/
109
+ ENV/
110
+ env.bak/
111
+ venv.bak/
112
+
113
+ # Spyder project settings
114
+ .spyderproject
115
+ .spyproject
116
+
117
+ # Rope project settings
118
+ .ropeproject
119
+
120
+ # mkdocs documentation
121
+ /site
122
+
123
+ # mypy
124
+ .mypy_cache/
125
+ .dmypy.json
126
+ dmypy.json
127
+
128
+ # Pyre type checker
129
+ .pyre/
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Andrei Zhytkevich
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
README.md ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: PNG Info
3
+ emoji: 🚀
4
+ colorFrom: indigo
5
+ colorTo: yellow
6
+ sdk: gradio
7
+ sdk_version: 3.16.2
8
+ app_file: app.py
9
+ pinned: false
10
+ license: wtfpl
11
+ duplicated_from: andzhk/PNGInfo
12
+ ---
13
+
14
+ This project is published on [HuggingFace](https://huggingface.co/spaces/andzhk/PNGInfo)
15
+
16
+ # PNG Info (png-params)
17
+
18
+ This is Gradio project for reading and displaying an image and its metadata from url.
19
+
20
+ Currently, only PNG is supported.
21
+
22
+ ## Usage
23
+
24
+ - Copy image address
25
+ - Paste it into the **url** field
26
+ - or Drag and Drop/Upload image
27
+ - Submit
28
+
29
+ **Generation parameters** text can be directly used in AUTOMATIC1111 UI
30
+
31
+ ## Running locally
32
+
33
+ ### Prerequisites
34
+
35
+ Python 3
36
+
37
+ ### Install requirements
38
+
39
+ ```bash
40
+ pip install -r requirements.txt
41
+ ```
42
+
43
+ ### Run
44
+
45
+ ```bash
46
+ python images.py
47
+ ```
48
+
49
+ Use [nodemon](https://www.npmjs.com/package/nodemon) for development.
50
+
51
+ ```bash
52
+ nodemon images.py
53
+ ```
54
+
55
+ ### Open UI
56
+
57
+ Usually Gradio UI is running on http://127.0.0.1:7860
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from PIL import Image
3
+ from urllib.request import Request, urlopen
4
+
5
+ def display_image_from_url(url, input_image):
6
+ if url == '' and input_image is None:
7
+ return None, "", ""
8
+
9
+ image = None
10
+ if url != '':
11
+ req = Request(
12
+ url=url,
13
+ headers={'User-Agent': 'Mozilla/5.0'}
14
+ )
15
+ res = urlopen(req)
16
+ image = Image.open(res)
17
+ image.load()
18
+
19
+
20
+ if input_image is not None:
21
+ image = input_image
22
+
23
+ parameters = "Parameters have been erased from this image or unsupported format"
24
+ if 'parameters' in image.info:
25
+ parameters = image.info['parameters']
26
+
27
+ return image, parameters, image.info
28
+
29
+ blocks = gr.Blocks(css="#out_image {height: 400px}")
30
+ with blocks as png_info:
31
+ with gr.Row():
32
+ gr.Markdown(
33
+ """
34
+ Report any issues on the [GitHub](https://github.com/andzhik/png-params) page of this project
35
+ """)
36
+ with gr.Row().style(equal_height=False):
37
+ with gr.Column():
38
+ in_url = gr.Textbox(label="Source URL")
39
+ in_image = gr.Image(label="Source Image", type='pil')
40
+ with gr.Row():
41
+ btn_submit = gr.Button("Submit", variant="primary")
42
+
43
+ with gr.Column():
44
+ out_image = gr.Image(type='pil', elem_id="out_image")
45
+ out_info = gr.Textbox(label="Generation Parameters")
46
+ out_meta = gr.Textbox(label="Metadata")
47
+
48
+ btn_submit.click(fn=display_image_from_url,
49
+ inputs=[in_url, in_image],
50
+ outputs=[out_image, out_info, out_meta])
51
+
52
+ png_info.launch()
nodemon.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "verbose": true,
3
+ "execMap": {
4
+ "py": "/usr/bin/python3"
5
+ }
6
+ }
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ Pillow
2
+ gradio
3
+ urllib3