Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -388,7 +388,7 @@ def log_query_analytics(query, product_type, response_time):
|
|
| 388 |
|
| 389 |
# Get product images from Astra DB
|
| 390 |
def get_product_images(product):
|
| 391 |
-
"""Get product images from Astra DB"""
|
| 392 |
global product_images
|
| 393 |
|
| 394 |
if not astra_session:
|
|
@@ -405,13 +405,23 @@ def get_product_images(product):
|
|
| 405 |
|
| 406 |
rows = astra_session.execute(query, (product,))
|
| 407 |
|
| 408 |
-
# Store image URLs
|
| 409 |
image_urls = []
|
| 410 |
for row in rows:
|
| 411 |
-
# In a real implementation, you would save the image temporarily and serve it
|
| 412 |
-
# For this demo, we're just using the image ID as an identifier
|
| 413 |
image_id = row.id
|
| 414 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 415 |
|
| 416 |
# If no images found, use placeholder URLs
|
| 417 |
if not image_urls:
|
|
@@ -823,7 +833,7 @@ def create_gradio_app():
|
|
| 823 |
<li>Ask about installation and maintenance</li>
|
| 824 |
<li>Get help with troubleshooting</li>
|
| 825 |
<li>S3 Bucket Name=agent-product-discovery</li>
|
| 826 |
-
<li>ABB Ability™ System 800xA® 6.2.pdf, Enclosed Softstarters.pdf, Ex-Solutions.pdf, Low_power_UPS_catalogue_EN.pdf<li>
|
| 827 |
</ul>
|
| 828 |
''')
|
| 829 |
gr.HTML('</div>')
|
|
|
|
| 388 |
|
| 389 |
# Get product images from Astra DB
|
| 390 |
def get_product_images(product):
|
| 391 |
+
"""Get product images from Astra DB, save them temporarily, and serve them"""
|
| 392 |
global product_images
|
| 393 |
|
| 394 |
if not astra_session:
|
|
|
|
| 405 |
|
| 406 |
rows = astra_session.execute(query, (product,))
|
| 407 |
|
| 408 |
+
# Store image URLs for display
|
| 409 |
image_urls = []
|
| 410 |
for row in rows:
|
|
|
|
|
|
|
| 411 |
image_id = row.id
|
| 412 |
+
image_data = row.image_data
|
| 413 |
+
|
| 414 |
+
# Save image data to a temporary file
|
| 415 |
+
temp_dir = os.path.join(os.getcwd(), 'temp_images')
|
| 416 |
+
os.makedirs(temp_dir, exist_ok=True)
|
| 417 |
+
|
| 418 |
+
temp_path = os.path.join(temp_dir, f"image-{image_id}.jpg")
|
| 419 |
+
with open(temp_path, 'wb') as f:
|
| 420 |
+
f.write(image_data)
|
| 421 |
+
|
| 422 |
+
# Create a URL that can be served by your web server
|
| 423 |
+
image_url = f"/temp_images/image-{image_id}.jpg"
|
| 424 |
+
image_urls.append(image_url)
|
| 425 |
|
| 426 |
# If no images found, use placeholder URLs
|
| 427 |
if not image_urls:
|
|
|
|
| 833 |
<li>Ask about installation and maintenance</li>
|
| 834 |
<li>Get help with troubleshooting</li>
|
| 835 |
<li>S3 Bucket Name=agent-product-discovery</li>
|
| 836 |
+
<li>ABB Ability™ System 800xA® 6.2.pdf, Enclosed Softstarters.pdf, Ex-Solutions.pdf, Low_power_UPS_catalogue_EN.pdf</li>
|
| 837 |
</ul>
|
| 838 |
''')
|
| 839 |
gr.HTML('</div>')
|