Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,16 +1,4 @@
|
|
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
|
@@ -43,25 +31,34 @@ def process_with_model(pec_number):
|
|
43 |
return outputs.last_hidden_state.mean(dim=1).squeeze().tolist()
|
44 |
|
45 |
# Combine both functions to create a prediction
|
46 |
-
def predict(pec_number):
|
47 |
try:
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
49 |
name = get_name(pec_number, df)
|
50 |
model_output = process_with_model(pec_number)
|
51 |
return f"Name: {name}\nModel Output: {model_output}"
|
52 |
except FileNotFoundError as e:
|
53 |
return str(e)
|
54 |
|
55 |
-
# Build the Gradio interface
|
56 |
iface = gr.Interface(
|
57 |
fn=predict,
|
58 |
-
inputs=
|
|
|
|
|
|
|
59 |
outputs="text",
|
60 |
title="PEC Number Lookup with Model Integration",
|
61 |
-
description="Enter a PEC number to retrieve the corresponding name and process it with a Hugging Face model."
|
62 |
)
|
63 |
|
64 |
# Run the Gradio interface
|
65 |
if __name__ == "__main__":
|
66 |
iface.launch()
|
67 |
|
|
|
|
1 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
import pandas as pd
|
3 |
import gradio as gr
|
4 |
from transformers import AutoModel, AutoTokenizer
|
|
|
31 |
return outputs.last_hidden_state.mean(dim=1).squeeze().tolist()
|
32 |
|
33 |
# Combine both functions to create a prediction
|
34 |
+
def predict(pec_number, file):
|
35 |
try:
|
36 |
+
# Load the dataset from the uploaded file if provided
|
37 |
+
if file is not None:
|
38 |
+
df = pd.read_excel(file.name)
|
39 |
+
else:
|
40 |
+
df = load_dataset()
|
41 |
+
|
42 |
name = get_name(pec_number, df)
|
43 |
model_output = process_with_model(pec_number)
|
44 |
return f"Name: {name}\nModel Output: {model_output}"
|
45 |
except FileNotFoundError as e:
|
46 |
return str(e)
|
47 |
|
48 |
+
# Build the Gradio interface with file upload option
|
49 |
iface = gr.Interface(
|
50 |
fn=predict,
|
51 |
+
inputs=[
|
52 |
+
gr.Textbox(lines=1, placeholder="Enter PEC Number..."),
|
53 |
+
gr.File(label="Upload PEC Numbers and Names file (optional)")
|
54 |
+
],
|
55 |
outputs="text",
|
56 |
title="PEC Number Lookup with Model Integration",
|
57 |
+
description="Enter a PEC number to retrieve the corresponding name and process it with a Hugging Face model. Optionally, upload the Excel file if not found."
|
58 |
)
|
59 |
|
60 |
# Run the Gradio interface
|
61 |
if __name__ == "__main__":
|
62 |
iface.launch()
|
63 |
|
64 |
+
|