shreyasiv commited on
Commit
0dcc24a
1 Parent(s): 6245223

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +106 -0
  2. requirements.txt +66 -0
app.py ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import cv2
3
+ from PIL import Image
4
+ import os
5
+ import requests
6
+ from io import BytesIO
7
+ from dotenv import load_dotenv
8
+
9
+ # Load environment variables from .env file
10
+ load_dotenv()
11
+
12
+ # Your Google API Key from the .env file
13
+ GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
14
+
15
+ st.set_page_config(page_title="Insightly")
16
+ st.sidebar.image("https://i.ibb.co/bX6GdqG/insightly-wbg.png", use_column_width=True)
17
+ st.title("Frame Capturer 📸")
18
+ uploaded_video = st.file_uploader("Choose video", type=["mp4", "mov"])
19
+ frame_skip = 150 # display every 150 frames
20
+
21
+ # Add custom CSS to increase space between images
22
+ st.markdown(
23
+ """
24
+ <style>
25
+ .image-container {
26
+ margin-bottom: 60px;
27
+ }
28
+ .sidebar-link {
29
+ display: flex;
30
+ justify-content: left;
31
+ font-size: 24px;
32
+ margin-top: 20px;
33
+ }
34
+ </style>
35
+ """,
36
+ unsafe_allow_html=True,
37
+ )
38
+
39
+ # Function to perform reverse image search using the Google API
40
+ def reverse_image_search(image_bytes):
41
+ url = "https://www.googleapis.com/customsearch/v1"
42
+ params = {
43
+ "key": GOOGLE_API_KEY,
44
+ "cx": "015419011015122782581:_3y6h7e8b9q",
45
+ "q": "image",
46
+ "searchType": "image",
47
+ "imgSize": "large",
48
+ "num": 5,
49
+ }
50
+
51
+ response = requests.post(url, params=params, files={"file": image_bytes})
52
+ if response.ok:
53
+ data = response.json()
54
+ return data.get("items", [])
55
+ else:
56
+ return []
57
+
58
+ if uploaded_video is not None: # run only when the user uploads a video
59
+ vid = uploaded_video.name
60
+ with open(vid, mode='wb') as f:
61
+ f.write(uploaded_video.read()) # save video to disk
62
+
63
+ st.markdown(f"""
64
+ ### Files
65
+ - {vid}
66
+ """,
67
+ unsafe_allow_html=True) # display file name
68
+
69
+ vidcap = cv2.VideoCapture(vid) # load video from disk
70
+ cur_frame = 0
71
+ success = True
72
+
73
+ while success:
74
+ success, frame = vidcap.read() # get the next frame from the video
75
+ if cur_frame % frame_skip == 0: # only analyze every n=300 frames
76
+ print('frame: {}'.format(cur_frame))
77
+ frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) # convert BGR to RGB
78
+ pil_img = Image.fromarray(frame_rgb) # convert the OpenCV frame (with type()==numpy) into PIL Image
79
+
80
+ # Add custom class to the image container for applying CSS
81
+ st.image(pil_img, channels='RGB', use_column_width=True, caption=f"Frame {cur_frame}")
82
+
83
+ # Get the bytes of the current image
84
+ image_bytes = BytesIO()
85
+ pil_img.save(image_bytes, format="JPEG")
86
+
87
+ if st.button("Reverse Image Search", key=f"search_{cur_frame}"):
88
+ results = reverse_image_search(image_bytes.getvalue())
89
+ if results:
90
+ st.markdown("### Reverse Image Search Results:")
91
+ for result in results:
92
+ st.image(result["link"], use_column_width=True, caption=result["title"])
93
+
94
+ st.markdown(
95
+ """
96
+ <div class="image-container"></div>
97
+ """,
98
+ unsafe_allow_html=True,
99
+ )
100
+
101
+ cur_frame += 1
102
+
103
+ # Add link to the sidebar
104
+ st.sidebar.markdown("<p class='sidebar-link'>📈 <a href='https://insightly-csv-bot.hf.space/'> Insightly - CSV Bot</a></p>", unsafe_allow_html=True)
105
+ st.sidebar.markdown("<p class='sidebar-link'>📚 <a href='https://chandrakalagowda-demo2.hf.space/'> Insightly - PDF Bot </a></p>", unsafe_allow_html=True)
106
+ st.sidebar.markdown("<p class='sidebar-link'>🖼️ <a href='https://insightly-image-reader.hf.space'> Insightly - Image Reader</a></p>", unsafe_allow_html=True)
requirements.txt ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ altair==5.0.1
2
+ attrs==23.1.0
3
+ blinker==1.6.2
4
+ cachetools==5.3.1
5
+ certifi==2023.5.7
6
+ charset-normalizer==3.2.0
7
+ click==8.1.6
8
+ colorama==0.4.6
9
+ decorator==5.1.1
10
+ gitdb==4.0.10
11
+ GitPython==3.1.32
12
+ google-api-core==2.11.1
13
+ google-api-python-client==2.48.0
14
+ google-auth==2.22.0
15
+ google-auth-httplib2==0.1.0
16
+ Google-Images-Search==1.4.6
17
+ googleapis-common-protos==1.59.1
18
+ httplib2==0.22.0
19
+ idna==3.4
20
+ importlib-metadata==6.8.0
21
+ Jinja2==3.1.2
22
+ jsonschema==4.18.4
23
+ jsonschema-specifications==2023.7.1
24
+ markdown-it-py==3.0.0
25
+ MarkupSafe==2.1.3
26
+ mdurl==0.1.2
27
+ numpy==1.25.1
28
+ opencv-python==4.8.0.74
29
+ packaging==23.1
30
+ pandas==2.0.3
31
+ Pillow==9.5.0
32
+ protobuf==4.23.4
33
+ pyarrow==12.0.1
34
+ pyasn1==0.5.0
35
+ pyasn1-modules==0.3.0
36
+ pydeck==0.8.1b0
37
+ pyfiglet==0.8.post1
38
+ Pygments==2.15.1
39
+ Pympler==1.0.1
40
+ pyparsing==3.1.0
41
+ python-dateutil==2.8.2
42
+ python-dotenv==1.0.0
43
+ python-resize-image==1.1.20
44
+ pytz==2023.3
45
+ pytz-deprecation-shim==0.1.0.post0
46
+ referencing==0.30.0
47
+ requests==2.31.0
48
+ rich==13.4.2
49
+ rpds-py==0.9.2
50
+ rsa==4.9
51
+ six==1.16.0
52
+ smmap==5.0.0
53
+ streamlit==1.24.1
54
+ tenacity==8.2.2
55
+ termcolor==1.1.0
56
+ toml==0.10.2
57
+ toolz==0.12.0
58
+ tornado==6.3.2
59
+ typing_extensions==4.7.1
60
+ tzdata==2023.3
61
+ tzlocal==4.3.1
62
+ uritemplate==4.1.1
63
+ urllib3==1.26.16
64
+ validators==0.20.0
65
+ watchdog==3.0.0
66
+ zipp==3.16.2