File size: 742 Bytes
b9f1935
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
354bf96
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import gradio as gr
import json

def load_products():
    try:
        with open('products.json', 'r') as f:
            products = json.load(f)
        return products
    except Exception as e:
        print(f"Error loading products: {e}")
        return None

def show_products():
    products = load_products()
    if not products:
        return "<h1>Error loading products</h1>"
    
    html_content = "<h1>Products</h1>"
    for product in products['products']:
        html_content += f"<div><img src='{product['image']}' alt='{product['name']}' width='100'/><p>{product['details']}</p><p>Price: ${product['price']}</p></div>"
    return html_content

iface = gr.Interface(fn=show_products, inputs=[], outputs='html')
iface.launch()