WarTitan2077 commited on
Commit
5744d54
·
verified ·
1 Parent(s): 3444d20

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -21
app.py CHANGED
@@ -1,14 +1,15 @@
1
- import gradio as gr
2
  from transformers import pipeline
 
3
 
4
- # Load your model from Hugging Face
5
  classifier = pipeline(
6
  "text-classification",
7
- model="WarTitan2077/Number-Classifier", # Replace with your Hugging Face username/model
8
- tokenizer="WarTitan2077/Number-Classifier", # Same here
9
- top_k=None # Return all labels with scores
10
  )
11
 
 
12
  label_map = {
13
  "LABEL_0": "Symbolic1",
14
  "LABEL_1": "Numeric1",
@@ -19,7 +20,6 @@ label_map = {
19
  "LABEL_6": "Real1",
20
  "LABEL_7": "Prime1",
21
  "LABEL_8": "Composite1",
22
-
23
  "LABEL_9": "Symbolic2",
24
  "LABEL_10": "Numeric2",
25
  "LABEL_11": "Natural2",
@@ -29,7 +29,6 @@ label_map = {
29
  "LABEL_15": "Real2",
30
  "LABEL_16": "Prime2",
31
  "LABEL_17": "Composite2",
32
-
33
  "LABEL_18": "Symbolic3",
34
  "LABEL_19": "Numeric3",
35
  "LABEL_20": "Natural3",
@@ -41,26 +40,23 @@ label_map = {
41
  "LABEL_26": "Composite3"
42
  }
43
 
 
 
 
 
 
44
 
45
- # Define the prediction function
46
- def classify_numbers(n1, n2, n3):
47
- input_str = f"{n1}, {n2}, {n3}"
48
- result = classifier(input_str)
49
- # Format the results nicely
50
- output = {item["label"]: round(item["score"], 3) for item in result[0]}
51
  return output
52
 
53
- # Create Gradio interface
54
  iface = gr.Interface(
55
  fn=classify_numbers,
56
- inputs=[
57
- gr.Textbox(label="Input 1"),
58
- gr.Textbox(label="Input 2"),
59
- gr.Textbox(label="Input 3")
60
- ],
61
- output = {label_map[item["label"]]: round(item["score"], 3) for item in result[0]}
62
  title="Number Classifier",
63
- description="Enter 3 numbers or symbols (e.g., 3.14, pi, 2) to classify them."
64
  )
65
 
66
  iface.launch()
 
 
1
  from transformers import pipeline
2
+ import gradio as gr
3
 
4
+ # Load model and tokenizer
5
  classifier = pipeline(
6
  "text-classification",
7
+ model="WarTitan2077/Number-Classifier",
8
+ tokenizer="WarTitan2077/Number-Classifier",
9
+ top_k=None
10
  )
11
 
12
+ # Map Hugging Face's LABEL_X to human-readable labels
13
  label_map = {
14
  "LABEL_0": "Symbolic1",
15
  "LABEL_1": "Numeric1",
 
20
  "LABEL_6": "Real1",
21
  "LABEL_7": "Prime1",
22
  "LABEL_8": "Composite1",
 
23
  "LABEL_9": "Symbolic2",
24
  "LABEL_10": "Numeric2",
25
  "LABEL_11": "Natural2",
 
29
  "LABEL_15": "Real2",
30
  "LABEL_16": "Prime2",
31
  "LABEL_17": "Composite2",
 
32
  "LABEL_18": "Symbolic3",
33
  "LABEL_19": "Numeric3",
34
  "LABEL_20": "Natural3",
 
40
  "LABEL_26": "Composite3"
41
  }
42
 
43
+ # Prediction function
44
+ def classify_numbers(input1, input2, input3):
45
+ # Combine inputs into a single string (or modify to match your training format)
46
+ text = f"{input1}, {input2}, {input3}"
47
+ result = classifier(text)
48
 
49
+ # Convert raw LABEL_X output into readable format
50
+ output = {label_map[item["label"]]: round(item["score"], 3) for item in result[0]}
 
 
 
 
51
  return output
52
 
53
+ # Gradio UI
54
  iface = gr.Interface(
55
  fn=classify_numbers,
56
+ inputs=["text", "text", "text"],
57
+ outputs="json",
 
 
 
 
58
  title="Number Classifier",
59
+ description="Enter three numbers or expressions to classify them (e.g., 2, pi, 3.5)"
60
  )
61
 
62
  iface.launch()