Vorxart commited on
Commit
79277f6
·
verified ·
1 Parent(s): 5039d09

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -38
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", ["Arabic", "Urdu", "Russian", "French", "Spanish", "German", "Chinese", "Japanese"])
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 detailed product description:\n
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 and st.button("Translate Description"):
79
- try:
80
- # Translate the description using Granite-20B-Multilingual
81
- prompt = f"Translate the following product description into {target_language}:\n{st.session_state.generated_description}"
82
- model = ModelInference(model_id=ModelTypes.GRANITE_20B_MULTILINGUAL, params={
83
- GenParams.DECODING_METHOD: DecodingMethods.GREEDY,
84
- GenParams.MIN_NEW_TOKENS: 50,
85
- GenParams.MAX_NEW_TOKENS: 200,
86
- GenParams.STOP_SEQUENCES: ["\n"]
87
- }, credentials=credentials, project_id=project_id)
88
-
89
- with st.spinner(f"Translating product description to {target_language}..."):
90
- translation_response = model.generate_text(prompt=prompt)
91
- st.session_state.translated_description = translation_response
92
- st.success(f"Product description translated to {target_language}!")
93
- st.write(translation_response)
94
- except Exception as e:
95
- st.error(f"An error occurred while translating the description: {e}")
 
 
 
 
 
 
 
 
 
 
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 and st.button("Customize Description"):
102
- try:
103
- # Customize the description using Granite-13B-Chat
104
- prompt = f"Customize the following product description based on the user's request:\n{st.session_state.generated_description}\nUser Request: {customization_prompt}"
105
- model = ModelInference(model_id=ModelTypes.GRANITE_13B_CHAT_V2, params={
106
- GenParams.DECODING_METHOD: DecodingMethods.GREEDY,
107
- GenParams.MIN_NEW_TOKENS: 50,
108
- GenParams.MAX_NEW_TOKENS: 200,
109
- GenParams.STOP_SEQUENCES: ["\n"]
110
- }, credentials=credentials, project_id=project_id)
111
-
112
- with st.spinner("Customizing product description..."):
113
- customization_response = model.generate_text(prompt=prompt)
114
- st.session_state.customized_description = customization_response
115
- st.success("Product description customized!")
116
- st.write(customization_response)
117
- except Exception as e:
118
- st.error(f"An error occurred while customizing the description: {e}")
 
 
 
 
 
 
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.")