wybxc commited on
Commit
3ce4ca8
1 Parent(s): bfc9213

upload files

Browse files
Files changed (6) hide show
  1. .gitattributes +1 -0
  2. .gitignore +2 -0
  3. README.md +3 -4
  4. app.py +43 -0
  5. png.py +0 -0
  6. requirements.txt +1 -0
.gitattributes CHANGED
@@ -32,3 +32,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
32
  *.zip filter=lfs diff=lfs merge=lfs -text
33
  *.zst filter=lfs diff=lfs merge=lfs -text
34
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
32
  *.zip filter=lfs diff=lfs merge=lfs -text
33
  *.zst filter=lfs diff=lfs merge=lfs -text
34
  *tfevents* filter=lfs diff=lfs merge=lfs -text
35
+ *.png filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ __pycache__
2
+ .vscode
README.md CHANGED
@@ -1,13 +1,12 @@
1
  ---
2
  title: Gallery
3
- emoji: 🦀
4
- colorFrom: purple
5
  colorTo: blue
6
  sdk: streamlit
7
  sdk_version: 1.17.0
8
  app_file: app.py
9
- pinned: false
10
  license: apache-2.0
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
  title: Gallery
3
+ emoji: 🖼️
4
+ colorFrom: green
5
  colorTo: blue
6
  sdk: streamlit
7
  sdk_version: 1.17.0
8
  app_file: app.py
9
+ pinned: true
10
  license: apache-2.0
11
  ---
12
 
 
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+
3
+ import streamlit as st
4
+ import numpy as np
5
+
6
+
7
+ @st.experimental_singleton # type: ignore
8
+ def get_image_list():
9
+
10
+ image_dir = Path(__file__).parent.resolve() / "images"
11
+ return list(image_dir.glob("*.png"))
12
+
13
+
14
+ def overflow_text(text: str, max_width: int):
15
+ return text if len(text) <= max_width - 3 else f"{text[:max_width - 3]}..."
16
+
17
+
18
+ def read_png(path: Path):
19
+ from png import Reader
20
+
21
+ with path.open("rb") as f:
22
+ reader = Reader(file=f)
23
+ width, height, pixels, metadata = reader.read_flat()
24
+ data = np.array(pixels).reshape(height, width, metadata["planes"])
25
+ parameters = (metadata["text"] or {}).get("parameters")
26
+ return width, height, data, parameters
27
+
28
+
29
+ image_list = get_image_list()
30
+
31
+ with st.sidebar:
32
+ image_path = st.radio(
33
+ "Select an image", image_list, format_func=lambda p: overflow_text(p.name, 30)
34
+ )
35
+
36
+ if image_path:
37
+ width, height, image, parameters = read_png(image_path)
38
+ st.image(
39
+ image, use_column_width="auto", caption=f"{image_path.name} ({width}x{height})"
40
+ )
41
+ if parameters:
42
+ st.write("Parameters:")
43
+ st.code(parameters, language="text")
png.py ADDED
The diff for this file is too large to render. See raw diff
 
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ numpy