from itertools import product import streamlit as st import numpy as np import pandas as pd from PIL import Image, ImageOps import time from paddleocr import PaddleOCR import os from dotenv import load_dotenv from huggingface_hub import login load_dotenv() # Load .env file huggingface_token = os.getenv("HF_TOKEN") login(huggingface_token) ##########################LLAMA3BI################################ from huggingface_hub import InferenceClient client = InferenceClient(api_key=huggingface_token) messages = [ {"role": "system", "content": """Your task is to get the product details out of the text given. The text given will be raw text from OCR of product images, and the goal is to get product details and description so that it can be used for e-commerce product listing. TRY TO KEEP THE LISTING IN FOLLOWING FORMAT. \ud83d\udce6 [Product Name] \ud83d\udcb0 Price: $XX.XX ✨ Key Features: • [Main Feature 1] • [Main Feature 2] • [Main Feature 3] \ud83d\udcf8 [Product Image] \ud83c\udff7 Available Now on E-commerce Platform ✈️ Fast Shipping Available \ud83d\udecd️ Shop Now: [Link] 🔍 Search: [Main Keywords] [#RelevantHashtags] """}, ] # Initialize PaddleOCR model ocr = PaddleOCR(use_angle_cls=True, lang='en') # Team details team_members = [ {"name": "Aman Deep", "image": "aman.jpg"}, {"name": "Gaurav Lodhi", "image": "anandimg.jpg"} ] # Function to display team members in circular format def display_team_members(members, max_members_per_row=4): num_members = len(members) num_rows = (num_members + max_members_per_row - 1) // max_members_per_row for i in range(num_rows): cols = st.columns(min(max_members_per_row, num_members - i * max_members_per_row)) for j, member in enumerate(members[i * max_members_per_row:(i + 1) * max_members_per_row]): with cols[j]: img = Image.open(member["image"]) st.image(img, use_column_width=True) st.write(member["name"]) # Function to simulate loading process with a progress bar def simulate_progress(): progress_bar = st.progress(0) for percent_complete in range(100): time.sleep(0.02) progress_bar.progress(percent_complete + 1) # Title and description st.title("Hacknovate 6.0") # Team Details with links st.sidebar.title("Hacknovate 6.0") st.sidebar.write("DELHI TECHNOLOGICAL UNIVERSITY") # Navbar with task tabs st.sidebar.title("Navigation") st.sidebar.write("Team Name: sadhya") app_mode = st.sidebar.selectbox("Choose the task", ["Welcome", "Project Details", "Task 1", "Team Details"]) if app_mode == "Welcome": st.write("# Welcome to Hacknovate 6.0! 🎉") video_file = open('Finalist.mp4', 'rb') video_bytes = video_file.read() st.video(video_bytes) welcome_image = Image.open("grid_banner.jpg") st.image(welcome_image, use_column_width=True) elif app_mode == "Project Details": st.write("## Project Overview: Automating Product Listings with AI") st.write("Our system extracts product details using OCR and LLMs to create structured e-commerce listings.") elif app_mode == "Team Details": st.write("## Meet Our Team:") display_team_members(team_members) st.write("Delhi Technological University") elif app_mode == "Task 1": st.write("## Task 1: 🖼️ OCR to Extract Details 📄") st.write("Using OCR to extract details from product packaging material.") uploaded_files = st.file_uploader("Upload images of products", type=["jpeg", "png", "jpg"], accept_multiple_files=True) if uploaded_files: st.write("### Uploaded Images:") for uploaded_file in uploaded_files: img = Image.open(uploaded_file) st.image(img, use_column_width=True) if st.button("Start Analysis"): simulate_progress() for uploaded_image in uploaded_files: image = Image.open(uploaded_image) img_array = np.array(image) st.write(f"Extracting details from {uploaded_image.name}...") result = ocr.ocr(img_array, cls=True) text = " ".join([box[1][0] for line in result for box in line]) st.write(f"OCR Result: {text}") simulate_progress() messages.append({"role": "user", "content": text}) completion = client.chat.completions.create( model="meta-llama/Llama-3.2-3B-Instruct", messages=messages, max_tokens=500 ) productListingContent = completion.choices[0].message st.markdown(productListingContent.content) st.markdown("---") else: st.write("Please upload images to extract product details.") st.markdown("""
""", unsafe_allow_html=True)