arifagustyawan
commited on
Commit
•
ba62668
1
Parent(s):
f5f155f
add application file
Browse files
app.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
# Define the header and subheader
|
8 |
+
header = "Sentiment Analysis"
|
9 |
+
subheader = "Generate sentiment analysis and its reason based on product reviews using your FLAN-T5 base model."
|
10 |
+
|
11 |
+
# Default text prompt
|
12 |
+
default_text_prompt = "Produk ini sangat bagus. Saya sangat puas dengan kualitasnya."
|
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=custom_pipe,
|
24 |
+
inputs=[
|
25 |
+
gr.Textbox(prompt="Give sentiment and its reason: ", default=default_text_prompt, lines=5),
|
26 |
+
gr.Number("Max New Tokens", default=50, min=1, max=500, step=1),
|
27 |
+
gr.Number("Num Beams", default=1, min=1, max=10, step=1),
|
28 |
+
gr.Checkbox("Gunakan Temperature", default=False),
|
29 |
+
gr.Number("Temperature", default=1.0, min=0.1, max=5.0, step=0.1),
|
30 |
+
],
|
31 |
+
outputs=gr.Textbox(),
|
32 |
+
live=True,
|
33 |
+
title=header,
|
34 |
+
description=subheader
|
35 |
+
)
|
36 |
+
|
37 |
+
# Set example texts for users to try
|
38 |
+
iface.set_examples([
|
39 |
+
[example_texts[0]],
|
40 |
+
[example_texts[1]],
|
41 |
+
[example_texts[2]],
|
42 |
+
])
|
43 |
+
|
44 |
+
# Launch the Gradio interface
|
45 |
+
iface.launch()
|