CoolFace
Apppublic

Ak1747/Cable_Kit_Finder

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
app.py64 linesDownload Raw Back to root
1# -*- coding: utf-8 -*-2"""app.ipynb3 4Automatically generated by Colab.5 6Original file is located at7    https://colab.research.google.com/drive/1aNNnZxqHsKD7YNZL_qigEJ_Zv7qBAHUo8"""9 10import gradio as gr11import pandas as pd12 13# Function to validate item number14def validate_item_number(item_number):15      try:16        # Read the Excel file17        df = pd.read_excel('data.xlsx', engine='openpyxl', header=None)18 19        # Clean the search number (remove hyphens)20        clean_number = search_number.replace("-", "")21 22        # Find the row with matching number in column B (index 1)23        match_index = None24        for i, row in df.iterrows():25            if str(row[1]).replace("-", "") == clean_number:26                match_index = i27                break28 29        if match_index is None:30            return f"Number {search_number} not found in the Excel file"31 32        # Search upwards for nearest 0 in column A (index 0)33        result = None34        for i in range(match_index-1, -1, -1):35            if df.iloc[i, 0] == 0:36                result = df.iloc[i, 1]37                break38 39        if result is not None:40            return f"Found matching number above: {result}"41        else:42            return "No number with 0 above the found number"43 44      except Exception as e:45        return f"An error occurred: {str(e)}"46 47# Get search number from user48search_number = input("Enter the number to search (format: xxx-xxxxxx-xxxx): ")49 50# Perform the search51result = validate_item_number(search_number)52print("\nResult:")53print(result)54 55# Gradio Interface56iface = gr.Interface(57    fn=validate_item_number,58    inputs=gr.Textbox(label="Enter Item Number (730-XXXXXX-XXXX)"),59    outputs="text",60    title="Item Number Validator",61    description="Enter an item number to validate and get the corresponding level from the Excel sheet."62)63 64iface.launch()