prodigy-ecfr-textcat / gradio_interface.py
ManjinderUNCC's picture
Update gradio_interface.py
6589640 verified
raw
history blame
668 Bytes
# Import necessary libraries
import gradio as gr
import spacy
# Load the trained spaCy model
model_path = "./my_trained_model"
nlp = spacy.load(model_path)
# Function to classify text
def classify_text(text):
doc = nlp(text)
predicted_labels = doc.cats
return predicted_labels
# Gradio Interface
inputs = gr.inputs.Textbox(lines=7, label="Enter your text")
def classify_and_save(input_text):
predicted_labels = classify_text(input_text)
return predicted_labels
output = gr.outputs.JSON(label="Classification Results")
iface = gr.Interface(fn=classify_and_save, inputs=inputs, outputs=output, title="Text Classifier")
iface.launch(share=True)