Spaces:
Sleeping
Sleeping
fschwartzer
commited on
Commit
•
5d4f445
1
Parent(s):
bd113d2
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,13 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
import pandas as pd
|
4 |
-
|
5 |
-
import re # Importa o módulo de expressões regulares
|
6 |
import csv
|
7 |
import datetime
|
|
|
|
|
|
|
8 |
from fuzzywuzzy import process
|
9 |
|
10 |
bens_df = pd.read_excel('bens_tab.xlsx')
|
@@ -36,8 +39,8 @@ def refinar_resultados(df):
|
|
36 |
return df_refinado
|
37 |
|
38 |
def get_best_match(query, choices, limit=5):
|
39 |
-
matches = process.
|
40 |
-
return [match[0] for match in matches if match[1] > 60]
|
41 |
|
42 |
def filtrar_itens_similares(df, termo_pesquisa, limit=5):
|
43 |
titulos = df['Title'].tolist()
|
@@ -69,22 +72,25 @@ def calcular_fator_avaliacao(titulo, EC, PU):
|
|
69 |
return fator_avaliacao
|
70 |
|
71 |
def select_nearest_items(df):
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
|
|
75 |
|
76 |
-
|
|
|
|
|
77 |
included_marketplaces = set()
|
78 |
-
nearest_items =
|
79 |
for _, row in df_sorted.iterrows():
|
80 |
if row['Marketplace'] not in included_marketplaces:
|
81 |
-
|
82 |
-
row_df = pd.DataFrame([row])
|
83 |
-
nearest_items = pd.concat([nearest_items, row_df], ignore_index=True)
|
84 |
included_marketplaces.add(row['Marketplace'])
|
85 |
-
if len(included_marketplaces) >= 3:
|
86 |
break
|
87 |
-
|
|
|
88 |
|
89 |
def integrated_app(query, titulo, EC, PU):
|
90 |
df_mercadolibre = fetch_data_to_dataframe(query, 50, "mercadolibre")
|
|
|
1 |
+
|
2 |
import gradio as gr
|
3 |
import requests
|
4 |
import pandas as pd
|
5 |
+
import re
|
|
|
6 |
import csv
|
7 |
import datetime
|
8 |
+
from rapidfuzz import process, fuzzimport
|
9 |
+
import requests
|
10 |
+
from difflib import get_close_matches
|
11 |
from fuzzywuzzy import process
|
12 |
|
13 |
bens_df = pd.read_excel('bens_tab.xlsx')
|
|
|
39 |
return df_refinado
|
40 |
|
41 |
def get_best_match(query, choices, limit=5):
|
42 |
+
matches = process.extract(query, choices, scorer=fuzz.WRatio, limit=limit)
|
43 |
+
return [match[0] for match in matches if match[1] > 60]
|
44 |
|
45 |
def filtrar_itens_similares(df, termo_pesquisa, limit=5):
|
46 |
titulos = df['Title'].tolist()
|
|
|
72 |
return fator_avaliacao
|
73 |
|
74 |
def select_nearest_items(df):
|
75 |
+
mode_prices = df['Price'].mode()
|
76 |
+
if len(mode_prices) > 0:
|
77 |
+
target_price = mode_prices.min() # Choose the smallest mode if multiple
|
78 |
+
else:
|
79 |
+
target_price = df['Price'].median() # Fallback to median if no mode
|
80 |
|
81 |
+
df['Distance'] = (df['Price'] - target_price).abs()
|
82 |
+
df_sorted = df.sort_values('Distance')
|
83 |
+
|
84 |
included_marketplaces = set()
|
85 |
+
nearest_items = []
|
86 |
for _, row in df_sorted.iterrows():
|
87 |
if row['Marketplace'] not in included_marketplaces:
|
88 |
+
nearest_items.append(row)
|
|
|
|
|
89 |
included_marketplaces.add(row['Marketplace'])
|
90 |
+
if len(included_marketplaces) >= 3:
|
91 |
break
|
92 |
+
|
93 |
+
return pd.DataFrame(nearest_items)
|
94 |
|
95 |
def integrated_app(query, titulo, EC, PU):
|
96 |
df_mercadolibre = fetch_data_to_dataframe(query, 50, "mercadolibre")
|