Spaces:
Runtime error
Runtime error
Update app.py
Browse files59 unmodified lines60616263646566676869707172737475767778795 unmodified lines8586878889909130 unmodified lines12212312412512612712820 unmodified lines14915015115215315415566 unmodified lines22222322422522622768 unmodified lines29629729829930030130238 unmodified lines34134234334434534634734834940 unmodified lines39039139239339439539660 unmodified lines45745845946046146246346431 unmodified lines49649749849950050159 unmodified lines# Function to get options for part numbers or size and descriptiondef get_options(preferred, search_by):if preferred == "Yes":filtered_inventory = inventory[inventory['Preferred'] == "Yes"]else:filtered_inventory = inventoryif search_by == "Part Number":options = filtered_inventory['Part Number'].unique().tolist()else:sizes = filtered_inventory['Size'].unique().tolist()descriptions = filtered_inventory['Description'].unique().tolist()options = (sizes, descriptions)return options# Function to dynamically add quantity columns if neededdef add_quantity_columns(df):current_qty_columns = [col for col in df.columns if 'QTY ' in col]5 unmodified linesglobal reservation # Ensure reservation is accessibleglobal activity_logif preferred == "Yes":inventory_to_use = inventory[inventory['Preferred'] == "Yes"]else:inventory_to_use = inventory30 unmodified linesreservation.loc[reservation_data.index[0], 'Reserved'] -= used_lengthif reservation.loc[reservation_data.index[0], 'Reserved'] <= 0:reservation = reservation.drop(reservation_data.index[0])# Update quantity for all matching rowsif search_by == "Part Number":reservation.loc[(reservation['Part Number'] == part_number) & (reservation['Quantity'] == from_length), 'Quantity'] -= used_length20 unmodified linesavailable_data = reservation[(reservation['Part Number'] == part_number) & (reservation['Quantity'] == from_length)]else:available_data = reservation[(reservation['Size'] == size) & (reservation['Description'] == description) & (reservation['Quantity'] == from_length)]if not available_data.empty:available_length = available_data['Available'].values[0]if used_length > available_length:66 unmodified lineselse:return "Length not found."# Save updated inventory and reservation to local filesupdated_inventory_path = "updated_inventory.xlsx"updated_reservation_path = "updated_reservation.xlsx"68 unmodified linesactivity_log = download_and_load(activity_log_file_id)with gr.Blocks() as demo:preferred = gr.Radio(choices=["Yes", "No"], label="Preferred Material")search_by = gr.Radio(choices=["Part Number", "Size and Description"], label="Search By")part_number = gr.Dropdown(label="Part Number", interactive=True, visible=False)size = gr.Dropdown(label="Size", interactive=True, visible=False)38 unmodified lines# Modify update_lengths to reload sheets before updating lengthsdef update_lengths(preferred, search_by, part_number=None, size=None, description=None):if search_by == "Part Number":part_data = inventory[(inventory['Part Number'] == part_number) & (inventory['Preferred'] == preferred)]else:part_data = inventory[(inventory['Size'] == size) & (inventory['Description'] == description) & (inventory['Preferred'] == preferred)]if part_data.empty:return gr.update(choices=[], visible=False) # No data found40 unmodified linesif action_value == "Consume":return gr.update(visible=True), gr.update(visible=True)else:return gr.update(visible=False), gr.update(visible(False))from_length.change(handle_from_length_change, inputs=[action], outputs=[job_number, used_length])60 unmodified linesreturn html_message, gr.update(visible=True), part_numbersubmit.click(fn=show_confirmation,31 unmodified lines59 unmodified lines6061626364656667686970717273747576777879805 unmodified lines8687888990919230 unmodified lines12312412512612712812920 unmodified lines15015115215315415515666 unmodified lines22322422522622722822968 unmodified lines29829930030130230330438 unmodified lines34334434534634734834935035140 unmodified lines39239339439539639739860 unmodified lines45946046146246346431 unmodified lines49649749849950050150250359 unmodified lines# Function to get options for part numbers or size and descriptiondef get_options(preferred, search_by):if preferred:filtered_inventory = inventory[inventory['Preferred'] == "Yes"]else:filtered_inventory = inventoryif search_by == "Part Number":options = filtered_inventory['Part Number'].unique().tolist()else:sizes = filtered_inventory['Size'].unique().tolist()descriptions = filtered_inventory['Description'].unique().tolist()options = (sizes, descriptions)return options# Function to dynamically add quantity columns if neededdef add_quantity_columns(df):current_qty_columns = [col for col in df.columns if 'QTY ' in col]5 unmodified linesglobal reservation # Ensure reservation is accessibleglobal activity_logif preferred:inventory_to_use = inventory[inventory['Preferred'] == "Yes"]else:inventory_to_use = inventory30 unmodified linesreservation.loc[reservation_data.index[0], 'Reserved'] -= used_lengthif reservation.loc[reservation_data.index[0], 'Reserved'] <= 0:reservation = reservation.drop(reservation_data.index[0])# Update quantity for all matching rowsif search_by == "Part Number":reservation.loc[(reservation['Part Number'] == part_number) & (reservation['Quantity'] == from_length), 'Quantity'] -= used_length20 unmodified linesavailable_data = reservation[(reservation['Part Number'] == part_number) & (reservation['Quantity'] == from_length)]else:available_data = reservation[(reservation['Size'] == size) & (reservation['Description'] == description) & (reservation['Quantity'] == from_length)]if not available_data.empty:available_length = available_data['Available'].values[0]if used_length > available_length:66 unmodified lineselse:return "Length not found."# Save updated inventory and reservation to local filesupdated_inventory_path = "updated_inventory.xlsx"updated_reservation_path = "updated_reservation.xlsx"68 unmodified linesactivity_log = download_and_load(activity_log_file_id)with gr.Blocks() as demo:preferred = gr.Checkbox(label="Show Preferred Materials Only")search_by = gr.Radio(choices=["Part Number", "Size and Description"], label="Search By")part_number = gr.Dropdown(label="Part Number", interactive=True, visible=False)size = gr.Dropdown(label="Size", interactive=True, visible=False)38 unmodified lines# Modify update_lengths to reload sheets before updating lengthsdef update_lengths(preferred, search_by, part_number=None, size=None, description=None):if search_by == "Part Number":part_data = inventory[(inventory['Part Number'] == part_number) & (inventory['Preferred'] == ("Yes" if preferred else "No"))]else:part_data = inventory[(inventory['Size'] == size) & (inventory['Description'] == description) & (inventory['Preferred'] == ("Yes" if preferred else "No"))]if part_data.empty:return gr.update(choices=[], visible=False) # No data found40 unmodified linesif action_value == "Consume":return gr.update(visible=True), gr.update(visible=True)else:return gr.update(visible=False), gr.update(visible=False)from_length.change(handle_from_length_change, inputs=[action], outputs=[job_number, used_length])60 unmodified linesreturn html_message, gr.update(visible=True), part_numbersubmit.click(fn=show_confirmation,31 unmodified lines
app.py+14-12