shreyanshjha0709 commited on
Commit
fbc2796
·
verified ·
1 Parent(s): 70c47bc

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -0
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.")