import gradio as gr import json import html # %% # Define the function to call the model def call_model_llama(input_message): from gradio_client import Client # Assuming this is where Client is from # Create the client object client = Client("featherless-ai/try-this-model") # Call the model with the combined input message result = client.predict( message=input_message, # Use the combined message model="mattshumer/Reflection-Llama-3.1-70B", api_name="/chat" ) # Return the result return result # %% # Define the function to call the model def call_model_Gpt4(input_message): from gradio_client import Client client = Client("KingNish/OpenGPT-4o") result = client.predict( user_prompt={"text":input_message,"files":[]}, api_name="/chat" ) return result # %% # Define the function to call the model def call_model_Gemini(input_message): from gradio_client import Client # Assuming this is where Client is from # Create the client object client = Client("NotASI/Google-AI-Playground") # Call the model with the input message result = client.predict( message={"text": input_message, "files": []}, api_name="/chat" ) # Return the result return result # Define the function to call the model def call_model_Gemini1(input_message): from gradio_client import Client # Assuming this is where Client is from # Create the client object client = Client("NotASI/Google-AI-Playground") # Call the model with the input message result = client.predict( message={"text":input_message,"files":[]}, model_id="gemini-1.5-flash-exp-0827", system_message="You are a friendly Chatbot.", max_tokens=4096, temperature=0.75, top_p=0.95, api_name="/chat_1" ) # Return the result return result # Print combined result (Optional) #print(prompt) def prompt_comb(input_file): # %% prompt0=""" ### Prompt: **Objective:** Your task is to analyze part information extracted from multiple documents and propose a **generalized Part Identification Number (PIN) layout**. You are provided with multiple part information data blocks. The goal is to identify common and unique parameters across all the parts, then intelligently **propose a single, generalized PIN layout** that can be applied to all parts in the dataset, while ensuring it captures the key attributes that define each part. **Instructions:** 1. **Input Data Format:** The input consists of data blocks representing various parts. Each data block includes attributes such as: - **Basic Series Name**: The part series identifier (e.g., `M85049/43`, `AS85049/52`). - **Connectors**: Lists compatible connectors (e.g., `MILDTL5015`, `MILDTL38999`). - **Self-locking Option**: Specifies if the part has a self-locking mechanism (e.g., `S`, `N`, or `-`). - **Shell Size**: Describes the available shell sizes (e.g., `8, 10, 12`). - **Material and Plating**: Lists the materials and their finishes (e.g., `A: Aluminum`, `N: Nickel`). - **Angle**: Describes the angle (e.g., `Straight`, `45°`, `90°`). - **Other features**: May include additional details, such as knurl style or dimensions, which can sometimes be relevant. Here is an example of a data block: ```plaintext { M85049 Backshells AS85049/43 Series - 45° cable clamp strain relief For connectors: MIL-DTL-5015 crimp MIL-DTL-26482 Series 2 AS81703 Series 3 MIL-DTL-83723 Series 1 & 3 Ordering information Self-locking option: Non self locking Shell size: 3, 8, 10, 12, 14, 16, 18, 20, 22, 24, 28, 32, 36, 40, 44, 48, 61 Material and plating: N: Aluminum, electroless nickel, W: Aluminum, olive drab cadmium } Task: Analyze All Data Blocks: Begin by thoroughly analyzing all the provided part data blocks under the extracted data section. Identify both common features (that appear across most parts) and unique features (that distinguish certain parts). Identify Key Attributes: From the data, extract the most significant attributes that are necessary for generating a PIN. These may include, but are not limited to: Basic Series Name Self-locking Option Shell Size Material and Plating Angle Connector Type Propose a Generalized PIN Layout: Based on the common and unique features identified across the data blocks, propose a general PIN layout that can be applied across all parts in the dataset. The layout should be flexible enough to accommodate different parts, yet standardized enough to be applied consistently. Expected Output: Generalized PIN Layout: Your output should propose a single, general layout for the Part Identification Number (PIN). The layout should combine key features, capturing relevant details, but should not be overly complex. Do Not Provide Individual PINs for each data block. Instead, your task is to propose one general layout that works across all the parts in the dataset. Examples: Based on your analysis, your output might look like: /---- However, you should adapt the structure based on your understanding of the data. For example, if angles are only relevant for certain parts, your proposed layout could conditionally include them. Your final layout should represent a balance between flexibility and simplicity. Why This Task is Important: The goal is to automate the process of generating a standardized Part Identification Number (PIN) layout across a large set of data blocks. Your solution should generalize the PIN structure so that it can be applied to various parts, enabling an efficient identification system without manual intervention. Few-Shot Learning Examples: Given the part information- Example 1: { M85049 Backshells AS85049/52 Series - Straight cable clamp strain relief For connectors: MIL-DTL-5015 crimp MIL-DTL-26482 Series 2 AS81703 Series 3 MIL-DTL-83723 Series 1 & 3 Self-locking option: S: Self-locking Shell size: 3, 8, 10, 12, 14, 16 Material and plating: N: Aluminum, electroless nickel } PIN Layout Proposed: AS85049/52-10-S-N-Straight-MILDTL5015 Example 2: { M85049 Backshells AS85049/43 Series - 45° cable clamp strain relief For connectors: MIL-DTL-5015 crimp MIL-DTL-26482 Series 2 AS81703 Series 3 Shell size: 3, 10, 16 Material and plating: W: Aluminum, olive drab cadmium } PIN Layout Proposed: AS85049/43-10-N-W-45-MILDTL5015 """ # %% prompt1="""**Objective:** Your task is to propose a **generalized solution** for generating Part Identification Numbers (PINs) that can handle **many styles of PINs and different designations**. You will be provided with data blocks extracted from multiple parts. Your goal is to: 1. **Challenge the generalization** of PIN generation by identifying common patterns across parts and ensuring flexibility in the layout to accommodate various styles of PINs. 2. **Design a general solution** that can include different styles of PINs and part designations, ensuring the flexibility to adapt to future variations in part information. **Instructions:** 1. **Input Data Format:** The input consists of data blocks representing various parts. Each data block includes attributes such as: - **Basic Series Name**: The part series identifier (e.g., `M85049/43`, `AS85049/52`). - **Connectors**: Lists compatible connectors (e.g., `MILDTL5015`, `MILDTL38999`). - **Self-locking Option**: Specifies if the part has a self-locking mechanism (e.g., `S`, `N`, or `-`). - **Shell Size**: Describes the available shell sizes (e.g., `8, 10, 12`). - **Material and Plating**: Lists the materials and their finishes (e.g., `A: Aluminum`, `N: Nickel`). - **Angle**: Describes the angle (e.g., `Straight`, `45°`, `90°`). - **Other features**: May include additional details, such as knurl style or dimensions, which can sometimes be relevant. Here is an example of a data block: ```plaintext { M85049 Backshells AS85049/43 Series - 45° cable clamp strain relief For connectors: MIL-DTL-5015 crimp MIL-DTL-26482 Series 2 AS81703 Series 3 MIL-DTL-83723 Series 1 & 3 Ordering information Self-locking option: Non self locking Shell size: 3, 8, 10, 12, 14, 16, 18, 20, 22, 24, 28, 32, 36, 40, 44, 48, 61 Material and plating: N: Aluminum, electroless nickel, W: Aluminum, olive drab cadmium } Main Task: Generalization Across Multiple Styles: The key challenge is to create a flexible PIN generation solution that generalizes well across multiple styles of parts. Your task is to understand the diversity in the dataset and propose a solution that accommodates different PIN structures and styles, while being able to adapt to future variations. Analyze All Data Blocks: Begin by thoroughly analyzing all the provided part data blocks. Identify common patterns (e.g., shell size, self-locking options) and unique variations (e.g., specific connector types or angle requirements). Challenge the Generalization: Ensure that your solution is capable of handling diverse PIN formats. This includes accommodating different part designations (e.g., connectors, angles) and ensuring that the PIN format can easily adapt to additional parts that may not follow the same format. Design a Flexible PIN Layout: Propose a flexible PIN layout that can apply to all parts, while allowing for multiple styles and designations. The layout should be capable of supporting future parts that may include different attributes or designations not present in the current dataset. Expected Output: Generalized PIN Layout: Your output should propose a generalized PIN layout that is capable of handling multiple styles and variations of PINs. The layout should be flexible, concise, and capable of accommodating both common and unique features across parts. Include Multiple Styles: Your layout should not rely on a single format but should challenge the generalization by including ways to handle parts with different styles and designations. For example, some parts may require angle information (e.g., 45°, 90°), while others may need unique connectors or specific shell sizes. Note: You are not asked to fill in individual PINs for each part but rather to propose a general solution that can handle the variations across the entire dataset and future parts. Examples: The layout should allow for different designations, such as connector types or additional material/plating options, to be inserted where applicable. If the part requires a different designation style, the layout should be able to accommodate that without breaking the overall format. Why This Task is Important: The goal is to challenge the generalization of PIN generation by designing a system that can handle multiple styles of PINs and accommodate different designations across a large set of data. The system should be able to adapt to future variations in parts and designations without requiring significant changes. Few-Shot Learning Examples: Example 1: Given the part information: { M85049 Backshells AS85049/52 Series - Straight cable clamp strain relief For connectors: MIL-DTL-5015 crimp MIL-DTL-26482 Series 2 AS81703 Series 3 MIL-DTL-83723 Series 1 & 3 Self-locking option: S: Self-locking Shell size: 3, 8, 10, 12, 14, 16 Material and plating: N: Aluminum, electroless nickel } Generalized PIN Layout : AS85049/52:10:S:N:Straight:MILDTL5015 Example 2: { M85049 Backshells AS85049/43 Series - 45° cable clamp strain relief For connectors: MIL-DTL-5015 crimp MIL-DTL-26482 Series 2 AS81703 Series 3 Shell size: 3, 10, 16 Material and plating: W: Aluminum, olive drab cadmium } Generalized PIN Layout: AS85049/43:10:N:W:45:MILDTL5015 """ # %% prompt2=""" ### Prompt2: ### Objective: Design a **generalized solution** for generating Part Identification Numbers (PINs) that accommodates **multiple styles of PINs and part designations**. Using data blocks extracted from various parts, your goal is to: 1. **Challenge the generalization** of the PIN generation by identifying common patterns across parts, while ensuring the layout can handle a wide range of PIN styles and part designations. 2. **Develop a flexible solution** that can adapt to future part variations without major changes, allowing for various attributes and styles in the PINs. ### Instructions: 1. **Input Data Format:** Each data block represents a part and includes attributes such as: - **Series Name**: Identifier for the part series (e.g., `M85049/43`, `AS85049/52`). - **Connectors**: Lists the compatible connectors (e.g., `MILDTL5015`, `MILDTL38999`). - **Self-locking Option**: Specifies the locking mechanism, such as `S` for self-locking or `N` for non-self-locking. - **Shell Size**: Defines available shell sizes (e.g., `8, 10, 12`). - **Material and Plating**: Lists the material and its finish (e.g., `N: Nickel`, `W: Olive drab cadmium`). - **Angle**: Describes part angle (e.g., `Straight`, `45°`, `90°`). - **Other Features**: May include knurl style or other specifications relevant to the part. Example of a data block: ```plaintext { M85049 Backshells AS85049/43 Series - 45° cable clamp strain relief For connectors: MIL-DTL-5015 crimp MIL-DTL-26482 Series 2 AS81703 Series 3 MIL-DTL-83723 Series 1 & 3 Ordering information Self-locking option: Non self-locking Shell size: 3, 8, 10, 12, 14, 16 Material and plating: N: Aluminum, electroless nickel; W: Aluminum, olive drab cadmium } Main Task: Generalization Across Multiple Styles: Analyze the dataset and propose a flexible solution that accommodates different PIN structures and styles, ensuring it adapts to future variations. Analyze Data Blocks: Identify common attributes like shell size, self-locking options, and material. Also, note unique variations like connector types and angles. Challenge the Generalization: Design a solution that handles various formats, while also allowing flexibility for future part additions. Design a Flexible Layout: Propose a flexible PIN layout applicable to all parts, supporting different designations and attributes. **Expected Output**: Generalized PIN Layout: Your proposed layout should be flexible and capable of handling multiple styles of PINs. Display JSON Output: DO NOT generate Python code for creating the JSON output file.Instead,Generate the PINs using a generalized layout for each data block and display the result directly in the following JSON structure format **Do not generate any PINs for data blocks outside the JSON structure**, Ensure the generated PINs are displayed as a valid JSON format as shown in **Few shot Examples** below and entire output remains within the token limit and . Few shot Examples:- Example 1: { M85049 Backshells AS85049/52 Series - Straight cable clamp strain relief For connectors: MIL-DTL-5015 crimp MIL-DTL-26482 Series 2 AS81703 Series 3 MIL-DTL-83723 Series 1 & 3 Self-locking option: S (Self-locking) Shell size: 3, 8, 10, 12, 14, 16 Material and plating: N (Aluminum, electroless nickel) } Generalized PIN Layout: AS85049/52:10:S:N:Straight:MILDTL5015 Example 2: { M85049 Backshells AS85049/43 Series - 45° cable clamp strain relief For connectors: MIL-DTL-5015 crimp MIL-DTL-26482 Series 2 AS81703 Series 3 Shell size: 3, 10, 16 Material and plating: W (Aluminum, olive drab cadmium) } Generalized PIN Layout: AS85049/43:10:N:W:45:MILDTL5015 **Display JSON Output**: The format should follow this example below: { "M85049": { "43": { "AS85049/43:3:N:W:45:MILDTL5015", "AS85049/43:10:N:W:45:MILDTL5015", "AS85049/43:16:N:W:45:MILDTL5015", "AS85049/43:3:N:W:45:MILDTL26482" }, "52": { "AS85049/52:3:S:N:Straight:MILDTL5015", "AS85049/52:8:S:N:Straight:MILDTL5015", "AS85049/52:10:S:N:Straight:MILDTL5015", "AS85049/52:16:S:N:Straight:MILDTL83723" } // Continue for other shell sizes and connectors... } } Note : This Json file syntax above is just to know about the structure of the output format required. """ # %% prompt3=""" ### Objective: Design a **generalized solution** for generating Part Identification Numbers (PINs) that accommodates **multiple styles of PINs and part designations**. Using data blocks extracted from various parts, your goal is to: 1. **Challenge the generalization** of the PIN generation by identifying common patterns across parts, while ensuring the layout can handle a wide range of PIN styles and part designations. 2. **Develop a flexible solution** that can adapt to future part variations without major changes, allowing for various attributes and styles in the PINs. ### Instructions: 1. **Input Data Format:** Each data block represents a part and includes attributes such as: - **Series Name**: Identifier for the part series (e.g., `M85049/43`, `AS85049/52`). - **Connectors**: Lists the compatible connectors (e.g., `MILDTL5015`, `MILDTL38999`). - **Self-locking Option**: Specifies the locking mechanism, such as `S` for self-locking or `N` for non-self-locking. - **Shell Size**: Defines available shell sizes (e.g., `8, 10, 12`). - **Material and Plating**: Lists the material and its finish (e.g., `N: Nickel`, `W: Olive drab cadmium`). - **Angle**: Describes part angle (e.g., `Straight`, `45°`, `90°`). - **Other Features**: May include knurl style or other specifications relevant to the part. Example of a data block: ```plaintext { M85049 Backshells AS85049/43 Series - 45° cable clamp strain relief For connectors: MIL-DTL-5015 crimp MIL-DTL-26482 Series 2 AS81703 Series 3 MIL-DTL-83723 Series 1 & 3 Ordering information Self-locking option: Non self-locking Shell size: 3, 8, 10, 12, 14, 16 Material and plating: N: Aluminum, electroless nickel; W: Aluminum, olive drab cadmium } Main Task: Generalization Across Multiple Styles: Analyze the dataset and propose a flexible solution that accommodates different PIN structures and styles, ensuring it adapts to future variations. Analyze Data Blocks: Identify common attributes like shell size, self-locking options, and material. Also, note unique variations like connector types and angles. Challenge the Generalization: Design a solution that handles various formats, while also allowing flexibility for future part additions. Design a Flexible Layout: Propose a flexible PIN layout applicable to all parts, supporting different designations and attributes. Support for Multiple Styles: Your solution should accommodate variations, such as connector types, angles, and material options. The layout should allow for different formats without breaking the system. **Expected Output**: Generalized PIN Layout: Your proposed layout should be flexible and capable of handling multiple styles of PINs. Few shot Examples:- Example 1: { M85049 Backshells AS85049/52 Series - Straight cable clamp strain relief For connectors: MIL-DTL-5015 crimp MIL-DTL-26482 Series 2 AS81703 Series 3 MIL-DTL-83723 Series 1 & 3 Self-locking option: S (Self-locking) Shell size: 3, 8, 10, 12, 14, 16 Material and plating: N (Aluminum, electroless nickel) } Generalized PIN Layout: AS85049/52:10:S:N:Straight:MILDTL5015 Example 2: { M85049 Backshells AS85049/43 Series - 45° cable clamp strain relief For connectors: MIL-DTL-5015 crimp MIL-DTL-26482 Series 2 AS81703 Series 3 Shell size: 3, 10, 16 Material and plating: W (Aluminum, olive drab cadmium) } Generalized PIN Layout: AS85049/43:10:N:W:45:MILDTL5015 """ # %% prompt_list=[] prompt_list.append(prompt0) prompt_list.append(prompt1) prompt_list.append(prompt2) prompt_list.append(prompt3) #print(prompt_list[0]) # %% # Function to read text from a file def read_text_file(file_name): with open(file_name, 'r') as file: return file.read() # Function to combine input text with file text and add a heading def combine_text(input_text, file_name, heading): # Read content from the file file_text = read_text_file(file_name) # Create the combined content with the heading combined_text = f"{input_text}\n{heading}\n{file_text}" return combined_text # Example usage heading = "Data Blocks Extracted:" prompt_combine=[] for prompt in prompt_list: # Combine the file with the input text prompt_combine.append(combine_text(prompt,input_file,heading)) return prompt_combine # Define the function to call the model def call_model(model_name, input_file, prompt_name): prompt_combine = prompt_comb(input_file) if prompt_name == "Basic_v1": index = 0 elif prompt_name == "Basic_v2": index = 1 elif prompt_name == "Generalize_v1": index = 2 elif prompt_name == "Generalize_v2": index = 3 input_message = prompt_combine[index] # Call the selected model if model_name == "llama": output = call_model_llama(input_message) elif model_name == "gpt4": output = call_model_Gpt4(input_message) elif model_name == "gemini": output = call_model_Gemini(input_message) else: output = call_model_Gemini1(input_message) # Decode the output decoded_string = html.unescape(output) return decoded_string # Define the Gradio interface def launch_interface(): # Define the input components model_dropdown = gr.Dropdown(["llama", "gpt4", "gemini", "gemini1"], label="Select Model") input_file = gr.File(label="Upload JSON File") prompt_dropdown = gr.Dropdown(["Basic_v1", "Basic_v2", "Generalize_v1", "Generalize_v2"], label="Select Prompt") # Define the output component output_text = gr.Textbox(label="Output", interactive=False) # Create the Gradio interface with dark theme interface = gr.Interface( fn=call_model, inputs=[model_dropdown, input_file, prompt_dropdown], outputs=output_text, title="Part Identification Number (PINs)", description="Choose a model **(llama-preferred)** and Upload a JSON file, select a prompt **(Generalize_v2-preferred)**, to generalize the PINs.", theme="dark", # Set the theme to dark ) return interface # Launch the Gradio app if __name__ == "__main__": import sys sys.stdout.reconfigure(encoding='utf-8') interface = launch_interface() interface.launch() # Create a public link