Sanj12 commited on
Commit
f4a52a3
Β·
verified Β·
1 Parent(s): f26bba0

Update streamlit_app.py

Browse files
Files changed (1) hide show
  1. streamlit_app.py +61 -57
streamlit_app.py CHANGED
@@ -1,57 +1,61 @@
1
- import streamlit as st
2
- from tagger import generate_tags, generate_caption
3
- from style_classifier import load_model, predict_style
4
- from search import find_similar_images
5
- from db_sqlite import init_db, save_metadata
6
- import os
7
- import json
8
- from cloudinary_utils import upload_to_cloudinary
9
-
10
-
11
- # πŸ“¦ Init DB + Load style model
12
- init_db()
13
- with open("models/style_classes.json") as f:
14
- STYLE_CLASSES = json.load(f)
15
- style_model = load_model("models/style_model_hf.pth", STYLE_CLASSES)
16
-
17
- st.title("🎨 Curato - AI Art Tagger")
18
-
19
- uploaded_file = st.file_uploader("Upload an artwork", type=["jpg", "png", "jpeg"])
20
-
21
- if uploaded_file:
22
- temp_path = os.path.join("data", uploaded_file.name)
23
- with open(temp_path, "wb") as f:
24
- f.write(uploaded_file.getvalue())
25
-
26
- st.image(temp_path, caption="Uploaded Artwork", use_container_width=True)
27
-
28
- with st.spinner("Analyzing artwork..."):
29
- tags = generate_tags(temp_path)
30
- style = predict_style(temp_path, style_model, STYLE_CLASSES)
31
- caption = generate_caption(temp_path)
32
-
33
- st.success("Results:")
34
- st.write("🎨 **Art Style:**", style)
35
- st.write("🏷️ **Tags:**", tags)
36
- st.write("πŸ“ **Caption:**", caption)
37
- cloud_url = upload_to_cloudinary(temp_path)
38
- st.write("🌐 **Cloudinary URL:**", cloud_url)
39
-
40
-
41
- # πŸ’Ύ Save to SQLite
42
- save_metadata(uploaded_file.name, style, tags, caption, cloud_url)
43
-
44
-
45
- # πŸ” Image-to-Image Search
46
- st.markdown("---")
47
- st.subheader("πŸ” Visually Similar Artworks")
48
-
49
- matches = find_similar_images(temp_path, top_k=5)
50
-
51
- if matches:
52
- cols = st.columns(len(matches))
53
- for col, (fname, score) in zip(cols, matches):
54
- img_path = os.path.join("gallery", fname)
55
- col.image(img_path, caption=f"{fname} (Score: {score:.2f})", use_container_width=True)
56
- else:
57
- st.info("No similar artworks found.")
 
 
 
 
 
1
+ import streamlit as st
2
+ from tagger import generate_tags, generate_caption
3
+ from style_classifier import load_model, predict_style
4
+ from search import find_similar_images
5
+ from db_sqlite import init_db, save_metadata
6
+ import os
7
+ import json
8
+ from cloudinary_utils import upload_to_cloudinary
9
+ import os
10
+
11
+ # πŸ“¦ Init DB + Load style model
12
+ init_db()
13
+ with open("models/style_classes.json") as f:
14
+ STYLE_CLASSES = json.load(f)
15
+ style_model = load_model("models/style_model_hf.pth", STYLE_CLASSES)
16
+
17
+ st.title("🎨 Curato - AI Art Tagger")
18
+
19
+ uploaded_file = st.file_uploader("Upload an artwork", type=["jpg", "png", "jpeg"])
20
+
21
+ if uploaded_file:
22
+ os.makedirs("data", exist_ok=True) # βœ… Make sure 'data/' exists
23
+
24
+ temp_path = os.path.join("data", uploaded_file.name)
25
+
26
+ with open(temp_path, "wb") as f:
27
+ f.write(uploaded_file.getvalue())
28
+
29
+
30
+ st.image(temp_path, caption="Uploaded Artwork", use_container_width=True)
31
+
32
+ with st.spinner("Analyzing artwork..."):
33
+ tags = generate_tags(temp_path)
34
+ style = predict_style(temp_path, style_model, STYLE_CLASSES)
35
+ caption = generate_caption(temp_path)
36
+
37
+ st.success("Results:")
38
+ st.write("🎨 **Art Style:**", style)
39
+ st.write("🏷️ **Tags:**", tags)
40
+ st.write("πŸ“ **Caption:**", caption)
41
+ cloud_url = upload_to_cloudinary(temp_path)
42
+ st.write("🌐 **Cloudinary URL:**", cloud_url)
43
+
44
+
45
+ # πŸ’Ύ Save to SQLite
46
+ save_metadata(uploaded_file.name, style, tags, caption, cloud_url)
47
+
48
+
49
+ # πŸ” Image-to-Image Search
50
+ st.markdown("---")
51
+ st.subheader("πŸ” Visually Similar Artworks")
52
+
53
+ matches = find_similar_images(temp_path, top_k=5)
54
+
55
+ if matches:
56
+ cols = st.columns(len(matches))
57
+ for col, (fname, score) in zip(cols, matches):
58
+ img_path = os.path.join("gallery", fname)
59
+ col.image(img_path, caption=f"{fname} (Score: {score:.2f})", use_container_width=True)
60
+ else:
61
+ st.info("No similar artworks found.")