polyguard-space / app.py
MUHAMMADSAADAMIN's picture
Initial commit of PolyGuard Space
3841e33 verified
raw
history blame contribute delete
927 Bytes
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)