shreyanshjha0709 commited on
Commit
5d087ca
·
verified ·
1 Parent(s): 93e2204

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -43
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import streamlit as st
2
- from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, pipeline
 
3
 
4
  # Load model and tokenizer
5
  @st.cache_resource
@@ -10,47 +11,64 @@ def load_model():
10
 
11
  model, tokenizer = load_model()
12
 
13
- # Streamlit interface
 
 
 
 
 
 
 
 
 
 
 
 
14
  st.title("Watch Description Generator")
15
 
16
- # List of watch brands from the provided image (excluding "View All")
17
- brands = [
18
- "Rolex", "Alpina", "Angelus", "Armin Strom", "Arnold & Son", "Baume & Mercier",
19
- "Bell & Ross", "Bianchet", "Bovet", "Breitling", "Bremont", "BVLGARI",
20
- "Carl F. Bucherer", "Chronoswiss", "CIGA Design", "Corum", "Cuervo y Sobrinos",
21
- "CVSTOS", "Czapek", "Doxa", "Eberhard & Co.", "Edox", "Ernest Borel", "Eterna",
22
- "Favre Leuba", "Frederique Constant", "Gerald Charles", "Girard-Perregaux",
23
- "Graham", "Grand Seiko", "H. Moser & Cie.", "Hublot", "Ikepod", "IWC Schaffhausen",
24
- "Jacob & Co.", "Jaeger-LeCoultre", "Junghans", "Laurent Ferrier", "Longines",
25
- "Louis Erard", "Louis Moinet", "Luminox", "Maserati", "Maurice Lacroix",
26
- "MeisterSinger", "Mühle-Glashütte", "Nivada Grenchen", "Nomos Glashutte",
27
- "NORQAIN", "Omega", "Oris", "Panerai", "Parmigiani", "Perrelet", "Rado",
28
- "Raymond Weil", "Ressence", "Seiko", "Speake-Marin", "TAG Heuer", "Tissot",
29
- "Titoni", "Trilobe", "Tudor", "Tutima Glashütte", "Ulysse Nardin", "Urwerk",
30
- "Zenith", "Zeppelin"
31
- ]
32
-
33
- # Create dropdown for selecting the brand
34
- selected_brand = st.selectbox("Select a Brand", brands)
35
-
36
- # Input fields for Watch Name and SKU
37
- watch_name = st.text_input("Enter Watch Name")
38
- sku = st.text_input("Enter SKU")
39
-
40
- # Button to generate description
41
- if st.button("Generate Description"):
42
- if watch_name and sku and selected_brand:
43
- input_text = f"Brand: {selected_brand}, Watch Name: {watch_name}, SKU: {sku}"
44
-
45
- # Tokenize input and generate description
46
- inputs = tokenizer(input_text, return_tensors="pt")
47
- outputs = model.generate(**inputs)
48
-
49
- # Decode generated text
50
- description = tokenizer.decode(outputs[0], skip_special_tokens=True)
51
-
52
- # Display the result
53
- st.write("### Generated Description")
54
- st.write(description)
55
- else:
56
- st.error("Please enter all details (brand, watch name, and SKU)")
 
 
 
 
 
 
1
  import streamlit as st
2
+ import json
3
+ from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
4
 
5
  # Load model and tokenizer
6
  @st.cache_resource
 
11
 
12
  model, tokenizer = load_model()
13
 
14
+ # Load the JSON file
15
+ @st.cache_data
16
+ def load_json():
17
+ with open('watches_data.json') as f: # Your JSON file name
18
+ data = json.load(f)
19
+ return data
20
+
21
+ data = load_json()
22
+
23
+ # Extract unique brands
24
+ brands = sorted(list(set([item["brand"] for item in data])))
25
+
26
+ # Streamlit UI
27
  st.title("Watch Description Generator")
28
 
29
+ # Select brand
30
+ selected_brand = st.selectbox("Select a Brand", ["Select"] + brands)
31
+
32
+ # Filter watches and SKUs by the selected brand
33
+ if selected_brand != "Select":
34
+ watches = [item["name"] for item in data if item["brand"] == selected_brand]
35
+ skus = [item["sku"] for item in data if item["brand"] == selected_brand]
36
+
37
+ selected_watch = st.selectbox("Select Watch Name (Optional)", ["Select"] + watches)
38
+ selected_sku = st.selectbox("Select SKU (Optional)", ["Select"] + skus)
39
+
40
+ # Get the selected watch data from the JSON
41
+ watch_data = None
42
+ if selected_watch != "Select":
43
+ watch_data = next((item for item in data if item["name"] == selected_watch), None)
44
+ elif selected_sku != "Select":
45
+ watch_data = next((item for item in data if item["sku"] == selected_sku), None)
46
+
47
+ if watch_data:
48
+ # Generate description based on attributes
49
+ if st.button("Generate Description"):
50
+ attributes = {
51
+ "brand": watch_data["brand"],
52
+ "name": watch_data.get("name", "Unknown Watch"),
53
+ "sku": watch_data.get("sku", "Unknown SKU"),
54
+ "features": watch_data.get("features", "Unknown Features"),
55
+ "casesize": watch_data.get("casesize", "Unknown Case Size"),
56
+ "movement": watch_data.get("movement", "Unknown Movement"),
57
+ "gender": watch_data.get("gender", "Unknown Gender"),
58
+ # Add more attributes as needed
59
+ }
60
+
61
+ input_text = f"Brand: {attributes['brand']}, Watch Name: {attributes['name']}, SKU: {attributes['sku']}, Features: {attributes['features']}, Case Size: {attributes['casesize']}, Movement: {attributes['movement']}, Gender: {attributes['gender']}"
62
+
63
+ # Tokenize input and generate description
64
+ inputs = tokenizer(input_text, return_tensors="pt")
65
+ outputs = model.generate(**inputs)
66
+
67
+ # Decode generated text
68
+ description = tokenizer.decode(outputs[0], skip_special_tokens=True)
69
+
70
+ # Display the result
71
+ st.write("### Generated Description")
72
+ st.write(description)
73
+ else:
74
+ st.warning("Please select a brand.")