Pisethan commited on
Commit
db4681c
·
verified ·
1 Parent(s): 88bd3a1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
3
+
4
+ # Load your model from Hugging Face Hub
5
+ MODEL_NAME = "Pisethan/sangapac-math"
6
+ reverse_label_mapping = {
7
+ 0: "arithmetic",
8
+ 1: "multiplication",
9
+ 2: "division",
10
+ 3: "algebra",
11
+ 4: "geometry",
12
+ }
13
+
14
+ # Load tokenizer and model
15
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
16
+ model = AutoModelForSequenceClassification.from_pretrained(MODEL_NAME)
17
+ classifier = pipeline("text-classification", model=model, tokenizer=tokenizer)
18
+
19
+ def predict(input_text):
20
+ # Predict using the model
21
+ result = classifier(input_text)
22
+ label_id = int(result[0]["label"].split("_")[-1]) # Extract label ID
23
+ category = reverse_label_mapping[label_id] # Map label to category
24
+
25
+ # Return prediction result
26
+ return {
27
+ "Category": category,
28
+ "Confidence": result[0]["score"],
29
+ }
30
+
31
+ # Gradio interface
32
+ interface = gr.Interface(
33
+ fn=predict,
34
+ inputs=gr.Textbox(lines=2, placeholder="Enter a math problem..."),
35
+ outputs="json",
36
+ title="Sangapac Math Model",
37
+ description="A model to classify math problems into categories like Arithmetic, Multiplication, Division, Algebra, and Geometry.",
38
+ )
39
+
40
+ # Launch the app
41
+ interface.launch()