feature to directly paste link of insta post and get the product listing details added.

#7
by RatanPrakash - opened
Files changed (1) hide show
  1. app.py +37 -0
app.py CHANGED
@@ -11,6 +11,22 @@ import dateparser
11
  import os
12
  import matplotlib.pyplot as plt
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  # Initialize PaddleOCR model
15
  ocr = PaddleOCR(use_angle_cls=True, lang='en')
16
  # Define the class names based on your dataset
@@ -256,6 +272,27 @@ elif app_mode == "Team Details":
256
  elif app_mode == "Task 1":
257
  st.write("## Task 1: ๐Ÿ–ผ๏ธ OCR to Extract Details ๐Ÿ“„")
258
  st.write("Using OCR to extract details from product packaging material, including brand name and pack size.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
259
 
260
  # File uploader for images (supports multiple files)
261
  uploaded_files = st.file_uploader("Upload images of products", type=["jpeg", "png", "jpg"], accept_multiple_files=True)
 
11
  import os
12
  import matplotlib.pyplot as plt
13
 
14
+ # Function to get Instagram post details
15
+ import instaloader
16
+ def get_instagram_post_details(post_url):
17
+ try:
18
+ shortcode = post_url.split('/')[-2]
19
+ post = instaloader.Post.from_shortcode(L.context, shortcode)
20
+
21
+ # Retrieve caption and image URL
22
+ caption = post.caption
23
+ image_url = post.url
24
+
25
+ return caption, image_url
26
+ except Exception as e:
27
+ return str(e), None
28
+
29
+
30
  # Initialize PaddleOCR model
31
  ocr = PaddleOCR(use_angle_cls=True, lang='en')
32
  # Define the class names based on your dataset
 
272
  elif app_mode == "Task 1":
273
  st.write("## Task 1: ๐Ÿ–ผ๏ธ OCR to Extract Details ๐Ÿ“„")
274
  st.write("Using OCR to extract details from product packaging material, including brand name and pack size.")
275
+
276
+
277
+ # Instantiate Instaloader
278
+ L = instaloader.Instaloader()
279
+
280
+ # Streamlit UI
281
+ st.title("Instagram Post Details Extractor")
282
+
283
+ # Text input for Instagram post URL
284
+ post_url = st.text_input("Enter Instagram Post URL:")
285
+
286
+ if post_url:
287
+ caption, image_url = get_instagram_post_details(post_url)
288
+
289
+ if image_url:
290
+ st.subheader("Caption:")
291
+ st.write(caption)
292
+ st.subheader("Image:")
293
+ st.image(image_url, use_column_width=True)
294
+ else:
295
+ st.error("Failed to retrieve the post details. Please check the URL.")
296
 
297
  # File uploader for images (supports multiple files)
298
  uploaded_files = st.file_uploader("Upload images of products", type=["jpeg", "png", "jpg"], accept_multiple_files=True)