shreyanshjha0709 commited on
Commit
50c822a
·
verified ·
1 Parent(s): 51621c3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -50
app.py CHANGED
@@ -47,30 +47,28 @@ if selected_brand != "Select":
47
 
48
  if watch_data:
49
  # Display the image from the JSON
50
- image_url = watch_data.get("image", None) # Assume the "image" key holds the image URL
51
  if image_url:
52
  st.image(image_url, caption=f"{watch_data['name']} Image")
53
 
54
- # Generation parameters
55
- max_length = st.slider("Max Length", min_value=100, max_value=500, value=300)
56
- temperature = st.slider("Temperature", min_value=0.1, max_value=1.0, value=0.7, step=0.1)
57
- repetition_penalty = st.slider("Repetition Penalty", min_value=1.0, max_value=2.0, value=1.2, step=0.1)
58
-
59
- # Generate description based on attributes and image
60
- if st.button("Generate Description"):
61
- attributes = {
62
- "brand": watch_data["brand"],
63
- "name": watch_data.get("name", "Unknown Watch"),
64
- "sku": watch_data.get("sku", "Unknown SKU"),
65
- "features": watch_data.get("features", "Unknown Features"),
66
- "casesize": watch_data.get("casesize", "Unknown Case Size"),
67
- "movement": watch_data.get("movement", "Unknown Movement"),
68
- "gender": watch_data.get("gender", "Unknown Gender"),
69
- "color": watch_data.get("color", "Unknown Color"), # Simulated color field
70
- }
71
-
72
- # Simulate a description that mentions the color, look, and other aspects
73
- input_text = f"""Generate a detailed description for the following watch:
74
  Brand: {attributes['brand']}
75
  Name: {attributes['name']}
76
  SKU: {attributes['sku']}
@@ -78,38 +76,33 @@ Features: {attributes['features']}
78
  Case Size: {attributes['casesize']}
79
  Movement: {attributes['movement']}
80
  Gender: {attributes['gender']}
81
- Color: {attributes['color']}
82
- Look: Based on its stunning design, as seen in the image, this watch has a {attributes['color']} finish that complements its {attributes['casesize']}mm case size. It exudes elegance and sophistication, making it perfect for {attributes['gender']} audiences. The craftsmanship seen in the movement adds to its luxurious appeal.
 
 
 
83
 
84
  Description:"""
85
 
86
- # Tokenize input and generate description
87
- inputs = tokenizer(input_text, return_tensors="pt", max_length=512, truncation=True)
88
- outputs = model.generate(
89
- **inputs,
90
- max_length=max_length,
91
- num_return_sequences=1,
92
- temperature=temperature,
93
- top_k=50,
94
- top_p=0.95,
95
- do_sample=True,
96
- repetition_penalty=repetition_penalty # Prevent repetitive descriptions
97
- )
98
-
99
- # Decode generated text
100
- description = tokenizer.decode(outputs[0], skip_special_tokens=True)
101
-
102
- # Display the result
103
- st.write("### Generated Description")
104
- st.write(description)
105
-
106
- # Display watch details
107
- st.write("### Watch Details")
108
- st.json(json.dumps(watch_data, indent=2))
109
-
110
- # Display input text for debugging
111
- st.write("### Input Text (for debugging)")
112
- st.text(input_text)
113
  else:
114
  st.warning("Please select a brand.")
115
 
 
47
 
48
  if watch_data:
49
  # Display the image from the JSON
50
+ image_url = watch_data.get("image", None)
51
  if image_url:
52
  st.image(image_url, caption=f"{watch_data['name']} Image")
53
 
54
+ # Generate description based on attributes automatically
55
+ attributes = {
56
+ "brand": watch_data["brand"],
57
+ "name": watch_data.get("name", "Unknown Watch"),
58
+ "sku": watch_data.get("sku", "Unknown SKU"),
59
+ "features": watch_data.get("features", "Unknown Features"),
60
+ "casesize": watch_data.get("casesize", "Unknown Case Size"),
61
+ "movement": watch_data.get("movement", "Unknown Movement"),
62
+ "gender": watch_data.get("gender", "Unknown Gender"),
63
+ "water_resistance": watch_data.get("water_resistance", "Unknown Water Resistance"),
64
+ "power_reserve": watch_data.get("power_reserve", "Unknown Power Reserve"),
65
+ "dial_color": watch_data.get("dial_color", "Unknown Dial Color"),
66
+ "strap_material": watch_data.get("strap_material", "Unknown Strap Material"),
67
+ "price": watch_data.get("price", "Unknown Price"),
68
+ }
69
+
70
+ # Expanded input text with more attributes, using the model as a guide for the output
71
+ input_text = f"""Generate a detailed 100-word description for the following watch:
 
 
72
  Brand: {attributes['brand']}
73
  Name: {attributes['name']}
74
  SKU: {attributes['sku']}
 
76
  Case Size: {attributes['casesize']}
77
  Movement: {attributes['movement']}
78
  Gender: {attributes['gender']}
79
+ Water Resistance: {attributes['water_resistance']}
80
+ Power Reserve: {attributes['power_reserve']}
81
+ Dial Color: {attributes['dial_color']}
82
+ Strap Material: {attributes['strap_material']}
83
+ Price: {attributes['price']}
84
 
85
  Description:"""
86
 
87
+ # Tokenize input and generate description
88
+ inputs = tokenizer(input_text, return_tensors="pt", max_length=512, truncation=True)
89
+ outputs = model.generate(
90
+ **inputs,
91
+ max_length=150, # Limit output to 100-150 words
92
+ num_return_sequences=1,
93
+ temperature=0.7,
94
+ top_k=50,
95
+ top_p=0.95,
96
+ do_sample=True,
97
+ repetition_penalty=1.2 # Prevent repetition in descriptions
98
+ )
99
+
100
+ # Decode generated text
101
+ description = tokenizer.decode(outputs[0], skip_special_tokens=True)
102
+
103
+ # Display the result
104
+ st.write("### Generated Description")
105
+ st.write(description)
 
 
 
 
 
 
 
 
106
  else:
107
  st.warning("Please select a brand.")
108