Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,6 @@
|
|
| 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(
|
| 7 |
"text-classification",
|
| 8 |
model="WarTitan2077/Number-Classifier",
|
|
@@ -10,48 +8,34 @@ classifier = pipeline(
|
|
| 10 |
top_k=None
|
| 11 |
)
|
| 12 |
|
| 13 |
-
# Define labels in the correct order
|
| 14 |
labels = ["Symbolic", "Numeric", "Natural", "Integer", "Rational", "Irrational", "Real", "Prime", "Composite"]
|
| 15 |
label_map = {f"LABEL_{i}": label for i, label in enumerate(labels)}
|
| 16 |
|
| 17 |
-
#
|
| 18 |
-
|
|
|
|
| 19 |
inputs = {"Input1": input1, "Input2": input2, "Input3": input3}
|
| 20 |
-
print(f"[{datetime.datetime.now()}] Received inputs: {inputs}")
|
| 21 |
-
|
| 22 |
results = {}
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
print(f"[{datetime.datetime.now()}] Error during classification: {e}")
|
| 34 |
-
raise e
|
| 35 |
-
|
| 36 |
return results
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
demo
|
| 49 |
-
fn=classify_numbers,
|
| 50 |
-
inputs=inputs,
|
| 51 |
-
outputs=output,
|
| 52 |
-
title="Number Classifier",
|
| 53 |
-
description="Enter up to three inputs to classify them as Symbolic, Numeric, Prime, etc."
|
| 54 |
-
)
|
| 55 |
-
|
| 56 |
-
if __name__ == "__main__":
|
| 57 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
|
|
|
| 3 |
|
|
|
|
| 4 |
classifier = pipeline(
|
| 5 |
"text-classification",
|
| 6 |
model="WarTitan2077/Number-Classifier",
|
|
|
|
| 8 |
top_k=None
|
| 9 |
)
|
| 10 |
|
|
|
|
| 11 |
labels = ["Symbolic", "Numeric", "Natural", "Integer", "Rational", "Irrational", "Real", "Prime", "Composite"]
|
| 12 |
label_map = {f"LABEL_{i}": label for i, label in enumerate(labels)}
|
| 13 |
|
| 14 |
+
# 🎯 Route exposed at /predict
|
| 15 |
+
@gr.predict()
|
| 16 |
+
def classify_numbers(input1: str, input2: str, input3: str) -> dict:
|
| 17 |
inputs = {"Input1": input1, "Input2": input2, "Input3": input3}
|
|
|
|
|
|
|
| 18 |
results = {}
|
| 19 |
+
for name, value in inputs.items():
|
| 20 |
+
if value.strip():
|
| 21 |
+
output = classifier(value)[0]
|
| 22 |
+
result = {
|
| 23 |
+
label_map[item["label"]]: round(item["score"], 3)
|
| 24 |
+
for item in output
|
| 25 |
+
}
|
| 26 |
+
results[name] = result
|
| 27 |
+
else:
|
| 28 |
+
results[name] = {}
|
|
|
|
|
|
|
|
|
|
| 29 |
return results
|
| 30 |
|
| 31 |
+
# Optional web UI (so Space still looks nice)
|
| 32 |
+
with gr.Blocks() as demo:
|
| 33 |
+
with gr.Row():
|
| 34 |
+
input1 = gr.Textbox(label="Input 1")
|
| 35 |
+
input2 = gr.Textbox(label="Input 2")
|
| 36 |
+
input3 = gr.Textbox(label="Input 3")
|
| 37 |
+
output = gr.JSON()
|
| 38 |
+
button = gr.Button("Classify")
|
| 39 |
+
button.click(fn=classify_numbers, inputs=[input1, input2, input3], outputs=output)
|
| 40 |
+
|
| 41 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|