Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
@@ -9,38 +9,33 @@ import os
|
|
9 |
# Set up page configuration
|
10 |
st.set_page_config(page_title="ProductProse - AI Product Description Generator", layout="wide")
|
11 |
|
12 |
-
# Initialize session state to track API responses
|
13 |
if 'generated_description' not in st.session_state:
|
14 |
st.session_state.generated_description = None
|
15 |
if 'translated_description' not in st.session_state:
|
16 |
st.session_state.translated_description = None
|
17 |
if 'customized_description' not in st.session_state:
|
18 |
st.session_state.customized_description = None
|
19 |
-
if '
|
20 |
-
st.session_state.
|
21 |
|
22 |
# Sidebar for product data input
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
specifications = st.text_area("Product Specifications", placeholder="e.g., Dimensions: 10x5x3 inches, Weight: 1.5 lbs")
|
29 |
|
30 |
-
|
31 |
-
|
32 |
|
33 |
# Main app title and description
|
34 |
-
st.
|
35 |
st.markdown("""
|
36 |
Welcome to ProductProse, an AI-powered tool for generating and customizing product descriptions using IBM Granite LLMs.
|
37 |
Simply input your product data and let the AI do the rest, including generating descriptions, translating them into multiple languages, and customizing them to match your brand tone and style.
|
38 |
""")
|
39 |
|
40 |
-
# UI Enhancement: Color-coded sections for clarity
|
41 |
-
def section_header(title, color):
|
42 |
-
st.markdown(f'<h2 style="color:{color};">{title}</h2>', unsafe_allow_html=True)
|
43 |
-
|
44 |
# IBM WatsonX API Setup
|
45 |
project_id = os.getenv('WATSONX_PROJECT_ID')
|
46 |
api_key = os.getenv('WATSONX_API_KEY')
|
@@ -51,15 +46,15 @@ if api_key and project_id:
|
|
51 |
client.set.default_project(project_id)
|
52 |
|
53 |
# Tone Selection for Description Customization
|
54 |
-
tone_example = st.sidebar.selectbox("
|
55 |
-
st.sidebar.markdown("_Example:
|
56 |
|
57 |
# Keyword Input for SEO Optimization
|
58 |
-
seo_keywords_example = st.sidebar.text_area("SEO Keywords (comma-separated
|
59 |
-
st.sidebar.markdown("_Example: Add keywords
|
60 |
|
61 |
# Step 1: Generate Product Description
|
62 |
-
|
63 |
if st.button("Generate Description"):
|
64 |
if product_name and features and benefits and specifications:
|
65 |
# Prompt engineering for Granite-13B-Instruct
|
@@ -83,7 +78,6 @@ if api_key and project_id:
|
|
83 |
description_response = model.generate_text(prompt=prompt)
|
84 |
st.session_state.generated_description = description_response
|
85 |
st.session_state.translated_description = None # Clear previous translations
|
86 |
-
st.session_state.customized_description = None # Clear previous customizations
|
87 |
st.success("Product description generated!")
|
88 |
st.write(description_response)
|
89 |
except Exception as e:
|
@@ -92,7 +86,7 @@ if api_key and project_id:
|
|
92 |
st.warning("Please fill in all the product data fields before generating a description.")
|
93 |
|
94 |
# Step 2: Translate Product Description
|
95 |
-
|
96 |
if st.session_state.generated_description:
|
97 |
if st.button("Translate Description"):
|
98 |
try:
|
@@ -123,8 +117,8 @@ if api_key and project_id:
|
|
123 |
st.write(st.session_state.translated_description)
|
124 |
|
125 |
# Step 3: Customize Product Description via Chat Interface
|
126 |
-
|
127 |
-
customization_prompt = st.text_input("Customize the product description
|
128 |
|
129 |
if st.session_state.generated_description and customization_prompt:
|
130 |
if st.button("Customize Description"):
|
@@ -151,59 +145,15 @@ if api_key and project_id:
|
|
151 |
st.subheader("Customized Product Description")
|
152 |
st.write(st.session_state.customized_description)
|
153 |
|
154 |
-
# Option to translate the customized description if it hasn't been translated yet
|
155 |
-
if st.session_state.translated_description:
|
156 |
-
if st.button("Translate Customized Description"):
|
157 |
-
try:
|
158 |
-
# Translate the customized description using Granite-20B-Multilingual
|
159 |
-
prompt = f"Translate the following customized product description into {target_language}:\n{st.session_state.customized_description}"
|
160 |
-
model = ModelInference(model_id=ModelTypes.GRANITE_20B_MULTILINGUAL, params={
|
161 |
-
GenParams.DECODING_METHOD: DecodingMethods.GREEDY,
|
162 |
-
GenParams.MIN_NEW_TOKENS: 50,
|
163 |
-
GenParams.MAX_NEW_TOKENS: 200,
|
164 |
-
GenParams.STOP_SEQUENCES: ["\n"]
|
165 |
-
}, credentials=credentials, project_id=project_id)
|
166 |
-
|
167 |
-
with st.spinner(f"Translating customized product description to {target_language}..."):
|
168 |
-
customized_translation_response = model.generate_text(prompt=prompt)
|
169 |
-
st.session_state.translated_customized_description = customized_translation_response
|
170 |
-
st.success(f"Customized product description translated to {target_language}!")
|
171 |
-
st.write(customized_translation_response)
|
172 |
-
except Exception as e:
|
173 |
-
st.error(f"An error occurred while translating the customized description: {e}")
|
174 |
-
|
175 |
-
# Display the translated customized description if available
|
176 |
-
if 'translated_customized_description' in st.session_state:
|
177 |
-
st.subheader(f"Translated Customized Product Description ({target_language})")
|
178 |
-
st.write(st.session_state.translated_customized_description)
|
179 |
-
|
180 |
# Step 4: Feedback and Quality Scoring
|
181 |
-
|
182 |
-
|
183 |
feedback_comments = st.text_area("Additional Comments")
|
184 |
|
185 |
if st.button("Submit Feedback"):
|
186 |
-
|
187 |
-
feedback_entry = {
|
188 |
-
"rating": feedback_rating,
|
189 |
-
"comments": feedback_comments,
|
190 |
-
"description": st.session_state.generated_description,
|
191 |
-
"customized_description": st.session_state.customized_description if st.session_state.customized_description else "N/A",
|
192 |
-
"translated_description": st.session_state.translated_description if st.session_state.translated_description else "N/A"
|
193 |
-
}
|
194 |
-
st.session_state.feedback_history.append(feedback_entry)
|
195 |
st.success("Thank you for your feedback!")
|
196 |
-
|
197 |
-
# Display the feedback summary
|
198 |
-
st.subheader("Feedback Summary")
|
199 |
-
for i, feedback in enumerate(st.session_state.feedback_history, 1):
|
200 |
-
st.write(f"**Feedback {i}:**")
|
201 |
-
st.write(f"Rating: {feedback['rating']}")
|
202 |
-
st.write(f"Comments: {feedback['comments']}")
|
203 |
-
st.write(f"Generated Description: {feedback['description']}")
|
204 |
-
st.write(f"Customized Description: {feedback['customized_description']}")
|
205 |
-
st.write(f"Translated Description: {feedback['translated_description']}")
|
206 |
-
st.markdown("---")
|
207 |
|
208 |
else:
|
209 |
st.error("IBM WatsonX API credentials are not set. Please check your environment variables.")
|
|
|
9 |
# Set up page configuration
|
10 |
st.set_page_config(page_title="ProductProse - AI Product Description Generator", layout="wide")
|
11 |
|
12 |
+
# Initialize session state to track API responses and user feedback
|
13 |
if 'generated_description' not in st.session_state:
|
14 |
st.session_state.generated_description = None
|
15 |
if 'translated_description' not in st.session_state:
|
16 |
st.session_state.translated_description = None
|
17 |
if 'customized_description' not in st.session_state:
|
18 |
st.session_state.customized_description = None
|
19 |
+
if 'feedback' not in st.session_state:
|
20 |
+
st.session_state.feedback = None
|
21 |
|
22 |
# Sidebar for product data input
|
23 |
+
st.sidebar.title("Product Data Input")
|
24 |
+
product_name = st.sidebar.text_input("Product Name", "Example Product")
|
25 |
+
features = st.sidebar.text_area("Product Features", "Feature 1, Feature 2, Feature 3")
|
26 |
+
benefits = st.sidebar.text_area("Product Benefits", "Benefit 1, Benefit 2, Benefit 3")
|
27 |
+
specifications = st.sidebar.text_area("Product Specifications", "Specification 1, Specification 2, Specification 3")
|
|
|
28 |
|
29 |
+
# Select target language for translation
|
30 |
+
target_language = st.sidebar.selectbox("Target Language for Translation", ["Arabic", "Chinese", "French", "German", "Japanese", "Portugese", "Russian", "Spanish", "Urdu"])
|
31 |
|
32 |
# Main app title and description
|
33 |
+
st.title("ProductProse - AI Product Description Generator")
|
34 |
st.markdown("""
|
35 |
Welcome to ProductProse, an AI-powered tool for generating and customizing product descriptions using IBM Granite LLMs.
|
36 |
Simply input your product data and let the AI do the rest, including generating descriptions, translating them into multiple languages, and customizing them to match your brand tone and style.
|
37 |
""")
|
38 |
|
|
|
|
|
|
|
|
|
39 |
# IBM WatsonX API Setup
|
40 |
project_id = os.getenv('WATSONX_PROJECT_ID')
|
41 |
api_key = os.getenv('WATSONX_API_KEY')
|
|
|
46 |
client.set.default_project(project_id)
|
47 |
|
48 |
# Tone Selection for Description Customization
|
49 |
+
tone_example = st.sidebar.selectbox("Select Example Tone (Feel free to modify)", ["Formal", "Casual", "Professional", "Playful"])
|
50 |
+
st.sidebar.markdown("_Example: You can choose a tone that best fits your brand's style._")
|
51 |
|
52 |
# Keyword Input for SEO Optimization
|
53 |
+
seo_keywords_example = st.sidebar.text_area("SEO Keywords (comma-separated, e.g., 'smart home, automation')", "smart home, intelligent, automation")
|
54 |
+
st.sidebar.markdown("_Example: Add keywords to optimize for search engines._")
|
55 |
|
56 |
# Step 1: Generate Product Description
|
57 |
+
st.header("Step 1: Generate Product Description")
|
58 |
if st.button("Generate Description"):
|
59 |
if product_name and features and benefits and specifications:
|
60 |
# Prompt engineering for Granite-13B-Instruct
|
|
|
78 |
description_response = model.generate_text(prompt=prompt)
|
79 |
st.session_state.generated_description = description_response
|
80 |
st.session_state.translated_description = None # Clear previous translations
|
|
|
81 |
st.success("Product description generated!")
|
82 |
st.write(description_response)
|
83 |
except Exception as e:
|
|
|
86 |
st.warning("Please fill in all the product data fields before generating a description.")
|
87 |
|
88 |
# Step 2: Translate Product Description
|
89 |
+
st.header("Step 2: Translate Product Description")
|
90 |
if st.session_state.generated_description:
|
91 |
if st.button("Translate Description"):
|
92 |
try:
|
|
|
117 |
st.write(st.session_state.translated_description)
|
118 |
|
119 |
# Step 3: Customize Product Description via Chat Interface
|
120 |
+
st.header("Step 3: Customize Product Description")
|
121 |
+
customization_prompt = st.text_input("Customize the product description (Feel free to modify the example tone and SEO keywords)")
|
122 |
|
123 |
if st.session_state.generated_description and customization_prompt:
|
124 |
if st.button("Customize Description"):
|
|
|
145 |
st.subheader("Customized Product Description")
|
146 |
st.write(st.session_state.customized_description)
|
147 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
# Step 4: Feedback and Quality Scoring
|
149 |
+
st.header("Step 4: Provide Feedback")
|
150 |
+
feedback = st.slider("Rate the quality of the generated product description (1 = Poor, 5 = Excellent)", 1, 5, 3)
|
151 |
feedback_comments = st.text_area("Additional Comments")
|
152 |
|
153 |
if st.button("Submit Feedback"):
|
154 |
+
st.session_state.feedback = {"rating": feedback, "comments": feedback_comments}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
st.success("Thank you for your feedback!")
|
156 |
+
st.write(st.session_state.feedback)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
|
158 |
else:
|
159 |
st.error("IBM WatsonX API credentials are not set. Please check your environment variables.")
|