Spaces:
Runtime error
Runtime error
Commit
·
ff62df8
1
Parent(s):
caed163
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import preprocessor as tweet_cleaner
|
3 |
+
import requests
|
4 |
+
from transformers import pipeline
|
5 |
+
|
6 |
+
pretrained_name = "w11wo/indonesian-roberta-base-sentiment-classifier"
|
7 |
+
|
8 |
+
sentiment = pipeline(
|
9 |
+
"sentiment-analysis",
|
10 |
+
model=pretrained_name,
|
11 |
+
tokenizer=pretrained_name,
|
12 |
+
max_length=512,
|
13 |
+
truncation=True,
|
14 |
+
)
|
15 |
+
|
16 |
+
def clean_tweet(tweet):
|
17 |
+
return tweet_cleaner.clean(tweet)
|
18 |
+
|
19 |
+
def get_sentiment(input_text):
|
20 |
+
return sentiment(clean_tweet(input_text))
|
21 |
+
|
22 |
+
iface = gr.Interface(fn = get_sentiment,
|
23 |
+
inputs = 'text',
|
24 |
+
outputs = ['text'],
|
25 |
+
title = 'Analisis Sentimen Twitter',
|
26 |
+
description="Dapatkan sentimen postiif, negatif, atau netral untuk tweet yang dimasukkan.")
|
27 |
+
|
28 |
+
iface.launch(inline = False)
|