import matplotlib.pyplot as plt import streamlit as st from pages.Model import Load_Model import warnings import tokenizers warnings.filterwarnings("ignore") st.set_page_config( page_title="PTT 版面應用 App", page_icon="🧊", layout="wide", initial_sidebar_state="expanded", menu_items={ 'About': """組員名單:張云姵、林維婕、陳玉涵、蔡尚宏""", } ) sample_text = [ 'Select', '神谷浩史,2014年人氣聲優以來一直就穩坐第1位,六連霸的神谷浩史,那個男人的魅力 是什麼。 配過的角色有阿松裡吐槽擔當輕松,語速快到不像話被神谷說又要進去那累死人的配音室 的齊木楠雄、夏目友人帳的暖男夏目、航海王的羅、還是最近小妹我啦,很愛的進擊巨人 身高一米六最強人類里維兵長(心)人氣高過主角 新番隱瞞之事的爸爸聲線也超棒 神谷的聲音算辨識度很高,他只有在配兵長聲線時讓我滿驚豔的、卡米亞配音時的聲音要 比平時更加低沉,好像比較少出演這種高冷深沉的角色? 大家覺得神谷最經典的代表作是什麼呢 話說神谷有出演過那種校園愛情番的男主嗎 (滿想看的XD)? 兵長我老公 話說我查了一下大家推的阿良良木 這段是....(問號wwww https://youtu.be/GTmjk9pUwrM', ' 以下重點: 《Soul of Eden》開啟 Google Play 預註冊 《DEEMO II》概念前導片及 Google Play 預註冊 《Cytus II》將與《maimai DX》合作 《MO:Astray》將推出 Switch 主機版 《Implosion》將更新至 Android 10 適配版並新增角色日文配音 新品牌Rayark Infuse並合作推出新遊戲《Chaos Academy 渾沌學院》 樓下開放噓鳳毛麟角過氣公司 C1的劇情我覺得比較像是設定而已,直接忽略也不會對體驗有多少影響 C2的劇情就真的看不懂了orz 是說音樂遊戲哪需要什麼劇情(X', '[討論] 合法掩護非法!國家隊工廠偷賣百萬口罩 合法掩護非法國家隊工廠偷賣百萬片口罩遭抓包,不法所得破千萬 國家都徵收了. 怎麼工廠還有產能? 防疫中心跟政府沒在稽查? 還是只看工廠送上來的產能報告? 今年2月至今,該口罩的售價從每盒50片350元,陸續漲價至每盒50片650元,換算下來每 片口罩價格高達13元。另外調查局也指出,該公司私下生產的違法醫用活性碳口罩總計 110萬餘片,不法所得估計逾千萬元。 晙d局已於4月24日依法搜索該公司及負責人之住處等3處所,當場查獲非法活性碳口罩1 萬6550片,同時也約談該公司負責人劉某到案說明。 所以多賣了二個月才被發現? 防疫中心跟調查局被耍了二個月才發現? 那全國的所有口罩國家隊有沒有偷賣的口罩? 我認為要清查 1. 買了多少原料? 做了多少? 還剩多少? 2. 有沒有偷偷出口? 清查所有海關資料? 3. 防疫中心以及政府多久去查一次產能? 還是都不查? 看廠商良心? 看起來還是有人沒良心的. ', '把1星英雄練到10等 犧牲另一隻1星 變成2星 把20變成20等 犧牲兩隻2星 變成三星 好好玩 救命... 驟雨初歇村似畫 濛濛夕霧滿秋山 ', '[問卦] 八卦對哪個族群偏見最多? 是這樣啦 我們對不同人都會有刻板印象 像是醫生薪水很高這種的 但滿多是負面的 新北都鬼父 動漫宅宅很臭 之類的 那 大家覺得誰的負面刻板印象最多? 有木有八卦? ' ] @st.cache_resource def load_all_model(): classify_model = Load_Model.Bert_Classify_Model() classify_model.load_model() senti_model = Load_Model.Sentiment_Model() senti_model.load_model() summarize_model = Load_Model.Summarization_Model() summarize_model.load_model() wordcloud_model = Load_Model.WordCloudDrawer() return classify_model, senti_model, summarize_model, wordcloud_model def text_area_widget(): input_content = st.selectbox( "使用範例文章", sample_text, index=0 ) if input_content == "Select": input_content = st.text_area( label="請輸入文章...", max_chars=1024 ) else: input_content = st.text_area( label="請輸入文章...", value=input_content, max_chars=1024 ) return input_content def draw_wordcloud(wordcloud_model, input_content): st.subheader("文字雲") wc = wordcloud_model.word_cloud(input_content, num_words=15) st.image( wc.to_array(), width=500, caption="文字雲" ) st.divider() def make_result_button(classify_model, senti_model, summarize_model, wordcloud_model, input_content): if st.button("產出成果"): if input_content == "": st.error('請先輸入您想分析的文章或直接選擇範例文章!', icon="🚨") else: with st.spinner('Wait for it...'): run_analysis(classify_model, senti_model, summarize_model, wordcloud_model, input_content) st.balloons() def run_analysis(classify, senti, summarize, wordcloud_model, input_sentence): draw_wordcloud(wordcloud_model, input_sentence) tab_summarize, tab_classify, tab_sentiment = st.tabs(["文章摘要", "版面預測成果", "情緒分析"]) with tab_summarize: st.subheader("文章摘要") st.caption('以下為您的文章摘要。') st.write(summarize.run_summarize(input_sentence)) with tab_classify: st.subheader("版面預測成果") st.caption('以下為版面預測的機率。') classify_result = classify.predict(input_sentence).round(4) st.write(f"您的文章最有可能是 {classify_result.iloc[0, 0]},可能性為 {classify_result['機率'].max()*100:2f} %") with st.expander("查看所有版面預測機率"): st.dataframe( data=classify_result, use_container_width=True ) with tab_sentiment: st.subheader("情緒分析成果") st.caption('以下為您的文章情緒') senti_result = senti.run_sentiment(input_sentence)[0] st.write(f"您的文章情緒為 {senti_result['label']},分數為 {senti_result['score']}") def main(): # first init model classify_model, senti_model, summarize_model, wordcloud_model = load_all_model() # page design head_section = st.container() ana_section = st.container() output_section = st.container() with head_section: st.title("Dashboard") st.divider() with ana_section: input_content = text_area_widget() st.divider() with output_section: make_result_button(classify_model, senti_model, summarize_model, wordcloud_model, input_content) if __name__ == '__main__': main()