arifagustyawan
commited on
Commit
•
e20d46c
1
Parent(s):
815fef3
add process button
Browse files
app.py
CHANGED
@@ -1,49 +1,27 @@
|
|
1 |
-
from transformers import pipeline
|
2 |
import gradio as gr
|
|
|
3 |
|
4 |
-
# Load your custom FLAN-T5 sentiment analysis pipeline
|
5 |
custom_pipe = pipeline("text-generation", model="arifagustyawan/flan-t5-base-sentiment-product-review")
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
# Example texts in Bahasa Indonesia
|
15 |
-
example_texts = [
|
16 |
-
"Give sentiment and its reason: Saya kecewa dengan layanan pelanggan mereka. Tidak responsif dan tidak membantu.",
|
17 |
-
"Give sentiment and its reason: Pengalaman belanja online kali ini luar biasa. Barang sampai tepat waktu dan sesuai ekspektasi.",
|
18 |
-
"Give sentiment and its reason: Kualitas produknya sangat rendah. Saya tidak merekomendasikan untuk pembelian.",
|
19 |
-
]
|
20 |
-
|
21 |
-
# Create Gradio interface with input parameters
|
22 |
-
iface = gr.Interface(
|
23 |
-
fn=lambda text, max_new_tokens, num_beams, use_temperature, temperature:
|
24 |
-
custom_pipe(text, max_length=int(max_new_tokens) if max_new_tokens else 100, num_beams=int(num_beams) if num_beams else 2,
|
25 |
-
temperature=float(temperature) if use_temperature else 1.0),
|
26 |
-
inputs=[
|
27 |
-
gr.Textbox(lines=5),
|
28 |
-
gr.Number(value=50, minimum=1, maximum=500, step=1, label="Max New Tokens"),
|
29 |
-
gr.Number(value=1, minimum=2, maximum=10, step=1, label="Num Beams"),
|
30 |
-
gr.Checkbox(value=False, label="Gunakan Temperature"),
|
31 |
-
gr.Number(value=1.0, minimum=0.1, maximum=5.0, step=0.1, label="Temperature"),
|
32 |
-
gr.Button("Proses", click=lambda: None),
|
33 |
-
],
|
34 |
-
outputs=gr.Textbox(),
|
35 |
-
live=True,
|
36 |
-
title=header,
|
37 |
-
description=subheader,
|
38 |
-
examples=[[text] for text in example_texts]
|
39 |
-
)
|
40 |
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
-
|
49 |
-
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
|
|
|
4 |
custom_pipe = pipeline("text-generation", model="arifagustyawan/flan-t5-base-sentiment-product-review")
|
5 |
|
6 |
+
with gr.Blocks() as demo:
|
7 |
+
gr.Markdown(
|
8 |
+
"""
|
9 |
+
# Product Review - Sentiment Analysis
|
10 |
+
Generate sentiment analysis and its reason based on product reviews using FLAN-T5 base model.
|
11 |
+
-----
|
12 |
+
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
+
with gr.Row():
|
15 |
+
with gr.Accordion("Parameters!", open = False):
|
16 |
+
max_new_tokens = gr.Number(value=50, minimum=1, maximum=500, step=1, label="Max New Tokens")
|
17 |
+
num_beams = gr.Number(value=2, minimum=1, maximum=10, step=1, label="Num Beams")
|
18 |
+
|
19 |
+
with gr.Row():
|
20 |
+
text = gr.Textbox(lines=5, label="Product Review", value="Give sentiment and its reason: Kualitas produknya sangat rendah. Saya tidak merekomendasikan untuk pembelian.")
|
21 |
+
output = gr.Textbox(lines=5, label="Sentiment Analysis")
|
22 |
+
with gr.Row():
|
23 |
+
btn = gr.Button(value="Process")
|
24 |
+
btn.click(custom_pipe, inputs=[text, max_new_tokens, num_beams], outputs=[output])
|
25 |
|
26 |
+
if __name__ == "__main__":
|
27 |
+
demo.launch()
|