shreyanshjha0709 commited on
Commit
27419d7
·
verified ·
1 Parent(s): dc02cf0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -3
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import streamlit as st
2
  import requests
 
3
  import json
4
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
5
 
@@ -25,6 +26,21 @@ data = load_json_from_url(json_url)
25
  # Extract unique brands
26
  brands = sorted(list(set([item["brand"] for item in data])))
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  # Streamlit UI
29
  st.title("Watch Description Generator")
30
 
@@ -51,7 +67,19 @@ if selected_brand != "Select":
51
  if image_url:
52
  st.image(image_url, caption=f"{watch_data['name']} Image")
53
 
54
- # Attributes without price
 
 
 
 
 
 
 
 
 
 
 
 
55
  attributes = {
56
  "brand": watch_data["brand"],
57
  "name": watch_data.get("name", "Unknown Watch"),
@@ -66,7 +94,7 @@ if selected_brand != "Select":
66
  "strap_material": watch_data.get("strap_material", "Unknown Strap Material")
67
  }
68
 
69
- # Create a detailed description prompt following your preferred style
70
  input_text = f"""Generate a detailed 100-word description for the following watch:
71
  Brand: {attributes['brand']}
72
  Name: {attributes['name']}
@@ -80,6 +108,9 @@ Power Reserve: {attributes['power_reserve']}
80
  Dial Color: {attributes['dial_color']}
81
  Strap Material: {attributes['strap_material']}
82
 
 
 
 
83
  Description: Provide a luxurious, detailed description focusing on the craftsmanship, innovation, and design, similar to a high-end editorial style."""
84
 
85
  # Tokenize input and generate description
@@ -109,7 +140,7 @@ st.sidebar.title("About")
109
  st.sidebar.info(
110
  "This app uses a fine-tuned AI model to generate descriptions for watches. "
111
  "Select a brand and a watch to get started. The model will generate a unique "
112
- "description based on the watch's attributes."
113
  )
114
 
115
  # Add a footer
 
1
  import streamlit as st
2
  import requests
3
+ from bs4 import BeautifulSoup
4
  import json
5
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
6
 
 
26
  # Extract unique brands
27
  brands = sorted(list(set([item["brand"] for item in data])))
28
 
29
+ # Web Scraping function to get product description from Ethos website
30
+ def scrape_ethos_description(product_link):
31
+ try:
32
+ response = requests.get(product_link)
33
+ soup = BeautifulSoup(response.text, 'html.parser')
34
+
35
+ # Assuming product description is within a specific class or ID, find it
36
+ description = soup.find('div', class_='product-description') # Example class, adjust based on actual site structure
37
+ if description:
38
+ return description.get_text(strip=True)
39
+ else:
40
+ return "No detailed description available on Ethos site."
41
+ except Exception as e:
42
+ return f"Error fetching details from Ethos site: {str(e)}"
43
+
44
  # Streamlit UI
45
  st.title("Watch Description Generator")
46
 
 
67
  if image_url:
68
  st.image(image_url, caption=f"{watch_data['name']} Image")
69
 
70
+ # Get the Ethos product link for web scraping (assuming 'url' key exists in your JSON)
71
+ product_link = watch_data.get("url", None)
72
+ if product_link:
73
+ st.write(f"Fetching details from: [Product Page]({product_link})")
74
+
75
+ # Scrape Ethos product page for more description
76
+ ethos_description = scrape_ethos_description(product_link)
77
+ st.write("### Ethos Product Description")
78
+ st.write(ethos_description)
79
+ else:
80
+ st.warning("No Ethos link available for this SKU.")
81
+
82
+ # Generate watch description based on attributes and scraped content
83
  attributes = {
84
  "brand": watch_data["brand"],
85
  "name": watch_data.get("name", "Unknown Watch"),
 
94
  "strap_material": watch_data.get("strap_material", "Unknown Strap Material")
95
  }
96
 
97
+ # Create a detailed description prompt combining scraped content and attributes
98
  input_text = f"""Generate a detailed 100-word description for the following watch:
99
  Brand: {attributes['brand']}
100
  Name: {attributes['name']}
 
108
  Dial Color: {attributes['dial_color']}
109
  Strap Material: {attributes['strap_material']}
110
 
111
+ Additional details from Ethos:
112
+ {ethos_description}
113
+
114
  Description: Provide a luxurious, detailed description focusing on the craftsmanship, innovation, and design, similar to a high-end editorial style."""
115
 
116
  # Tokenize input and generate description
 
140
  st.sidebar.info(
141
  "This app uses a fine-tuned AI model to generate descriptions for watches. "
142
  "Select a brand and a watch to get started. The model will generate a unique "
143
+ "description based on the watch's attributes and additional details."
144
  )
145
 
146
  # Add a footer