raphgonda's picture
Update app.py
6527255 verified
raw
history blame
996 Bytes
from transformers import AutoTokenizer, TFAutoModelForSequenceClassification, pipeline
import gradio as gr
# Load tokenizer and model explicitly
tokenizer = AutoTokenizer.from_pretrained("raphgonda/FilipinoShopping")
model = TFAutoModelForSequenceClassification.from_pretrained("raphgonda/FilipinoShopping")
# Create a pipeline
pipe = pipeline("text-classification", model=model, tokenizer=tokenizer, framework="tf")
# Define the sentiment analysis function
def analyze_sentiment(text):
try:
result = pipe(text)
label = result[0]["label"]
score = round(result[0]["score"] * 100, 2) # Convert score to percentage
return label, f"{score}%"
except Exception as e:
return "Error", str(e)
# Gradio app
interface = gr.Interface(
fn=analyze_sentiment,
inputs=gr.Textbox(label="Enter Filipino Text"),
outputs=[gr.Textbox(label="Sentiment"), gr.Textbox(label="Emotion Score")],
title="Filipino Sentiment Analysis"
)
interface.launch()