Spaces:
Runtime error
Runtime error
File size: 1,216 Bytes
b26e391 8d29ebb b26e391 037fe09 b26e391 8600e01 8d29ebb 8600e01 | 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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | import gradio as gr
import pandas as pd
import bm25s
from rapidfuzz import fuzz
import numpy as np
import matplotlib.pyplot as plt
# 1. Load the Data
abt_df = pd.read_csv("Abt.csv", encoding='latin1') #.rename(columns={'id': 'idAbt', 'name': 'name_A'})
buy_df = pd.read_csv("Buy.csv", encoding='latin1') #.rename(columns={'id': 'idBuy', 'name': 'name_B'})
print("Abt Missing Data:")
print(abt_df.isnull().sum())
print("\nBuy Missing Data:")
print(buy_df.isnull().sum())
# Calculate string lengths
abt_df['name_length'] = abt_df['name'].str.len()
buy_df['name_length'] = buy_df['name'].str.len()
def generate_plot():
fig = plt.figure()
plt.hist(abt_df['name_length'], alpha=0.5, label='Abt')
plt.hist(buy_df['name_length'], alpha=0.5, label='Buy')
plt.legend()
return fig # Return the figure, DO NOT use plt.show()
# Then in your Gradio layout:
with gr.Blocks() as demo:
gr.Markdown("# Welcome to the Product Matcher")
with gr.Row():
my_plot = gr.Plot(value=generate_plot()) # Gradio handles the drawing
print(f"Abt Price Range: ${abt_df['price'].min()} to ${abt_df['price'].max()}")
print(f"Buy Price Range: ${buy_df['price'].min()} to ${buy_df['price'].max()}") |