shreyanshjha0709 commited on
Commit
90909c6
·
verified ·
1 Parent(s): bf2578c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -8
app.py CHANGED
@@ -1,12 +1,13 @@
1
  import streamlit as st
2
  import requests
3
- from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
 
4
 
5
  # Load model and tokenizer
6
  @st.cache_resource
7
  def load_model():
8
- model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-large")
9
- tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-large")
10
  return model, tokenizer
11
 
12
  model, tokenizer = load_model()
@@ -34,7 +35,6 @@ selected_brand = st.selectbox("Select a Brand", ["Select"] + brands)
34
  if selected_brand != "Select":
35
  watches = [item["name"] for item in data if item["brand"] == selected_brand]
36
  skus = [item["sku"] for item in data if item["brand"] == selected_brand]
37
-
38
  selected_watch = st.selectbox("Select Watch Name (Optional)", ["Select"] + watches)
39
  selected_sku = st.selectbox("Select SKU (Optional)", ["Select"] + skus)
40
 
@@ -56,14 +56,12 @@ if selected_brand != "Select":
56
  "casesize": watch_data.get("casesize", "Unknown Case Size"),
57
  "movement": watch_data.get("movement", "Unknown Movement"),
58
  "gender": watch_data.get("gender", "Unknown Gender"),
59
- # Add more attributes as needed
60
  }
61
-
62
  input_text = f"Brand: {attributes['brand']}, Watch Name: {attributes['name']}, SKU: {attributes['sku']}, Features: {attributes['features']}, Case Size: {attributes['casesize']}, Movement: {attributes['movement']}, Gender: {attributes['gender']}"
63
 
64
  # Tokenize input and generate description
65
- inputs = tokenizer(input_text, return_tensors="pt")
66
- outputs = model.generate(**inputs)
67
 
68
  # Decode generated text
69
  description = tokenizer.decode(outputs[0], skip_special_tokens=True)
@@ -71,5 +69,38 @@ if selected_brand != "Select":
71
  # Display the result
72
  st.write("### Generated Description")
73
  st.write(description)
 
 
 
 
74
  else:
75
  st.warning("Please select a brand.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  import requests
3
+ import json
4
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
5
 
6
  # Load model and tokenizer
7
  @st.cache_resource
8
  def load_model():
9
+ model = AutoModelForSeq2SeqLM.from_pretrained("shreyanshjha0709/watch-description-generator")
10
+ tokenizer = AutoTokenizer.from_pretrained("shreyanshjha0709/watch-description-generator")
11
  return model, tokenizer
12
 
13
  model, tokenizer = load_model()
 
35
  if selected_brand != "Select":
36
  watches = [item["name"] for item in data if item["brand"] == selected_brand]
37
  skus = [item["sku"] for item in data if item["brand"] == selected_brand]
 
38
  selected_watch = st.selectbox("Select Watch Name (Optional)", ["Select"] + watches)
39
  selected_sku = st.selectbox("Select SKU (Optional)", ["Select"] + skus)
40
 
 
56
  "casesize": watch_data.get("casesize", "Unknown Case Size"),
57
  "movement": watch_data.get("movement", "Unknown Movement"),
58
  "gender": watch_data.get("gender", "Unknown Gender"),
 
59
  }
 
60
  input_text = f"Brand: {attributes['brand']}, Watch Name: {attributes['name']}, SKU: {attributes['sku']}, Features: {attributes['features']}, Case Size: {attributes['casesize']}, Movement: {attributes['movement']}, Gender: {attributes['gender']}"
61
 
62
  # Tokenize input and generate description
63
+ inputs = tokenizer(input_text, return_tensors="pt", max_length=512, truncation=True)
64
+ outputs = model.generate(**inputs, max_length=150, num_return_sequences=1)
65
 
66
  # Decode generated text
67
  description = tokenizer.decode(outputs[0], skip_special_tokens=True)
 
69
  # Display the result
70
  st.write("### Generated Description")
71
  st.write(description)
72
+
73
+ # Display watch details
74
+ st.write("### Watch Details")
75
+ st.json(json.dumps(watch_data, indent=2))
76
  else:
77
  st.warning("Please select a brand.")
78
+
79
+ # Add some information about the app
80
+ st.sidebar.title("About")
81
+ st.sidebar.info(
82
+ "This app uses a fine-tuned AI model to generate descriptions for watches. "
83
+ "Select a brand and a watch to get started. The model will generate a unique "
84
+ "description based on the watch's attributes."
85
+ )
86
+
87
+ # Add a footer
88
+ st.markdown(
89
+ """
90
+ <style>
91
+ .footer {
92
+ position: fixed;
93
+ left: 0;
94
+ bottom: 0;
95
+ width: 100%;
96
+ background-color: #f1f1f1;
97
+ color: black;
98
+ text-align: center;
99
+ }
100
+ </style>
101
+ <div class="footer">
102
+ <p>Developed with ❤️ by Your Name</p>
103
+ </div>
104
+ """,
105
+ unsafe_allow_html=True
106
+ )