Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -24,7 +24,7 @@ except Exception as e:
|
|
24 |
|
25 |
def predict(input_text):
|
26 |
if classifier is None:
|
27 |
-
return {"Error": "Model not loaded properly."}
|
28 |
|
29 |
try:
|
30 |
# Predict the category
|
@@ -37,14 +37,20 @@ def predict(input_text):
|
|
37 |
output = data["output"]
|
38 |
metadata = data["metadata"]
|
39 |
|
40 |
-
|
|
|
|
|
|
|
|
|
41 |
"Category": label,
|
42 |
"Confidence": score,
|
43 |
"Output (Result)": output,
|
44 |
"Metadata": metadata,
|
45 |
}
|
|
|
|
|
46 |
except Exception as e:
|
47 |
-
return {"Error": str(e)}
|
48 |
|
49 |
# Gradio interface
|
50 |
import gradio as gr
|
@@ -52,7 +58,10 @@ import gradio as gr
|
|
52 |
interface = gr.Interface(
|
53 |
fn=predict,
|
54 |
inputs=gr.Textbox(lines=2, placeholder="Enter a math problem..."),
|
55 |
-
outputs=
|
|
|
|
|
|
|
56 |
title="Sangapac Math Model",
|
57 |
description="A model to classify math problems into categories like Arithmetic, Multiplication, Division, Algebra, and Geometry.",
|
58 |
)
|
|
|
24 |
|
25 |
def predict(input_text):
|
26 |
if classifier is None:
|
27 |
+
return "Model not loaded properly.", {"Error": "Model not loaded properly."}
|
28 |
|
29 |
try:
|
30 |
# Predict the category
|
|
|
37 |
output = data["output"]
|
38 |
metadata = data["metadata"]
|
39 |
|
40 |
+
# Create a simple result string
|
41 |
+
simple_result = f"Category: {label}\nConfidence: {score:.2f}\nResult: {output}"
|
42 |
+
|
43 |
+
# Create the full JSON output
|
44 |
+
detailed_result = {
|
45 |
"Category": label,
|
46 |
"Confidence": score,
|
47 |
"Output (Result)": output,
|
48 |
"Metadata": metadata,
|
49 |
}
|
50 |
+
|
51 |
+
return simple_result, detailed_result
|
52 |
except Exception as e:
|
53 |
+
return "An error occurred.", {"Error": str(e)}
|
54 |
|
55 |
# Gradio interface
|
56 |
import gradio as gr
|
|
|
58 |
interface = gr.Interface(
|
59 |
fn=predict,
|
60 |
inputs=gr.Textbox(lines=2, placeholder="Enter a math problem..."),
|
61 |
+
outputs=[
|
62 |
+
gr.Textbox(label="Simple Output"), # Display only the result
|
63 |
+
gr.JSON(label="Detailed JSON Output"), # Display full JSON
|
64 |
+
],
|
65 |
title="Sangapac Math Model",
|
66 |
description="A model to classify math problems into categories like Arithmetic, Multiplication, Division, Algebra, and Geometry.",
|
67 |
)
|