Spaces:
Runtime error
Runtime error
feat: add app.py and requirement files
Browse files- app.py +52 -0
- requirements.txt +6 -0
app.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
from functools import partial
|
| 3 |
+
from typing import Callable, Dict
|
| 4 |
+
import transformers
|
| 5 |
+
from transformers import (
|
| 6 |
+
AutoModelForSequenceClassification,
|
| 7 |
+
AutoTokenizer,
|
| 8 |
+
pipeline
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
import pythainlp
|
| 13 |
+
from pprint import pprint
|
| 14 |
+
from itertools import chain
|
| 15 |
+
|
| 16 |
+
import gradio as gr
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
tokenizer=AutoTokenizer.from_pretrained(
|
| 20 |
+
'airesearch/wangchanberta-base-att-spm-uncased',
|
| 21 |
+
revision='finetuned@wisesight-sentiment'
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
#pipeline
|
| 25 |
+
text_cls_pipeline = pipeline(task='sentiment-analysis',
|
| 26 |
+
tokenizer=tokenizer,
|
| 27 |
+
model = 'airesearch/wangchanberta-base-att-spm-uncased',
|
| 28 |
+
revision ='finetuned@wisesight-sentiment')
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def classify_text(text: str):
|
| 32 |
+
results = text_cls_pipeline(text)
|
| 33 |
+
print(f'results:\n {results}')
|
| 34 |
+
html_text = results
|
| 35 |
+
|
| 36 |
+
return json.dumps(results, ensure_ascii=False, indent=4), html_text
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
demo = gr.Interface(fn=ner_tagging,
|
| 40 |
+
inputs=gr.Textbox(lines=5, placeholder='Input text in Thai', label='Input text'),
|
| 41 |
+
examples=[
|
| 42 |
+
'งานจากผกกคนนี้ไม่เคยทำให้เราผิดหวัง ให้ต้องไปดูอีกรอบสอง',
|
| 43 |
+
'ฟอร์ด บุกตลาด อีวี ในอินเดีย #prachachat #ตลาดรถยนต์',
|
| 44 |
+
'สั่งไป2 เมนู คือมัชฉะลาเต้ร้อน กับ ไอศครีมชาเขียว มัชฉะลาเต้ร้อน รสชาเขียวเข้มข้น หอม มัน แต่ไม่กลมกล่อม มันจืดแบบจืดสนิท ส่วนไอศครีมชาเขียว ทานแล้วรสมันออกใบไม้ๆมากกว่าชาเขียว แล้วก็หวานไป โดยรวมแล้วเฉยมากก ดีแค่รสชาเขียวเข้ม มีน้ำเปล่าบริการฟรี',
|
| 45 |
+
'ไม่ได้เรื่องเลย การบริการให้ 5 เต็ม ร้อย'
|
| 46 |
+
],
|
| 47 |
+
|
| 48 |
+
outputs=[gr.Textbox(), gr.HTML()])
|
| 49 |
+
|
| 50 |
+
print(f'\nINFO: transformers.__version__: {transformers.__version__}')
|
| 51 |
+
print(f'\nINFO: pythainlp.__version__: {pythainlp.__version__}')
|
| 52 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch==1.5.0
|
| 2 |
+
torchtext==0.4.0
|
| 3 |
+
torchvision==0.6.0
|
| 4 |
+
gradio
|
| 5 |
+
git+https://github.com/vistec-ai/thai2transformers.git@dev
|
| 6 |
+
pythainlp==2.2.4
|