-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroboflowdataClean.py
More file actions
68 lines (55 loc) · 2.5 KB
/
Copy pathroboflowdataClean.py
File metadata and controls
68 lines (55 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import streamlit as st
import pandas as pd
import json
from io import StringIO
st.set_page_config(
page_title="ECGO Brand Flavor Data Extractor",
page_icon="🍹",
layout="wide"
)
st.title("📦 ECGO Product Data Brand + Flavor Parser ~ Roboflow")
st.markdown("Convert your COCO-exported Roboflow dataset into a clean, structured CSV with **Brand Names** and **Flavor Tags** 🍫🥤")
st.markdown("---")
uploaded_file = st.file_uploader("📁 Upload your `_annotations.coco.json` file", type="json")
if uploaded_file:
st.markdown("✅ File uploaded successfully! Parsing...")
data = json.load(uploaded_file)
# Extract brand names from categories
brand_lookup = {c['id']: c['name'] for c in data.get("categories", [])}
# Map image IDs to filenames and user_tags (flavors)
image_lookup = {}
for img in data.get("images", []):
image_lookup[img['id']] = {
'filename': img.get('extra', {}).get('name', img['file_name']),
'tags': img.get('extra', {}).get('user_tags', [])
}
# Map image IDs to brand names via annotations
brand_map = {}
for ann in data.get("annotations", []):
img_id = ann.get('image_id')
cat_id = ann.get('category_id')
brand = brand_lookup.get(cat_id, "Unknown")
brand_map.setdefault(img_id, set()).add(brand)
# Build final structured data
structured_data = []
for img_id, info in image_lookup.items():
if img_id not in brand_map: # Skip if no brand label exists
continue
row = {
"📸 Filename": info['filename'],
"🏷️ Brand Name": ", ".join(sorted(brand_map.get(img_id, [])))
}
# Add flavor tags as Flavor 1, Flavor 2, ...
for i, tag in enumerate(info['tags']):
row[f"🍬 Flavor {i+1}"] = tag
structured_data.append(row)
df = pd.DataFrame(structured_data)
st.success("🎉 Successfully parsed JSON and generated structured data!")
st.markdown("### 🧾 Preview of Output Table")
st.dataframe(df, use_container_width=True)
csv = df.to_csv(index=False).encode('utf-8')
st.download_button("⬇️ Download CSV", csv, file_name="brand_flavor_data.csv", mime='text/csv')
else:
st.info("👆 Upload your COCO JSON file above to get started!")
st.markdown("---")
st.markdown("<div style='text-align: center; color: gray;'>Made with ❤️ by the ECGO Data Analysis Team</div>", unsafe_allow_html=True)