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 transformers import AutoModel, AutoTokenizer | |
import torch | |
from torch.utils.data import DataLoader, Dataset | |
from sklearn.model_selection import train_test_split | |
from google.colab import files | |
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) | |
# Upload your dataset | |
uploaded = files.upload() | |
# Load the dataset | |
filename = next(iter(uploaded)) # Automatically get the first uploaded file's name | |
df = pd.read_excel(filename) # Read the uploaded Excel file | |
# Display the columns in the uploaded DataFrame to help identify correct names | |
print("Columns in the dataset:", df.columns.tolist()) | |
# Function to search by name and return the PEC number | |
def search_by_name(name): | |
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 with the updated syntax | |
iface = gr.Interface( | |
fn=search_by_name, | |
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." | |
) | |
# Launch the Gradio interface | |
iface.launch() | |