atifsial123 commited on
Commit
f27514f
1 Parent(s): a89484e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -15
app.py CHANGED
@@ -21,8 +21,8 @@ tokenizer = AutoTokenizer.from_pretrained("Alibaba-NLP/gte-multilingual-base", t
21
  model = AutoModel.from_pretrained("Alibaba-NLP/gte-multilingual-base", trust_remote_code=True)
22
 
23
  # Load the dataset containing PEC numbers and names
24
- def load_dataset(file_path=None):
25
- if file_path and os.path.exists(file_path):
26
  df = pd.read_excel(file_path)
27
  else:
28
  raise FileNotFoundError(f"File not found: {file_path}")
@@ -31,7 +31,7 @@ def load_dataset(file_path=None):
31
  # Function to get the name based on the PEC number
32
  def get_name(pec_number, df):
33
  df['PEC No.'] = df['PEC No.'].str.strip().str.upper()
34
- pec_number = pec_number.strip().upper()
35
 
36
  result = df[df['PEC No.'] == pec_number]
37
 
@@ -48,13 +48,10 @@ def process_with_model(pec_number):
48
  return outputs.last_hidden_state.mean(dim=1).squeeze().tolist()
49
 
50
  # Combine both functions to create a prediction
51
- def predict(pec_number, file):
52
  try:
53
- # Load the dataset from the uploaded file if provided
54
- if file is not None:
55
- df = pd.read_excel(file.name)
56
- else:
57
- return "Please upload the PEC Numbers and Names file."
58
 
59
  name = get_name(pec_number, df)
60
  model_output = process_with_model(pec_number)
@@ -62,16 +59,13 @@ def predict(pec_number, file):
62
  except FileNotFoundError as e:
63
  return str(e)
64
 
65
- # Build the Gradio interface with file upload option
66
  iface = gr.Interface(
67
  fn=predict,
68
- inputs=[
69
- gr.Textbox(lines=1, placeholder="Enter PEC Number..."),
70
- gr.File(label="Upload PEC Numbers and Names file")
71
- ],
72
  outputs="text",
73
  title="PEC Number to Name Lookup",
74
- description="Enter a PEC number to retrieve the corresponding name and process it with a Hugging Face model. Please upload the Excel file."
75
  )
76
 
77
  # Run the Gradio interface
 
21
  model = AutoModel.from_pretrained("Alibaba-NLP/gte-multilingual-base", trust_remote_code=True)
22
 
23
  # Load the dataset containing PEC numbers and names
24
+ def load_dataset(file_path='PEC_Numbers_and_Names.xlsx'):
25
+ if os.path.exists(file_path):
26
  df = pd.read_excel(file_path)
27
  else:
28
  raise FileNotFoundError(f"File not found: {file_path}")
 
31
  # Function to get the name based on the PEC number
32
  def get_name(pec_number, df):
33
  df['PEC No.'] = df['PEC No.'].str.strip().str.upper()
34
+ pec_number = pec_number.strip().str.upper()
35
 
36
  result = df[df['PEC No.'] == pec_number]
37
 
 
48
  return outputs.last_hidden_state.mean(dim=1).squeeze().tolist()
49
 
50
  # Combine both functions to create a prediction
51
+ def predict(pec_number):
52
  try:
53
+ # Load the dataset from the root directory
54
+ df = load_dataset()
 
 
 
55
 
56
  name = get_name(pec_number, df)
57
  model_output = process_with_model(pec_number)
 
59
  except FileNotFoundError as e:
60
  return str(e)
61
 
62
+ # Build the Gradio interface without the file upload option
63
  iface = gr.Interface(
64
  fn=predict,
65
+ inputs=gr.Textbox(lines=1, placeholder="Enter PEC Number..."),
 
 
 
66
  outputs="text",
67
  title="PEC Number to Name Lookup",
68
+ description="Enter a PEC number to retrieve the corresponding name and process it with a Hugging Face model."
69
  )
70
 
71
  # Run the Gradio interface