Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
|
|
|
| 3 |
|
| 4 |
# Load your fine-tuned multi-label classification model
|
| 5 |
classifier = pipeline(
|
|
@@ -15,28 +16,22 @@ label_map = {f"LABEL_{i}": label for i, label in enumerate(labels)}
|
|
| 15 |
|
| 16 |
# Define the prediction function
|
| 17 |
def classify_numbers(input1, input2, input3):
|
| 18 |
-
inputs = {
|
| 19 |
-
|
| 20 |
-
"Input2": input2,
|
| 21 |
-
"Input3": input3
|
| 22 |
-
}
|
| 23 |
-
|
| 24 |
-
print(f"Received inputs: {inputs}") # Log inputs
|
| 25 |
|
| 26 |
results = {}
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
print(f"Returning results: {results}") # Log outputs
|
| 40 |
|
| 41 |
return results
|
| 42 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
+
import datetime
|
| 4 |
|
| 5 |
# Load your fine-tuned multi-label classification model
|
| 6 |
classifier = pipeline(
|
|
|
|
| 16 |
|
| 17 |
# Define the prediction function
|
| 18 |
def classify_numbers(input1, input2, input3):
|
| 19 |
+
inputs = {"Input1": input1, "Input2": input2, "Input3": input3}
|
| 20 |
+
print(f"[{datetime.datetime.now()}] Received inputs: {inputs}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
results = {}
|
| 23 |
+
try:
|
| 24 |
+
for name, value in inputs.items():
|
| 25 |
+
if value.strip():
|
| 26 |
+
output = classifier(value)[0]
|
| 27 |
+
result = {label_map[item["label"]]: round(item["score"], 3) for item in output}
|
| 28 |
+
results[name] = result
|
| 29 |
+
else:
|
| 30 |
+
results[name] = {}
|
| 31 |
+
print(f"[{datetime.datetime.now()}] Returning results: {results}")
|
| 32 |
+
except Exception as e:
|
| 33 |
+
print(f"[{datetime.datetime.now()}] Error during classification: {e}")
|
| 34 |
+
raise e
|
|
|
|
| 35 |
|
| 36 |
return results
|
| 37 |
|