Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
|
|
|
| 4 |
classifier = pipeline(
|
| 5 |
"text-classification",
|
| 6 |
model="WarTitan2077/Number-Classifier",
|
|
@@ -11,7 +12,7 @@ classifier = pipeline(
|
|
| 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 |
-
#
|
| 15 |
@gr.predict()
|
| 16 |
def classify_numbers(input1: str, input2: str, input3: str) -> dict:
|
| 17 |
inputs = {"Input1": input1, "Input2": input2, "Input3": input3}
|
|
@@ -19,23 +20,20 @@ def classify_numbers(input1: str, input2: str, input3: str) -> dict:
|
|
| 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
|
| 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 |
-
|
| 39 |
-
|
| 40 |
|
| 41 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load model
|
| 5 |
classifier = pipeline(
|
| 6 |
"text-classification",
|
| 7 |
model="WarTitan2077/Number-Classifier",
|
|
|
|
| 12 |
labels = ["Symbolic", "Numeric", "Natural", "Integer", "Rational", "Irrational", "Real", "Prime", "Composite"]
|
| 13 |
label_map = {f"LABEL_{i}": label for i, label in enumerate(labels)}
|
| 14 |
|
| 15 |
+
# ✅ This function gets exposed at /run/predict
|
| 16 |
@gr.predict()
|
| 17 |
def classify_numbers(input1: str, input2: str, input3: str) -> dict:
|
| 18 |
inputs = {"Input1": input1, "Input2": input2, "Input3": input3}
|
|
|
|
| 20 |
for name, value in inputs.items():
|
| 21 |
if value.strip():
|
| 22 |
output = classifier(value)[0]
|
| 23 |
+
result = {label_map[item["label"]]: round(item["score"], 3) for item in output}
|
|
|
|
|
|
|
|
|
|
| 24 |
results[name] = result
|
| 25 |
else:
|
| 26 |
results[name] = {}
|
| 27 |
return results
|
| 28 |
|
| 29 |
+
# Optional web UI for users
|
| 30 |
with gr.Blocks() as demo:
|
| 31 |
with gr.Row():
|
| 32 |
input1 = gr.Textbox(label="Input 1")
|
| 33 |
input2 = gr.Textbox(label="Input 2")
|
| 34 |
input3 = gr.Textbox(label="Input 3")
|
| 35 |
output = gr.JSON()
|
| 36 |
+
btn = gr.Button("Classify")
|
| 37 |
+
btn.click(fn=classify_numbers, inputs=[input1, input2, input3], outputs=output)
|
| 38 |
|
| 39 |
demo.launch()
|