# Import necessary libraries from transformers import pipeline import gradio as gr # Load the Filipino sentiment analysis model pipe = pipeline("text-classification", model="raphgonda/FilipinoShopping") # Define the sentiment analysis function def analyze_sentiment(text): try: # Predict sentiment using the model results = pipe(text) # Extract label and score label = results[0]["label"] score = round(results[0]["score"] * 100, 2) # Convert score to percentage return label, f"{score}%" except Exception as e: return "Error", "N/A" # Create a Gradio interface with custom UI with gr.Blocks() as interface: gr.Markdown("

Filipino Sentiment Analysis

") gr.Markdown("

Enter text in Filipino to analyze its sentiment.

") 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, ) # Define the function connection submit_btn.click( analyze_sentiment, inputs=[input_text], outputs=[sentiment_label, emotion_score], ) clear_btn.click( lambda: ("", ""), inputs=[], outputs=[sentiment_label, emotion_score], ) # Launch the app interface.launch()