WarTitan2077 commited on
Commit
9b30311
·
verified ·
1 Parent(s): 99d492c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -40
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
- # 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
 
38
-
39
- # Define Gradio interface
40
- inputs = [
41
- gr.Textbox(label="Input 1"),
42
- gr.Textbox(label="Input 2"),
43
- gr.Textbox(label="Input 3")
44
- ]
45
-
46
- output = gr.JSON(label="Predictions")
47
-
48
- demo = gr.Interface(
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()