Commit ·
c3cf996
1
Parent(s): 8d84048
Hook clara to UI
Browse files
app.py
CHANGED
|
@@ -1,7 +1,33 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load a text classification model
|
| 5 |
+
# Replace with your model's path or Hugging Face model name
|
| 6 |
+
model = pipeline(task="text-classification", model="adrienhongcs/clara-0")
|
| 7 |
|
| 8 |
+
def predict(input_text):
|
| 9 |
+
# Get predictions from the model
|
| 10 |
+
predictions = model(input_text)
|
| 11 |
+
|
| 12 |
+
# Extract the label and score
|
| 13 |
+
label = predictions[0]["label"]
|
| 14 |
+
score = predictions[0]["score"]
|
| 15 |
+
|
| 16 |
+
# Return the label and score
|
| 17 |
+
return label, score
|
| 18 |
+
|
| 19 |
+
# Create the Gradio interface
|
| 20 |
+
gradio_app = gr.Interface(
|
| 21 |
+
fn=predict, # Function to call
|
| 22 |
+
inputs=gr.Textbox(label="Enter a deduction backup doc text"), # Text input
|
| 23 |
+
outputs=[
|
| 24 |
+
gr.Textbox(label="Predicted Reason"), # Output for the label
|
| 25 |
+
gr.Number(label="Confidence Score") # Output for the score
|
| 26 |
+
],
|
| 27 |
+
title="Clara the reason classifier",
|
| 28 |
+
description="Enter a deduction backup (as text) to classify it and get the predicted label and confidence score."
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
# Launch the app
|
| 32 |
+
if __name__ == "__main__":
|
| 33 |
+
gradio_app.launch()
|