Spaces:
Sleeping
Sleeping
File size: 1,066 Bytes
6ae0021 98e860f 7b7d314 6ae0021 98e860f 6ae0021 98e860f 7b7d314 98e860f 852af05 6ae0021 98e860f |
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 |
import streamlit as st
from keybert import KeyBERT
import spacy
import jieba
# 加載中文 spaCy 模型
zh_model = spacy.load("zh_core_web_sm")
bertModel = KeyBERT(model=zh_model)
# Streamlit 介面
st.title("KeyBERT 關鍵字抓取應用")
# 輸入框讓用戶輸入文字
text = st.text_area("請貼上文字並按下按鈕以抓取關鍵字", height=200)
# 按鈕來觸發關鍵字抓取
if st.button("抓取關鍵字"):
if text:
# 使用 jieba 對輸入的中文文本進行分詞
doc = ' '.join(jieba.lcut(text))
# 使用 KeyBERT 抓取關鍵字
keywords = bertModel.extract_keywords(doc,
keyphrase_ngram_range=(1, 1),
stop_words=None,
top_n=10)
st.write("抓取到的關鍵字及相關性分數:")
for keyword, relevance in keywords:
st.write(f"關鍵字: {keyword}, 相關性分數: {relevance:.4f}")
else:
st.write("請先輸入文字")
|