Spaces:
Build error
Build error
File size: 927 Bytes
3841e33 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
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)
|