dimkar121 commited on
Commit
8d29ebb
·
verified ·
1 Parent(s): 037fe09

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -7
app.py CHANGED
@@ -3,6 +3,8 @@ import pandas as pd
3
  import bm25s
4
  from rapidfuzz import fuzz
5
  import numpy as np
 
 
6
 
7
  # 1. Load the Data
8
  abt_df = pd.read_csv("Abt.csv", encoding='latin1') #.rename(columns={'id': 'idAbt', 'name': 'name_A'})
@@ -14,18 +16,27 @@ print(abt_df.isnull().sum())
14
  print("\nBuy Missing Data:")
15
  print(buy_df.isnull().sum())
16
 
17
- import matplotlib.pyplot as plt
18
 
19
  # Calculate string lengths
20
  abt_df['name_length'] = abt_df['name'].str.len()
21
  buy_df['name_length'] = buy_df['name'].str.len()
22
 
23
- # Plot them side-by-side
24
- plt.hist(abt_df['name_length'], alpha=0.5, label='Abt Product Names', bins=30)
25
- plt.hist(buy_df['name_length'], alpha=0.5, label='Buy Product Names', bins=30)
26
- plt.legend()
27
- plt.title("How long are the product names?")
28
- plt.show()
 
 
 
 
 
 
 
 
 
 
29
 
30
 
31
  print(f"Abt Price Range: ${abt_df['price'].min()} to ${abt_df['price'].max()}")
 
3
  import bm25s
4
  from rapidfuzz import fuzz
5
  import numpy as np
6
+ import matplotlib.pyplot as plt
7
+
8
 
9
  # 1. Load the Data
10
  abt_df = pd.read_csv("Abt.csv", encoding='latin1') #.rename(columns={'id': 'idAbt', 'name': 'name_A'})
 
16
  print("\nBuy Missing Data:")
17
  print(buy_df.isnull().sum())
18
 
 
19
 
20
  # Calculate string lengths
21
  abt_df['name_length'] = abt_df['name'].str.len()
22
  buy_df['name_length'] = buy_df['name'].str.len()
23
 
24
+
25
+ def generate_plot():
26
+ fig = plt.figure()
27
+ plt.hist(abt_df['name_length'], alpha=0.5, label='Abt')
28
+ plt.hist(buy_df['name_length'], alpha=0.5, label='Buy')
29
+ plt.legend()
30
+ return fig # Return the figure, DO NOT use plt.show()
31
+
32
+ # Then in your Gradio layout:
33
+ with gr.Blocks() as demo:
34
+ gr.Markdown("# Welcome to the Product Matcher")
35
+
36
+ with gr.Row():
37
+ my_plot = gr.Plot(value=generate_plot()) # Gradio handles the drawing
38
+
39
+
40
 
41
 
42
  print(f"Abt Price Range: ${abt_df['price'].min()} to ${abt_df['price'].max()}")