WarTitan2077 commited on
Commit
a135394
·
verified ·
1 Parent(s): 4c7f128

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -14
app.py CHANGED
@@ -1,7 +1,6 @@
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,9 +11,7 @@ classifier = pipeline(
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}
19
  results = {}
20
  for name, value in inputs.items():
@@ -26,14 +23,22 @@ def classify_numbers(input1: str, input2: str, input3: str) -> dict:
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()
 
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
 
4
  classifier = pipeline(
5
  "text-classification",
6
  model="WarTitan2077/Number-Classifier",
 
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
+ def classify_numbers(input1, input2, input3):
 
 
15
  inputs = {"Input1": input1, "Input2": input2, "Input3": input3}
16
  results = {}
17
  for name, value in inputs.items():
 
23
  results[name] = {}
24
  return results
25
 
26
+ # This creates /predict endpoint usable by Unity
27
+ demo = gr.Interface(
28
+ fn=classify_numbers,
29
+ inputs=[
30
+ gr.Textbox(label="Input 1"),
31
+ gr.Textbox(label="Input 2"),
32
+ gr.Textbox(label="Input 3")
33
+ ],
34
+ outputs=gr.JSON(label="Predictions"),
35
+ title="Number Classifier",
36
+ description="Enter up to three inputs to classify them as Symbolic, Numeric, Prime, etc.",
37
+ allow_flagging="never",
38
+ examples=None,
39
+ cache_examples=False,
40
+ api_name="/predict" # ✅ This exposes /predict endpoint
41
+ )
42
 
43
+ if __name__ == "__main__":
44
+ demo.launch()