Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from setfit import SetFitModel
|
3 |
+
|
4 |
+
try:
|
5 |
+
transactional_model = SetFitModel.from_pretrained("edugargar/risk_model")
|
6 |
+
except Exception as e:
|
7 |
+
raise RuntimeError("Failed to load model: " + str(e))
|
8 |
+
|
9 |
+
def predict_and_score(text):
|
10 |
+
preds = transactional_model([text])
|
11 |
+
predicted_class = preds[0]
|
12 |
+
probs = transactional_model.predict_proba([text])
|
13 |
+
probability_distribution = probs[0]
|
14 |
+
probability_str = ", ".join(f"{p:.4f}" for p in probability_distribution)
|
15 |
+
return predicted_class, probability_str
|
16 |
+
|
17 |
+
with gr.Blocks() as demo:
|
18 |
+
gr.Markdown("## Risk Model Prediction")
|
19 |
+
text_input = gr.Textbox(label="Enter your text here:")
|
20 |
+
predict_button = gr.Button("Predict")
|
21 |
+
prediction_output = gr.Textbox(label="Predicted Class:")
|
22 |
+
score_output = gr.Textbox(label="Score (Probability Distribution):")
|
23 |
+
|
24 |
+
predict_button.click(fn=predict_and_score,
|
25 |
+
inputs=[text_input],
|
26 |
+
outputs=[prediction_output, score_output])
|
27 |
+
|
28 |
+
|
29 |
+
demo.launch()
|