Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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)
|
51 |
if image_url:
|
52 |
st.image(image_url, caption=f"{watch_data['name']} Image")
|
53 |
|
54 |
-
#
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
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 |
-
|
82 |
-
|
|
|
|
|
|
|
83 |
|
84 |
Description:"""
|
85 |
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
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 |
|