Workshop / app.py
0llheaven's picture
Update app.py
94f15b2 verified
raw
history blame contribute delete
950 Bytes
import streamlit as st
from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
# เอา model Sentiment Analysis ที่ทำการ Fine-Tuning มาแล้ว
model_demo = "CKBot3/Workshop1_Demo"
tokenizer = AutoTokenizer.from_pretrained(model_demo)
model = AutoModelForSequenceClassification.from_pretrained(model_demo, num_labels=2)
# สร้างโมเดลสำหรับ Sentiment Analysis
sentiment_analyzer = pipeline('sentiment-analysis', model=model, tokenizer=tokenizer)
# ทำการเปลี่ยนชื่อ label เพื่อความเข้าใจง่าย
label_map = {"LABEL_0": "NEGATIVE", "LABEL_1": "POSITIVE"}
st.title('Sentiment Analysis App')
text = st.text_area('Enter text to analyze:')
if st.button('Analyze'):
result = sentiment_analyzer(text)
for res in result:
res['label'] = label_map[res['label']]
st.write(result)