|
from transformers import AutoTokenizer, TFAutoModelForSequenceClassification, pipeline |
|
import gradio as gr |
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained("raphgonda/FilipinoShopping") |
|
model = TFAutoModelForSequenceClassification.from_pretrained("raphgonda/FilipinoShopping") |
|
|
|
|
|
pipe = pipeline("text-classification", model=model, tokenizer=tokenizer, framework="tf") |
|
|
|
|
|
def analyze_sentiment(text): |
|
try: |
|
result = pipe(text) |
|
label = result[0]["label"] |
|
score = round(result[0]["score"] * 100, 2) |
|
return label, f"{score}%" |
|
except Exception as e: |
|
return "Error", str(e) |
|
|
|
|
|
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() |
|
|