padisah / gradio_app.py
mert215's picture
Upload 7 files
b9f1935 verified
raw
history blame
No virus
752 Bytes
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(share=True)