File size: 2,334 Bytes
6dc656a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import json
from functools import partial
from typing import Callable, Dict
import transformers
from transformers import (
    AutoModelForSequenceClassification,
    AutoTokenizer,
    pipeline
)


import pythainlp
from pprint import pprint
from itertools import chain

import gradio as gr


tokenizer=AutoTokenizer.from_pretrained(
    'airesearch/wangchanberta-base-att-spm-uncased',
    revision='finetuned@wisesight-sentiment'
)

#pipeline
text_cls_pipeline = pipeline(task='sentiment-analysis',
         tokenizer=tokenizer,
         model =  'airesearch/wangchanberta-base-att-spm-uncased',
         revision ='finetuned@wisesight-sentiment')
         

def classify_text(text: str):
    results = text_cls_pipeline(text)
    print(f'results:\n {results}')
    html_text = results

    return json.dumps(results, ensure_ascii=False, indent=4), html_text


demo = gr.Interface(fn=ner_tagging,
inputs=gr.Textbox(lines=5, placeholder='Input text in Thai', label='Input text'),
examples=[
        'งานจากผกกคนนี้ไม่เคยทำให้เราผิดหวัง ให้ต้องไปดูอีกรอบสอง',
        'ฟอร์ด บุกตลาด อีวี ในอินเดีย #prachachat #ตลาดรถยนต์',
        'สั่งไป2 เมนู คือมัชฉะลาเต้ร้อน กับ ไอศครีมชาเขียว มัชฉะลาเต้ร้อน รสชาเขียวเข้มข้น หอม มัน แต่ไม่กลมกล่อม มันจืดแบบจืดสนิท ส่วนไอศครีมชาเขียว ทานแล้วรสมันออกใบไม้ๆมากกว่าชาเขียว แล้วก็หวานไป โดยรวมแล้วเฉยมากก ดีแค่รสชาเขียวเข้ม มีน้ำเปล่าบริการฟรี',
        'ไม่ได้เรื่องเลย การบริการให้ 5 เต็ม ร้อย'
    ],

outputs=[gr.Textbox(), gr.HTML()])

print(f'\nINFO: transformers.__version__: {transformers.__version__}')
print(f'\nINFO: pythainlp.__version__: {pythainlp.__version__}')
demo.launch()