Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -25,7 +25,7 @@ benefits = st.sidebar.text_area("Product Benefits", "Benefit 1, Benefit 2, Benef
|
|
25 |
specifications = st.sidebar.text_area("Product Specifications", "Specification 1, Specification 2, Specification 3")
|
26 |
|
27 |
# Select target language for translation
|
28 |
-
target_language = st.sidebar.selectbox("Target Language for Translation", ["
|
29 |
|
30 |
# Main app title and description
|
31 |
st.title("ProductProse - AI Product Description Generator")
|
@@ -49,11 +49,12 @@ if api_key and project_id:
|
|
49 |
if product_name and features and benefits and specifications:
|
50 |
# Prompt engineering for Granite-13B-Instruct
|
51 |
prompt = f"""
|
52 |
-
You are an AI that generates high-quality product descriptions. Based on the following details, generate a
|
53 |
Product Name: {product_name}\n
|
54 |
Features: {features}\n
|
55 |
Benefits: {benefits}\n
|
56 |
Specifications: {specifications}\n
|
|
|
57 |
"""
|
58 |
try:
|
59 |
model = ModelInference(model_id=ModelTypes.GRANITE_13B_INSTRUCT_V2, params={
|
@@ -75,47 +76,63 @@ if api_key and project_id:
|
|
75 |
|
76 |
# Translate Product Description
|
77 |
st.header("Step 2: Translate Product Description")
|
78 |
-
if st.session_state.generated_description
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
|
97 |
# Customize Product Description via Chat Interface
|
98 |
st.header("Step 3: Customize Product Description")
|
99 |
customization_prompt = st.text_input("Customize the product description (e.g., adjust tone, add brand-specific details)")
|
100 |
|
101 |
-
if st.session_state.generated_description and customization_prompt
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
|
120 |
else:
|
121 |
st.error("IBM WatsonX API credentials are not set. Please check your environment variables.")
|
|
|
25 |
specifications = st.sidebar.text_area("Product Specifications", "Specification 1, Specification 2, Specification 3")
|
26 |
|
27 |
# Select target language for translation
|
28 |
+
target_language = st.sidebar.selectbox("Target Language for Translation", ["French", "Spanish", "German", "Chinese", "Japanese"])
|
29 |
|
30 |
# Main app title and description
|
31 |
st.title("ProductProse - AI Product Description Generator")
|
|
|
49 |
if product_name and features and benefits and specifications:
|
50 |
# Prompt engineering for Granite-13B-Instruct
|
51 |
prompt = f"""
|
52 |
+
You are an AI that generates high-quality product descriptions. Based on the following details, generate a professional and engaging product description:\n
|
53 |
Product Name: {product_name}\n
|
54 |
Features: {features}\n
|
55 |
Benefits: {benefits}\n
|
56 |
Specifications: {specifications}\n
|
57 |
+
Generate only the final product description text, without including any instruction or prompt context.
|
58 |
"""
|
59 |
try:
|
60 |
model = ModelInference(model_id=ModelTypes.GRANITE_13B_INSTRUCT_V2, params={
|
|
|
76 |
|
77 |
# Translate Product Description
|
78 |
st.header("Step 2: Translate Product Description")
|
79 |
+
if st.session_state.generated_description:
|
80 |
+
if st.button("Translate Description"):
|
81 |
+
try:
|
82 |
+
# Translate the description using Granite-20B-Multilingual
|
83 |
+
prompt = f"Translate the following product description into {target_language}:\n{st.session_state.generated_description}"
|
84 |
+
model = ModelInference(model_id=ModelTypes.GRANITE_20B_MULTILINGUAL, params={
|
85 |
+
GenParams.DECODING_METHOD: DecodingMethods.GREEDY,
|
86 |
+
GenParams.MIN_NEW_TOKENS: 50,
|
87 |
+
GenParams.MAX_NEW_TOKENS: 200,
|
88 |
+
GenParams.STOP_SEQUENCES: ["\n"]
|
89 |
+
}, credentials=credentials, project_id=project_id)
|
90 |
+
|
91 |
+
with st.spinner(f"Translating product description to {target_language}..."):
|
92 |
+
translation_response = model.generate_text(prompt=prompt)
|
93 |
+
st.session_state.translated_description = translation_response
|
94 |
+
st.success(f"Product description translated to {target_language}!")
|
95 |
+
st.write(translation_response)
|
96 |
+
except Exception as e:
|
97 |
+
st.error(f"An error occurred while translating the description: {e}")
|
98 |
+
|
99 |
+
# Display previous results
|
100 |
+
if st.session_state.generated_description:
|
101 |
+
st.subheader("Generated Product Description")
|
102 |
+
st.write(st.session_state.generated_description)
|
103 |
+
|
104 |
+
if st.session_state.translated_description:
|
105 |
+
st.subheader(f"Translated Product Description ({target_language})")
|
106 |
+
st.write(st.session_state.translated_description)
|
107 |
|
108 |
# Customize Product Description via Chat Interface
|
109 |
st.header("Step 3: Customize Product Description")
|
110 |
customization_prompt = st.text_input("Customize the product description (e.g., adjust tone, add brand-specific details)")
|
111 |
|
112 |
+
if st.session_state.generated_description and customization_prompt:
|
113 |
+
if st.button("Customize Description"):
|
114 |
+
try:
|
115 |
+
# Customize the description using Granite-13B-Chat
|
116 |
+
prompt = f"Customize the following product description based on the user's request:\n{st.session_state.generated_description}\nCustomization Request: {customization_prompt}\nGenerate only the final customized product description."
|
117 |
+
model = ModelInference(model_id=ModelTypes.GRANITE_13B_CHAT_V2, params={
|
118 |
+
GenParams.DECODING_METHOD: DecodingMethods.GREEDY,
|
119 |
+
GenParams.MIN_NEW_TOKENS: 50,
|
120 |
+
GenParams.MAX_NEW_TOKENS: 200,
|
121 |
+
GenParams.STOP_SEQUENCES: ["\n"]
|
122 |
+
}, credentials=credentials, project_id=project_id)
|
123 |
+
|
124 |
+
with st.spinner("Customizing product description..."):
|
125 |
+
customization_response = model.generate_text(prompt=prompt)
|
126 |
+
st.session_state.customized_description = customization_response
|
127 |
+
st.success("Product description customized!")
|
128 |
+
st.write(customization_response)
|
129 |
+
except Exception as e:
|
130 |
+
st.error(f"An error occurred while customizing the description: {e}")
|
131 |
+
|
132 |
+
# Display customized result if available
|
133 |
+
if st.session_state.customized_description:
|
134 |
+
st.subheader("Customized Product Description")
|
135 |
+
st.write(st.session_state.customized_description)
|
136 |
|
137 |
else:
|
138 |
st.error("IBM WatsonX API credentials are not set. Please check your environment variables.")
|