shreyanshjha0709 commited on
Commit
93e2204
·
verified ·
1 Parent(s): 9038d0b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -43
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 the pretrained model and tokenizer
8
- MODEL_NAME = "google/flan-t5-large"
9
- tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
10
- model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_NAME)
 
 
11
 
12
- # Function to generate text description
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
- # Function to scrape brand website
20
- def scrape_brand_website(brand_name, sku):
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
- # Streamlit App
33
- st.title("Watch Description Generator & Brand Scout")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
- # Inputs for watch details
36
- brand_name = st.text_input("Enter Brand Name")
 
 
37
  watch_name = st.text_input("Enter Watch Name")
38
- sku = st.text_input("Enter Watch SKU")
39
 
40
  # Button to generate description
41
  if st.button("Generate Description"):
42
- if brand_name and watch_name and sku:
43
- # Generate description using the model
44
- input_text = f"Watch Name: {watch_name}, Brand: {brand_name}, SKU: {sku}"
45
- generated_description = generate_description(input_text)
46
- st.write("Generated Description:")
47
- st.write(generated_description)
48
-
49
- # Scrape brand website for relevant information
50
- st.write("Fetching Brand Website...")
51
- brand_link = scrape_brand_website(brand_name, sku)
52
- st.write(f"Brand Website: {brand_link}")
 
 
53
  else:
54
- st.warning("Please fill in all fields.")
 
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)")