Spaces:
Build error
Build error
| import gradio as gr | |
| from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification | |
| import os | |
| # Define the model path within the Space | |
| MODEL_PATH = "./model" | |
| # Load your model and tokenizer | |
| tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH) | |
| model = AutoModelForSequenceClassification.from_pretrained(MODEL_PATH) | |
| # Create a Hugging Face pipeline | |
| classifier = pipeline("text-classification", model=model, tokenizer=tokenizer) | |
| def predict_sentiment(text): | |
| result = classifier(text)[0] | |
| label = result['label'] | |
| score = result['score'] | |
| return f"Label: {label}, Score: {score:.4f}" | |
| # Create the Gradio interface | |
| iface = gr.Interface( | |
| fn=predict_sentiment, | |
| inputs=gr.Textbox(lines=5, placeholder="Enter text here..."), | |
| outputs="text", | |
| title="PolyGuard Model Demo", | |
| description="A simple Gradio interface to demonstrate the PolyGuard model." | |
| ) | |
| iface.launch(share=True) | |