Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,6 +20,7 @@ from torch.utils.data import DataLoader, Dataset
|
|
| 20 |
from sklearn.model_selection import train_test_split
|
| 21 |
import pandas as pd
|
| 22 |
import gradio as gr
|
|
|
|
| 23 |
|
| 24 |
# Load the pre-trained model and tokenizer
|
| 25 |
model = AutoModel.from_pretrained("Alibaba-NLP/gte-multilingual-base", trust_remote_code=True)
|
|
@@ -27,15 +28,20 @@ tokenizer = AutoTokenizer.from_pretrained("Alibaba-NLP/gte-multilingual-base", t
|
|
| 27 |
|
| 28 |
# Function to load the dataset
|
| 29 |
def load_dataset():
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
print("Columns in the dataset:", df.columns.tolist())
|
| 32 |
return df
|
| 33 |
|
| 34 |
# Function to search by name and return the PEC number
|
| 35 |
def search_by_name(name, df):
|
| 36 |
-
name_matches = df[df['
|
| 37 |
if not name_matches.empty:
|
| 38 |
-
return f"Your PEC number: {name_matches['PEC
|
| 39 |
else:
|
| 40 |
return "No matches found for your name."
|
| 41 |
|
|
@@ -53,5 +59,9 @@ def build_interface():
|
|
| 53 |
|
| 54 |
# Main function to run the Gradio app
|
| 55 |
if __name__ == "__main__":
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
from sklearn.model_selection import train_test_split
|
| 21 |
import pandas as pd
|
| 22 |
import gradio as gr
|
| 23 |
+
import os
|
| 24 |
|
| 25 |
# Load the pre-trained model and tokenizer
|
| 26 |
model = AutoModel.from_pretrained("Alibaba-NLP/gte-multilingual-base", trust_remote_code=True)
|
|
|
|
| 28 |
|
| 29 |
# Function to load the dataset
|
| 30 |
def load_dataset():
|
| 31 |
+
# Use the uploaded file path
|
| 32 |
+
file_path = "Valid-part-2.xlsx"
|
| 33 |
+
if not os.path.exists(file_path):
|
| 34 |
+
raise FileNotFoundError(f"Dataset not found. Please ensure that '{file_path}' exists.")
|
| 35 |
+
|
| 36 |
+
df = pd.read_excel(file_path) # Load the Excel file
|
| 37 |
print("Columns in the dataset:", df.columns.tolist())
|
| 38 |
return df
|
| 39 |
|
| 40 |
# Function to search by name and return the PEC number
|
| 41 |
def search_by_name(name, df):
|
| 42 |
+
name_matches = df[df['name'].str.contains(name, case=False, na=False)]
|
| 43 |
if not name_matches.empty:
|
| 44 |
+
return f"Your PEC number: {name_matches['PEC number'].values[0]}"
|
| 45 |
else:
|
| 46 |
return "No matches found for your name."
|
| 47 |
|
|
|
|
| 59 |
|
| 60 |
# Main function to run the Gradio app
|
| 61 |
if __name__ == "__main__":
|
| 62 |
+
try:
|
| 63 |
+
iface = build_interface()
|
| 64 |
+
iface.launch()
|
| 65 |
+
except FileNotFoundError as e:
|
| 66 |
+
print(str(e))
|
| 67 |
+
|