Spaces:
Sleeping
Sleeping
import gradio as gr | |
import random | |
# Links for the websites | |
website_links = { | |
"Jarir": "https://www.jarir.com/sa-en/dp/office-supplies.html?gad_source=1&gclid=Cj0KCQjwiOy1BhDCARIsADGvQnDgDOE5cSZjXQOHsdVQs8Vge-QWL77ocXPBKZ17Op_X7vEF5jwOOekaArlaEALw_wcB&gclsrc=aw.ds#listingContent", | |
"Virgin Megastore": "https://www.virginmegastore.sa/en?gad_source=1&gclid=Cj0KCQjwiOy1BhDCARIsADGvQnDpnU5nhgtZ3DiCwPQlPbIfGaTNo7dVBteRI8XQuuSP_HU7B9WieFEaAmuYEALw_wcB", | |
"Extra": "https://www.extra.com/en-sa?gad_source=1&gclid=Cj0KCQjwiOy1BhDCARIsADGvQnDKIzuV97LBL15A-sg46w429-B0Ch9joJnxWJZMX12lozQRTKJmoA0aAn0hEALw_wcB&gclsrc=aw.ds" | |
} | |
# Function to simulate price generation | |
def simulate_price(product_name): | |
# Mock price generation using random values for three different websites | |
prices = { | |
"Jarir": round(random.uniform(300, 500), 2), | |
"Virgin Megastore": round(random.uniform(300, 500), 2), | |
"Extra": round(random.uniform(300, 500), 2) | |
} | |
# Find the cheapest price | |
cheapest_site = min(prices, key=prices.get) | |
cheapest_price = prices[cheapest_site] | |
cheapest_link = website_links[cheapest_site] | |
return f"The cheapest price for '{product_name}' is ${cheapest_price:.2f} on {cheapest_site}. [Check it out here]({cheapest_link})." | |
# Function to generate and compare prices | |
def compare_prices(product_name): | |
# Simulate prices instead of relying on text generation for this purpose | |
return simulate_price(product_name) | |
# Create Gradio interface | |
demo = gr.Interface( | |
fn=compare_prices, | |
inputs="text", | |
outputs="markdown", # Use "markdown" to allow clickable links | |
title="Price Comparator", | |
description="Enter the product name to find the cheapest price across simulated websites." | |
) | |
demo.launch() | |