Spaces:
Runtime error
Runtime error
Commit
·
b8b8d2d
1
Parent(s):
b843a7f
Update app.py
Browse files
app.py
CHANGED
@@ -44,7 +44,7 @@ def get_chatgpt_response(messages, selected_model):
|
|
44 |
return response['choices'][0]['message']['content']
|
45 |
|
46 |
# Define pages in sidebar
|
47 |
-
page = st.sidebar.radio('Select a page:', ('Review Analysis', 'review summary', 'Feature Benefits', 'Identify Avatars', 'Tone of Voice Manual', 'question_answers'))
|
48 |
|
49 |
|
50 |
if page == 'Review Analysis':
|
@@ -1182,3 +1182,249 @@ if page == 'question_answers':
|
|
1182 |
st.error(f"An error occurred while writing to Google Sheets: {e}")
|
1183 |
|
1184 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
return response['choices'][0]['message']['content']
|
45 |
|
46 |
# Define pages in sidebar
|
47 |
+
page = st.sidebar.radio('Select a page:', ('Review Analysis', 'review summary', 'Feature Benefits', 'feature_mapping', 'benefit_mapping', 'Identify Avatars', 'Tone of Voice Manual', 'question_answers'))
|
48 |
|
49 |
|
50 |
if page == 'Review Analysis':
|
|
|
1182 |
st.error(f"An error occurred while writing to Google Sheets: {e}")
|
1183 |
|
1184 |
|
1185 |
+
if page == 'feature_mapping':
|
1186 |
+
st.title('feature_mapping')
|
1187 |
+
|
1188 |
+
gc = gspread.service_account_from_dict(credentials_dict)
|
1189 |
+
|
1190 |
+
# Ask user for Google Sheet URL
|
1191 |
+
sheet_url = st.text_input('Enter the URL of your Google Sheet')
|
1192 |
+
|
1193 |
+
# Add this in the part of your Streamlit app where the user can select the model
|
1194 |
+
models = ["gpt-3.5-turbo", "gpt-4"]
|
1195 |
+
selected_model = st.selectbox("Choose a model:", models)
|
1196 |
+
|
1197 |
+
# Extract sheet ID from URL
|
1198 |
+
sheet_id = sheet_url.split('/')[5]
|
1199 |
+
# Open the Google spreadsheet
|
1200 |
+
sheet = gc.open_by_key(sheet_id)
|
1201 |
+
|
1202 |
+
# Select sheet named 'Listing'
|
1203 |
+
worksheet = sheet.worksheet('Listing')
|
1204 |
+
# Get all records of the data
|
1205 |
+
df = get_as_dataframe(worksheet)
|
1206 |
+
|
1207 |
+
# Convert DataFrame to strings
|
1208 |
+
df_str = df.astype(str)
|
1209 |
+
|
1210 |
+
title = df[df.eq('Title').any(axis=1)].iloc[0, 2]
|
1211 |
+
bullets = [df[df.eq(f"Bullet #{i}").any(axis=1)].iloc[0, 2] for i in range(1, 6)]
|
1212 |
+
|
1213 |
+
backend_search_terms = df[df.astype(str).apply(lambda x: 'Backend Search Terms' in ' '.join(x), axis=1)].iloc[0, 2] if len(df[df.astype(str).apply(lambda x: 'Backend Search Terms' in ' '.join(x), axis=1)]) > 0 else None
|
1214 |
+
|
1215 |
+
image_text_row = df[df.eq('Image Text').any(axis=1)]
|
1216 |
+
image_text = list(image_text_row.dropna(axis=1).iloc[0, :])
|
1217 |
+
|
1218 |
+
a_plus_desc_mask = df.astype(str).apply(lambda x: 'A+ Description' in ' '.join(x), axis=1)
|
1219 |
+
if a_plus_desc_mask.any():
|
1220 |
+
a_plus_desc_row = df[a_plus_desc_mask].index[0]
|
1221 |
+
a_plus_desc = df.iloc[a_plus_desc_row:, :].fillna('').values.flatten()
|
1222 |
+
a_plus_desc = ' '.join(a_plus_desc).strip()
|
1223 |
+
else:
|
1224 |
+
a_plus_desc = None
|
1225 |
+
|
1226 |
+
legacy_desc = df[df.astype(str).apply(lambda x: 'Legacy Product Description' in ' '.join(x), axis=1)].iloc[0, 2] if len(df[df.astype(str).apply(lambda x: 'Legacy Product Description' in ' '.join(x), axis=1)]) > 0 else None
|
1227 |
+
|
1228 |
+
image_text_string = ' '.join(image_text)
|
1229 |
+
|
1230 |
+
bullet_str = ""
|
1231 |
+
for i, bullet in enumerate(bullets, 1):
|
1232 |
+
bullet_str += f"Bullet #{i}: {bullet}\n"
|
1233 |
+
|
1234 |
+
# Display default prompt to user
|
1235 |
+
default_prompt = """Features:
|
1236 |
+
1) Professional Artist Testing: Developed and tested by professional artists to ensure exceptional product quality and results for all types of artistic expression.
|
1237 |
+
2) 1:1 Aspect Ratio: Square aspect ratio of 1:1 facilitates an easy design process and balanced compositions based on famous artworks.
|
1238 |
+
3) 100% Cotton Fibers: Uses 100% cotton fibers to provide natural and lasting beauty and exceptional resistance to scratching and erasing.
|
1239 |
+
4) Gelatin-sized Paper: Offers astounding absorbency resulting in harmonious, natural grain texture and no optical brightening agents that maintain the original brightness of the artwork.
|
1240 |
+
5) Cold & Hot Presses: Available in both cold press and hot press finishes, resulting in slightly textured, toothed surfaces (cold press) for depth and almost no tooth (hot press) surfaces for seamless blending, overlay, or paint removal.
|
1241 |
+
6) European Mill Crafting: Crafted by European mill masters with over 400 years of paper-making experience, ensuring that you produce your finest works.
|
1242 |
+
7) Easy-Block Format: Offers a unique "Easy-Block" format that eliminates the need to stretch watercolor paper sheets, saves time and effort, and ensures that paint dries to the desired texture and prevent buckling or creasing.
|
1243 |
+
8) 2 Glued, 2 Open Edges: Glued on 2 edges and open on 2 edges for easy removal of finished painting, saving time and effort while maintaining paper integrity and preservation.
|
1244 |
+
9) Travel-friendly: Suitable for travel, providing increased convenience to artists.
|
1245 |
+
10) Various Paper Weights: Available in a range of paper weights, ensuring maximum versatility for different artistic styles and techniques.
|
1246 |
+
11) 100 Series Youth Quality: Offers youth quality in the 100 series, providing a traditional watercolor feel for artistic expression.
|
1247 |
+
12) Cotton & Wood Pulp Choices: Offers two different choices of watercolor paper: 100% cotton pulp and 100% wood pulp.
|
1248 |
+
13) Indoor & Outdoor Use: Designed for use indoors and outdoors, providing versatility for artists on the go.
|
1249 |
+
14) 14 Cold-pressed Sheets: Offers 14 sheets of cold-pressed, textured watercolor paper, providing ample surface area for larger projects.
|
1250 |
+
15) Glue Binding: Offers glue binding for easy tearing out of pages, allowing for experimentation and perfecting techniques.
|
1251 |
+
16) Drawing, Sketching, Painting: Versatile for drawing, sketching, and painting.
|
1252 |
+
17) Mixed Media Suitable: Top choice for mixed media projects.
|
1253 |
+
18) Artist-approved: Tested and approved by artists.
|
1254 |
+
19) Chlorine-free & pH-neutral: Chlorine-free, pH-neutral, and archival, ensuring the longevity of artwork.
|
1255 |
+
20) Natural White Paper: Natural white, providing a textured surface for extraordinary vibrant colors.
|
1256 |
+
21) Rough Watercolor Paper: Rough, providing both smooth and textured surfaces for experimentation.
|
1257 |
+
22) Dual-Sided Surfaces: Dual-sided with smooth and textured surfaces.
|
1258 |
+
23) Expert Quality: Provides expert quality for perfect combination of durability and ease of use.
|
1259 |
+
24) Art-N-Fly Compatibility: Compatible with Art-N-Fly Watercolor Pens.
|
1260 |
+
25) Historic Paper Quality: Offers exceptional papers since the 1700s.
|
1261 |
+
26) Calcium Carbonate Buffer: Buffered with calcium carbonate for added protection.
|
1262 |
+
27) Random Texture: Provides a distinctive random texture.
|
1263 |
+
28) Internally Sized: Internally sized to maintain paper integrity and prevent paper deterioration.
|
1264 |
+
|
1265 |
+
|
1266 |
+
--------------------------------------------------------------------------------------------
|
1267 |
+
|
1268 |
+
You have to search for presence of above features in below information of listing:
|
1269 |
+
|
1270 |
+
--------------------------------------------------------------------------------------------
|
1271 |
+
------------------------------------
|
1272 |
+
Title: {}\n
|
1273 |
+
bullet_str: {}\n
|
1274 |
+
Legacy Product Description: {}\n
|
1275 |
+
A+ Description: {}\n
|
1276 |
+
Image_text: {}\n
|
1277 |
+
backend_search_terms: {}\n
|
1278 |
+
-------------------------------------
|
1279 |
+
|
1280 |
+
|
1281 |
+
|
1282 |
+
Please carefully read the given information of listing and create feature present matrix. if feature is present then you have to mark it using 1 and if absent leave empty. please create in table format. note, only present features should be covered. You have to explain at the end where did you find the present features. also once table is ready create one json that I can easily load in pandas df
|
1283 |
+
""".format(title, bullet_str, legacy_desc, a_plus_desc, image_text_string, backend_search_terms)
|
1284 |
+
|
1285 |
+
prompt = st.text_area("Edit the prompt:", value=default_prompt, height=200)
|
1286 |
+
|
1287 |
+
|
1288 |
+
|
1289 |
+
# If the user has input a URL, fetch the data from Google Sheets
|
1290 |
+
if st.button('generate'):
|
1291 |
+
|
1292 |
+
messages = [
|
1293 |
+
{"role": "system", "content": "You are helpful assistant"},
|
1294 |
+
{"role": "user", "content": prompt}
|
1295 |
+
]
|
1296 |
+
|
1297 |
+
|
1298 |
+
|
1299 |
+
model_response = get_chatgpt_response(messages, selected_model)
|
1300 |
+
|
1301 |
+
feature_mapping= model_response
|
1302 |
+
|
1303 |
+
st.session_state.feature_mapping = feature_mapping
|
1304 |
+
|
1305 |
+
st.write(feature_mapping)
|
1306 |
+
|
1307 |
+
|
1308 |
+
if page == 'benefit_mapping':
|
1309 |
+
st.title('benefit_mapping')
|
1310 |
+
|
1311 |
+
|
1312 |
+
gc = gspread.service_account_from_dict(credentials_dict)
|
1313 |
+
|
1314 |
+
# Ask user for Google Sheet URL
|
1315 |
+
sheet_url = st.text_input('Enter the URL of your Google Sheet')
|
1316 |
+
|
1317 |
+
# Add this in the part of your Streamlit app where the user can select the model
|
1318 |
+
models = ["gpt-3.5-turbo", "gpt-4"]
|
1319 |
+
selected_model = st.selectbox("Choose a model:", models)
|
1320 |
+
|
1321 |
+
# Extract sheet ID from URL
|
1322 |
+
sheet_id = sheet_url.split('/')[5]
|
1323 |
+
# Open the Google spreadsheet
|
1324 |
+
sheet = gc.open_by_key(sheet_id)
|
1325 |
+
|
1326 |
+
# Select sheet named 'Listing'
|
1327 |
+
worksheet = sheet.worksheet('Listing')
|
1328 |
+
# Get all records of the data
|
1329 |
+
df = get_as_dataframe(worksheet)
|
1330 |
+
|
1331 |
+
# Convert DataFrame to strings
|
1332 |
+
df_str = df.astype(str)
|
1333 |
+
|
1334 |
+
title = df[df.eq('Title').any(axis=1)].iloc[0, 2]
|
1335 |
+
bullets = [df[df.eq(f"Bullet #{i}").any(axis=1)].iloc[0, 2] for i in range(1, 6)]
|
1336 |
+
|
1337 |
+
backend_search_terms = df[df.astype(str).apply(lambda x: 'Backend Search Terms' in ' '.join(x), axis=1)].iloc[0, 2] if len(df[df.astype(str).apply(lambda x: 'Backend Search Terms' in ' '.join(x), axis=1)]) > 0 else None
|
1338 |
+
|
1339 |
+
image_text_row = df[df.eq('Image Text').any(axis=1)]
|
1340 |
+
image_text = list(image_text_row.dropna(axis=1).iloc[0, :])
|
1341 |
+
|
1342 |
+
a_plus_desc_mask = df.astype(str).apply(lambda x: 'A+ Description' in ' '.join(x), axis=1)
|
1343 |
+
if a_plus_desc_mask.any():
|
1344 |
+
a_plus_desc_row = df[a_plus_desc_mask].index[0]
|
1345 |
+
a_plus_desc = df.iloc[a_plus_desc_row:, :].fillna('').values.flatten()
|
1346 |
+
a_plus_desc = ' '.join(a_plus_desc).strip()
|
1347 |
+
else:
|
1348 |
+
a_plus_desc = None
|
1349 |
+
|
1350 |
+
legacy_desc = df[df.astype(str).apply(lambda x: 'Legacy Product Description' in ' '.join(x), axis=1)].iloc[0, 2] if len(df[df.astype(str).apply(lambda x: 'Legacy Product Description' in ' '.join(x), axis=1)]) > 0 else None
|
1351 |
+
|
1352 |
+
image_text_string = ' '.join(image_text)
|
1353 |
+
|
1354 |
+
bullet_str = ""
|
1355 |
+
for i, bullet in enumerate(bullets, 1):
|
1356 |
+
bullet_str += f"Bullet #{i}: {bullet}\n"
|
1357 |
+
|
1358 |
+
# Display default prompt to user
|
1359 |
+
default_prompt = """Benefits:
|
1360 |
+
1) Long-lasting Artwork: Exceptional product quality ensures long-lasting, beautiful artwork and exceptional results for various artistic expressions.
|
1361 |
+
2) Easy Composition: A square aspect ratio of 1:1 on the paper facilitates an easy design process and balanced compositions based on famous artworks.
|
1362 |
+
3) Natural Beauty: 100% cotton fibers provide natural and lasting beauty and exceptional resistance to scratching and erasing.
|
1363 |
+
4) Superior Absorbency: Gelatin-sized paper offers astounding absorbency resulting in harmonious, natural grain texture and no optical brightening agents that maintain the original brightness of the artwork.
|
1364 |
+
5) Versatile Finishes: Available in both cold press and hot press finishes result in slightly textured, toothed surfaces (cold press) for depth and almost no tooth (hot press) surfaces for seamless blending, overlay, or paint removal and provide vibrantly versatile paper for customization based on the artist's preference.
|
1365 |
+
6) Expert Craftsmanship: Crafted by experienced mill masters guarantees that artists produce their finest works.
|
1366 |
+
7) No Stretching Needed: Unique "Easy-Block" format eliminates the need to stretch watercolor paper sheets, saves time and effort, and ensures that paint dries to the desired texture and prevents buckling or creasing.
|
1367 |
+
8) Easy Painting Removal: Glued on 2 edges and open on 2 edges for easy removal of finished painting saves time and effort while maintaining paper integrity and preservation.
|
1368 |
+
9) Travel Convenience: Suitable for travel, providing increased convenience to artists.
|
1369 |
+
10) Versatility: Available in a range of paper weights ensures maximum versatility for different artistic styles and techniques.
|
1370 |
+
11) Time & Money Savings: Saves time and money with ready-made sizes.
|
1371 |
+
12) Durable Preservation: Durable material for long-lasting preservation.
|
1372 |
+
13) Traditional Feel: Traditional watercolor feel for artistic expression.
|
1373 |
+
14) Ample Surface Area: Provides ample surface area for larger projects.
|
1374 |
+
15) Superior Value: Superior value compared to other brands.
|
1375 |
+
16) Artistic Versatility: Approved by professional artists for various artistic endeavors.
|
1376 |
+
17) Mixed Media Ideal: Suitable for creating mixed media artwork.
|
1377 |
+
18) Professional Quality: Ensures the longevity of artwork with high-quality material.
|
1378 |
+
19) Artwork Longevity: Provides a textured surface for extraordinary vibrant colors, contributing to artwork longevity.
|
1379 |
+
20) Beautiful Paintings: Ideal for creating beautiful artwork for weddings, gifts, and more.
|
1380 |
+
21) Vibrant Colors: Provides a textured surface that results in extraordinary vibrant colors.
|
1381 |
+
22) Technique Experimentation: Offers both smooth and textured surfaces for experimentation with different techniques.
|
1382 |
+
23) Creative Possibilities: Versatile enough for painting, sketching, printmaking, or drawing.
|
1383 |
+
24) Durable & Easy: Smooth edges and easy tear sheets ensure no damage to artwork.
|
1384 |
+
25) Professional Look: Provides a professional appearance for watercolor paintings.
|
1385 |
+
26) Unique Artisan Touch: Innovative artisan paper adds a unique touch to artwork.
|
1386 |
+
27) Added Protection: High-quality material ensures artwork longevity and protection.
|
1387 |
+
28) Budget-friendly: Cost-effective paper for budget-conscious artists.
|
1388 |
+
29) Quality Assurance: Highest grade of watercolor paper available, providing quality assurance and contributing to artistic confidence.
|
1389 |
+
|
1390 |
+
|
1391 |
+
--------------------------------------------------------------------------------------------
|
1392 |
+
|
1393 |
+
You have to search for presence of above Benefits in below information of listing:
|
1394 |
+
|
1395 |
+
--------------------------------------------------------------------------------------------
|
1396 |
+
------------------------------------
|
1397 |
+
Title: {}\n
|
1398 |
+
bullet_str: {}\n
|
1399 |
+
Legacy Product Description: {}\n
|
1400 |
+
A+ Description: {}\n
|
1401 |
+
Image_text: {}\n
|
1402 |
+
backend_search_terms: {}\n
|
1403 |
+
-------------------------------------
|
1404 |
+
|
1405 |
+
|
1406 |
+
|
1407 |
+
Please carefully read the given information of listing and create Benefits present matrix. if Benefit is present then you have to mark it using 1 and if absent leave empty. please create in table format. note, only present Benefits should be covered. please include benefit name in the table. You have to explain at the end where did you find the present Benefits. also once table is ready create one json that I can easily load in pandas df
|
1408 |
+
""".format(title, bullet_str, legacy_desc, a_plus_desc, image_text_string, backend_search_terms)
|
1409 |
+
|
1410 |
+
prompt = st.text_area("Edit the prompt:", value=default_prompt, height=200)
|
1411 |
+
|
1412 |
+
|
1413 |
+
|
1414 |
+
# If the user has input a URL, fetch the data from Google Sheets
|
1415 |
+
if st.button('generate'):
|
1416 |
+
|
1417 |
+
messages = [
|
1418 |
+
{"role": "system", "content": "You are helpful assistant"},
|
1419 |
+
{"role": "user", "content": prompt}
|
1420 |
+
]
|
1421 |
+
|
1422 |
+
|
1423 |
+
|
1424 |
+
model_response = get_chatgpt_response(messages, selected_model)
|
1425 |
+
|
1426 |
+
benefit_mapping= model_response
|
1427 |
+
|
1428 |
+
st.session_state.feature_mapping = benefit_mapping
|
1429 |
+
|
1430 |
+
st.write(benefit_mapping)
|