Spaces:
Sleeping
Sleeping
Commit
·
aabbc15
1
Parent(s):
ae19836
FIX: Simplified probability mapping in Gradio UI to resolve 100% display issue.
Browse files
app.py
CHANGED
|
@@ -97,23 +97,25 @@ async def get_predict(text: str):
|
|
| 97 |
raise HTTPException(status_code=500, detail=f"Internal Server Error during GET prediction: {e}")
|
| 98 |
|
| 99 |
def gradio_interface_fn(text_input):
|
|
|
|
| 100 |
if not text_input or not text_input.strip():
|
| 101 |
return "Please enter text for classification.", None
|
| 102 |
|
| 103 |
try:
|
| 104 |
result = predict_svm([text_input])[0]
|
|
|
|
| 105 |
prediction_label = result.prediction
|
| 106 |
|
| 107 |
prob_display = {
|
| 108 |
-
|
| 109 |
-
LABEL_1
|
| 110 |
}
|
| 111 |
|
| 112 |
return prediction_label, prob_display
|
| 113 |
|
| 114 |
except Exception as e:
|
| 115 |
return f"An error occurred: {str(e)}", None
|
| 116 |
-
|
| 117 |
ui = gr.Interface(
|
| 118 |
fn=gradio_interface_fn,
|
| 119 |
inputs=gr.Textbox(lines=2, placeholder="Enter a message to classify...", label="Input Text"),
|
|
|
|
| 97 |
raise HTTPException(status_code=500, detail=f"Internal Server Error during GET prediction: {e}")
|
| 98 |
|
| 99 |
def gradio_interface_fn(text_input):
|
| 100 |
+
"""Interface function to be called by Gradio UI."""
|
| 101 |
if not text_input or not text_input.strip():
|
| 102 |
return "Please enter text for classification.", None
|
| 103 |
|
| 104 |
try:
|
| 105 |
result = predict_svm([text_input])[0]
|
| 106 |
+
|
| 107 |
prediction_label = result.prediction
|
| 108 |
|
| 109 |
prob_display = {
|
| 110 |
+
LABEL_0: result.probability_NOT_STOP,
|
| 111 |
+
LABEL_1: result.probability_STOP
|
| 112 |
}
|
| 113 |
|
| 114 |
return prediction_label, prob_display
|
| 115 |
|
| 116 |
except Exception as e:
|
| 117 |
return f"An error occurred: {str(e)}", None
|
| 118 |
+
|
| 119 |
ui = gr.Interface(
|
| 120 |
fn=gradio_interface_fn,
|
| 121 |
inputs=gr.Textbox(lines=2, placeholder="Enter a message to classify...", label="Input Text"),
|