| 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() | |