from transformers import pipeline import gradio as gr # Load your custom FLAN-T5 sentiment analysis pipeline custom_pipe = pipeline("text-generation", model="arifagustyawan/flan-t5-base-sentiment-product-review") # Define the header and subheader header = "Sentiment Analysis" subheader = "Generate sentiment analysis and its reason based on product reviews using your FLAN-T5 base model." # Default text prompt default_text_prompt = "Produk ini sangat bagus. Saya sangat puas dengan kualitasnya." # Example texts in Bahasa Indonesia example_texts = [ "Give sentiment and its reason: Saya kecewa dengan layanan pelanggan mereka. Tidak responsif dan tidak membantu.", "Give sentiment and its reason: Pengalaman belanja online kali ini luar biasa. Barang sampai tepat waktu dan sesuai ekspektasi.", "Give sentiment and its reason: Kualitas produknya sangat rendah. Saya tidak merekomendasikan untuk pembelian.", ] # Create Gradio interface with input parameters iface = gr.Interface( fn=custom_pipe, inputs=[ gr.Textbox(prompt="Give sentiment and its reason: ", default=default_text_prompt, lines=5), gr.Number("Max New Tokens", default=50, min=1, max=500, step=1), gr.Number("Num Beams", default=1, min=1, max=10, step=1), gr.Checkbox("Gunakan Temperature", default=False), gr.Number("Temperature", default=1.0, min=0.1, max=5.0, step=0.1), ], outputs=gr.Textbox(), live=True, title=header, description=subheader ) # Set example texts for users to try iface.set_examples([ [example_texts[0]], [example_texts[1]], [example_texts[2]], ]) # Launch the Gradio interface iface.launch()