Spaces:
Sleeping
Sleeping
feature to directly paste link of insta post and get the product listing details added. (#7)
Browse files- feature to directly paste link of insta post and get the product listing details added. (f7c3ac83f49325e86794156ac5325119e16a8bbb)
Co-authored-by: Ratan Prakash Mishra <RatanPrakash@users.noreply.huggingface.co>
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 |
|
|
@@ -243,6 +259,27 @@ elif app_mode == "Team Details":
|
|
| 243 |
elif app_mode == "Task 1":
|
| 244 |
st.write("## Task 1: 🖼️ OCR to Extract Details 📄")
|
| 245 |
st.write("Using OCR to extract details from product packaging material, including brand name and pack size.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
|
| 247 |
# File uploader for images (supports multiple files)
|
| 248 |
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 |
|
|
|
|
| 259 |
elif app_mode == "Task 1":
|
| 260 |
st.write("## Task 1: 🖼️ OCR to Extract Details 📄")
|
| 261 |
st.write("Using OCR to extract details from product packaging material, including brand name and pack size.")
|
| 262 |
+
|
| 263 |
+
|
| 264 |
+
# Instantiate Instaloader
|
| 265 |
+
L = instaloader.Instaloader()
|
| 266 |
+
|
| 267 |
+
# Streamlit UI
|
| 268 |
+
st.title("Instagram Post Details Extractor")
|
| 269 |
+
|
| 270 |
+
# Text input for Instagram post URL
|
| 271 |
+
post_url = st.text_input("Enter Instagram Post URL:")
|
| 272 |
+
|
| 273 |
+
if post_url:
|
| 274 |
+
caption, image_url = get_instagram_post_details(post_url)
|
| 275 |
+
|
| 276 |
+
if image_url:
|
| 277 |
+
st.subheader("Caption:")
|
| 278 |
+
st.write(caption)
|
| 279 |
+
st.subheader("Image:")
|
| 280 |
+
st.image(image_url, use_column_width=True)
|
| 281 |
+
else:
|
| 282 |
+
st.error("Failed to retrieve the post details. Please check the URL.")
|
| 283 |
|
| 284 |
# File uploader for images (supports multiple files)
|
| 285 |
uploaded_files = st.file_uploader("Upload images of products", type=["jpeg", "png", "jpg"], accept_multiple_files=True)
|