|
|
|
from transformers import pipeline |
|
import gradio as gr |
|
|
|
|
|
pipe = pipeline("text-classification", model="raphgonda/FilipinoShopping") |
|
|
|
|
|
def analyze_sentiment(text): |
|
try: |
|
|
|
results = pipe(text) |
|
|
|
label = results[0]["label"] |
|
score = round(results[0]["score"] * 100, 2) |
|
return label, f"{score}%" |
|
except Exception as e: |
|
return "Error", "N/A" |
|
|
|
|
|
with gr.Blocks() as interface: |
|
gr.Markdown("<h1 style='text-align: center;'>Filipino Sentiment Analysis</h1>") |
|
gr.Markdown("<p style='text-align: center;'>Enter text in Filipino to analyze its sentiment.</p>") |
|
|
|
with gr.Row(): |
|
input_text = gr.Textbox( |
|
label="Enter text to analyze its sentiment", |
|
placeholder="Type your text here...", |
|
) |
|
|
|
with gr.Row(): |
|
submit_btn = gr.Button("Submit") |
|
clear_btn = gr.Button("Clear") |
|
|
|
sentiment_label = gr.Textbox(label="Sentiment Label", interactive=False, visible=True) |
|
|
|
with gr.Row(): |
|
emotion_score = gr.Textbox(label="Emotion Score", interactive=False) |
|
|
|
examples = gr.Examples( |
|
examples=[ |
|
["Okay ang aesthetic"], |
|
["Mabagal ang delivery"], |
|
["Napakaganda ng serbisyo!"], |
|
["Ang pangit ng produkto."] |
|
], |
|
inputs=input_text, |
|
) |
|
|
|
|
|
submit_btn.click( |
|
analyze_sentiment, |
|
inputs=[input_text], |
|
outputs=[sentiment_label, emotion_score], |
|
) |
|
clear_btn.click( |
|
lambda: ("", ""), |
|
inputs=[], |
|
outputs=[sentiment_label, emotion_score], |
|
) |
|
|
|
|
|
interface.launch() |
|
|