Spaces:
Sleeping
Sleeping
Create app.py
Browse files12345678910111213141516171819202122232425262728293031323334353637383940414243444546import gradio as grimport pandas as pdfrom difflib import SequenceMatcher
def similar(a, b):return SequenceMatcher(None, str(a).strip().lower(), str(b).strip().lower()).ratio()
def match_names(file1, file2, col1, col2):try:df1 = pd.read_excel(file1)df2 = pd.read_excel(file2)
df1 = df1[df1[col1].notna()]df2 = df2[df2[col2].notna()]
results = []
for name1 in df1[col1].astype(str):for name2 in df2[col2].astype(str):score = similar(name1, name2)results.append({"Name1": name1,"Name2": name2,"MatchScore (%)": round(score * 100, 2)})
result_df = pd.DataFrame(results)return result_dfexcept Exception as e:return f"Error: {str(e)}"
# Gradio UIdemo = gr.Interface(fn=match_names,inputs=[gr.File(label="Upload Excel File 1 (Input Names)", file_types=[".xlsx"]),gr.File(label="Upload Excel File 2 (Reference Names)", file_types=[".xlsx"]),gr.Textbox(label="Column name in File 1"),gr.Textbox(label="Column name in File 2"),],outputs=gr.Dataframe(label="Match Results (All Pairs with Score)"),title="Name Matcher using Sequence Similarity",description="Upload two Excel files with names. Specify column names. The app will compare every input name against every reference name and return similarity scores.")
demo.launch()app.pyAdded+46