Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,54 +1,56 @@
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
3 |
-
import requests
|
4 |
-
from bs4 import BeautifulSoup
|
5 |
-
import torch
|
6 |
|
7 |
-
# Load
|
8 |
-
|
9 |
-
|
10 |
-
model = AutoModelForSeq2SeqLM.from_pretrained(
|
|
|
|
|
11 |
|
12 |
-
|
13 |
-
def generate_description(input_text):
|
14 |
-
inputs = tokenizer(input_text, return_tensors="pt", max_length=512, truncation=True)
|
15 |
-
outputs = model.generate(inputs["input_ids"], max_length=200)
|
16 |
-
description = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
17 |
-
return description
|
18 |
|
19 |
-
#
|
20 |
-
|
21 |
-
search_url = f"https://www.google.com/search?q={brand_name}+{sku}"
|
22 |
-
headers = {
|
23 |
-
"User-Agent": "Mozilla/5.0"
|
24 |
-
}
|
25 |
-
response = requests.get(search_url, headers=headers)
|
26 |
-
soup = BeautifulSoup(response.text, 'html.parser')
|
27 |
-
|
28 |
-
# For demonstration, just fetch the first URL (modify as per your requirement)
|
29 |
-
link = soup.find('a')['href']
|
30 |
-
return link
|
31 |
|
32 |
-
#
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
-
#
|
36 |
-
|
|
|
|
|
37 |
watch_name = st.text_input("Enter Watch Name")
|
38 |
-
sku = st.text_input("Enter
|
39 |
|
40 |
# Button to generate description
|
41 |
if st.button("Generate Description"):
|
42 |
-
if
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
#
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
|
|
53 |
else:
|
54 |
-
st.
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, pipeline
|
|
|
|
|
|
|
3 |
|
4 |
+
# Load model and tokenizer
|
5 |
+
@st.cache_resource
|
6 |
+
def load_model():
|
7 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-large")
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-large")
|
9 |
+
return model, tokenizer
|
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)")
|