Spaces:
Runtime error
Runtime error
ahmadtalha
commited on
Upload 2 files
Browse files- app.py +37 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import cv2
|
2 |
+
import numpy as np
|
3 |
+
import streamlit as st
|
4 |
+
from PIL import Image
|
5 |
+
import streamlit_image_coordinates
|
6 |
+
|
7 |
+
def main():
|
8 |
+
prev_val = None
|
9 |
+
st.title("PySeek")
|
10 |
+
st.sidebar.title("Upload Image")
|
11 |
+
|
12 |
+
# File uploader widget
|
13 |
+
uploaded_file = st.sidebar.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
14 |
+
new_img = uploaded_file.name if uploaded_file is not None else None
|
15 |
+
# print(uploaded_file.file_id)
|
16 |
+
if uploaded_file is not None:
|
17 |
+
if uploaded_file.file_id not in st.session_state:
|
18 |
+
st.session_state[uploaded_file.file_id] = []
|
19 |
+
|
20 |
+
# Open and display the image
|
21 |
+
image = Image.open(uploaded_file)
|
22 |
+
img = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
|
23 |
+
# st.image(image, caption='Uploaded Image', use_column_width=True)
|
24 |
+
|
25 |
+
value = streamlit_image_coordinates.streamlit_image_coordinates(
|
26 |
+
# Image.open(uploaded_file),
|
27 |
+
img,
|
28 |
+
key="pil",
|
29 |
+
)
|
30 |
+
if value is not None and value != prev_val:
|
31 |
+
prev_val = value
|
32 |
+
st.session_state[uploaded_file.file_id].append((value['x'], value['y']))
|
33 |
+
if uploaded_file.file_id in st.session_state:
|
34 |
+
for val in st.session_state[uploaded_file.file_id]:
|
35 |
+
st.write(f"x: {val[0]}, y: {val[1]}")
|
36 |
+
if __name__ == "__main__":
|
37 |
+
main()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
numpy
|
2 |
+
pillow
|
3 |
+
streamlit_image_coordinates
|
4 |
+
opencv-python
|