import gradio as gr from transformers import pipeline custom_pipe = pipeline("text2text-generation", model="arifagustyawan/flan-t5-base-sentiment-product-review") def genrate_sentiment(text, max_new_tokens, num_beams): return custom_pipe(text, max_new_tokens=max_new_tokens, num_beams=int(num_beams)) with gr.Blocks() as demo: gr.Markdown( """ # Product Review - Sentiment Analysis Generate sentiment analysis and its reason based on product reviews using FLAN-T5 base model. ----- """) with gr.Row(): with gr.Accordion("Parameters!", open = False): max_new_tokens = gr.Number(value=50, minimum=1, maximum=500, step=1, label="Max New Tokens") num_beams = gr.Number(value=2, minimum=1, maximum=10, step=1, label="Num Beams") with gr.Row(): text = gr.Textbox(lines=5, label="Product Review", value="Give sentiment and its reason: Kualitas produknya sangat rendah. Saya tidak merekomendasikan untuk pembelian.") output = gr.Textbox(lines=5, label="Sentiment Analysis") with gr.Row(): btn = gr.Button(value="Process") btn.click(genrate_sentiment, inputs=[text, max_new_tokens, num_beams], outputs=[output]) if __name__ == "__main__": demo.launch()