Spaces:
Sleeping
Sleeping
File size: 2,122 Bytes
ccada5d 2a7742d 155059d 446d4d9 8d43ad3 2a7742d ccada5d 155059d 2a7742d 155059d 57fd499 69a76eb c56bd4a ccada5d 155059d ccada5d 69a76eb ccada5d 69a76eb ccada5d 2a7742d ccada5d 69a76eb 2a7742d ccada5d 97e6f2a 69a76eb 2a7742d | 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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | import gradio as gr
import pandas as pd
import json
import functions # Assuming functions.py has necessary imports and functions
import tempfile
def process_tables(table1_path, table2_path, params_file_path):
# Load tables
table1 = pd.read_excel(table1_path.name)
table2 = pd.read_excel(table2_path.name)
# Load parameters from the JSON file
with open(params_file_path.name, 'r') as f:
params = json.load(f)
# Extract parameters
harmonization = params.get("harmonization", True)
columns_embeddings_col1 = params.get("columns_embeddings_col1", "Indicator Name")
columns_embeddings_col2 = params.get("columns_embeddings_col2", "Indicator name (leonardo)")
# Process column names into lists
columns_embeddings_col1 = [col.strip() for col in columns_embeddings_col1.split(',')]
columns_embeddings_col2 = [col.strip() for col in columns_embeddings_col2.split(',')]
# Process the tables using a function from functions.py
result_final = functions.process_similarity_results(
table1=table1,
table2=table2,
columns_embeddings_col1=columns_embeddings_col1,
columns_embeddings_col2=columns_embeddings_col2,
harmonization=harmonization
)
# Save the result to a temporary CSV file
result_path = tempfile.NamedTemporaryFile(suffix=".csv", delete=False).name
result_final.to_csv(result_path, index=False)
return result_path
# Define the Gradio interface
iface = gr.Interface(
fn=process_tables,
inputs=[
gr.File(label="Upload Table 1 (Client Indicators or Framework Table)"),
gr.File(label="Upload Table 2 (Internal Indicator or Indicator Table)"),
gr.File(label="Upload Parameters File (JSON format)")
],
outputs="file",
description=(
"Upload two tables and a JSON parameters file to process them. The parameters file should include: "
"'harmonization' (True or False), 'columns_embeddings_col1' (comma-separated column names), "
"and 'columns_embeddings_col2' (comma-separated column names)."
)
)
iface.launch()
|