lalital's picture
feat: add app.py and requirement files
6dc656a
raw
history blame
2.33 kB
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()