Spaces:
Sleeping
Sleeping
import os | |
os.system('pip install transformers') | |
# Import the necessary libraries | |
import os | |
os.system('pip install torch') | |
from transformers import AutoModel, AutoTokenizer | |
import torch | |
from torch.utils.data import DataLoader, Dataset | |
from sklearn.model_selection import train_test_split | |
import pandas as pd | |
import gradio as gr | |
# Load the pre-trained model and tokenizer | |
model = AutoModel.from_pretrained("Alibaba-NLP/gte-multilingual-base", trust_remote_code=True) | |
tokenizer = AutoTokenizer.from_pretrained("Alibaba-NLP/gte-multilingual-base", trust_remote_code=True) | |
# Function to load dataset (adjust this function if your dataset is complex) | |
def load_dataset(): | |
df = pd.read_excel("your_dataset.xlsx") # Ensure this file exists in your working directory | |
print("Columns in the dataset:", df.columns.tolist()) | |
return df | |
# Example function to search by name and return the PEC number | |
def search_by_name(name, df): | |
name_matches = df[df['Name'].str.contains(name, case=False, na=False)] | |
if not name_matches.empty: | |
return f"Your PEC number: {name_matches['PEC No'].values[0]}" | |
else: | |
return "No matches found for your name." | |
# Gradio interface | |
def build_interface(): | |
df = load_dataset() # Load your dataset | |
iface = gr.Interface( | |
fn=lambda name: search_by_name(name, df), | |
inputs=gr.Textbox(label="Please write your Name"), | |
outputs=gr.Textbox(label="Your PEC number"), | |
title="PEC Number Lookup", | |
description="Enter your name to find your PEC number." | |
) | |
return iface | |
# Main function to run the Gradio app | |
if __name__ == "__main__": | |
iface = build_interface() | |
iface.launch() | |