pahri commited on
Commit
2517c42
1 Parent(s): 91b406f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from setfit import AbsaModel
3
+
4
+ # Load the ABSA model (assuming indo-setfit-absa-bert-base-restaurants is the aspect extraction model)
5
+ model = AbsaModel.from_pretrained(
6
+ "firqaaa/indo-setfit-absa-bert-base-restaurants-aspect",
7
+ "firqaaa/indo-setfit-absa-bert-base-restaurants-polarity",
8
+ spacy_model="id_core_news_trf",
9
+ )
10
+
11
+ def analyze_text(text):
12
+ """
13
+ Analyzes the input text using the ABSA model and returns aspects and sentiment.
14
+
15
+ Args:
16
+ text: The text to be analyzed.
17
+
18
+ Returns:
19
+ A dictionary containing aspects and sentiment.
20
+ """
21
+ aspects, sentiments = model.predict(text)
22
+ return {"Aspek": aspects, "Sentimen": sentiments}
23
+
24
+ description = "Analisa Aspek dan Sentimen Review Restoran"
25
+ title = "Analisa Review Restoran Anda"
26
+ examples = [["Makanannya enak, tapi pelayanannya lambat."]]
27
+
28
+ interface = gr.Interface(
29
+ fn=analyze_text,
30
+ inputs="textbox",
31
+ outputs="dict",
32
+ interpretation="text",
33
+ description=description,
34
+ title=title,
35
+ examples=examples
36
+ )
37
+
38
+ interface.launch()