File size: 1,261 Bytes
ba62668
e20d46c
ba62668
695677a
ba62668
6bb4810
3f8c6db
6bb4810
e20d46c
 
 
 
 
 
 
ba62668
e20d46c
 
 
 
 
 
 
 
 
 
6bb4810
ba62668
e20d46c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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()