atifsial123 commited on
Commit
8272ce2
·
verified ·
1 Parent(s): c68cde2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -3
app.py CHANGED
@@ -1,4 +1,16 @@
1
  import os
 
 
 
 
 
 
 
 
 
 
 
 
2
  import pandas as pd
3
  import gradio as gr
4
  from transformers import AutoModel, AutoTokenizer
@@ -26,8 +38,7 @@ def process_with_model(pec_number):
26
  inputs = tokenizer(pec_number, return_tensors="pt")
27
  with torch.no_grad():
28
  outputs = model(**inputs)
29
- # Here, we simply return the last hidden state as a string representation
30
- # In a real application, you might want to use this in a more meaningful way
31
  return outputs.last_hidden_state.mean(dim=1).squeeze().tolist()
32
 
33
  # Combine both functions to create a prediction
@@ -52,4 +63,3 @@ iface = gr.Interface(
52
  if __name__ == "__main__":
53
  iface.launch()
54
 
55
-
 
1
  import os
2
+ import subprocess
3
+
4
+ # Function to install a package if it is not already installed
5
+ def install(package):
6
+ subprocess.check_call([os.sys.executable, "-m", "pip", "install", package])
7
+
8
+ # Ensure the necessary packages are installed
9
+ install("transformers")
10
+ install("torch")
11
+ install("pandas")
12
+ install("gradio")
13
+
14
  import pandas as pd
15
  import gradio as gr
16
  from transformers import AutoModel, AutoTokenizer
 
38
  inputs = tokenizer(pec_number, return_tensors="pt")
39
  with torch.no_grad():
40
  outputs = model(**inputs)
41
+ # Return a simple representation of the model's output
 
42
  return outputs.last_hidden_state.mean(dim=1).squeeze().tolist()
43
 
44
  # Combine both functions to create a prediction
 
63
  if __name__ == "__main__":
64
  iface.launch()
65