MooMooChecker / app.py
dryade36513's picture
Upload app.py
bce1ab4 verified
# app.py
import streamlit as st
import jieba
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity
import difflib
import numpy as np
import time
# 設置網頁標題等信息
st.set_page_config(
page_title="哞哞文章相似度檢測",
page_icon="🐮",
layout="wide",
initial_sidebar_state="collapsed"
)
# 自定義CSS樣式
st.markdown("""
<style>
.stTextArea textarea {
font-size: 16px !important;
}
.big-font {
font-size: 24px !important;
font-weight: bold !important;
color: #FF4B4B !important;
}
.result-font {
font-size: 20px !important;
color: #1E88E5 !important;
}
@keyframes rainbow {
0% { border-color: red; box-shadow: 0 0 15px red; }
14% { border-color: orange; box-shadow: 0 0 15px orange; }
28% { border-color: yellow; box-shadow: 0 0 15px yellow; }
42% { border-color: green; box-shadow: 0 0 15px green; }
56% { border-color: blue; box-shadow: 0 0 15px blue; }
70% { border-color: indigo; box-shadow: 0 0 15px indigo; }
84% { border-color: violet; box-shadow: 0 0 15px violet; }
100% { border-color: red; box-shadow: 0 0 15px red; }
}
.rainbow-box {
border: 3px solid red;
border-radius: 15px;
padding: 25px;
margin: 20px 0;
animation: rainbow 5s linear infinite;
background: rgba(0, 0, 0, 0); /* 完全透明背景 */
}
.lawsuit-info {
font-family: "Microsoft JhengHei", sans-serif;
line-height: 1.6;
white-space: pre-line;
text-shadow: 0 0 5px rgba(255, 255, 255, 0.8); /* 添加文字陰影讓文字更清晰 */
}
.lawsuit-title {
font-weight: bold;
font-size: 1.5em;
color: #FF4B4B;
margin-bottom: 15px;
text-shadow: 0 0 10px rgba(255, 75, 75, 0.5); /* 紅色標題特效 */
}
.cost-section {
margin: 15px 0;
}
.cost-title {
font-weight: bold;
color: #1E88E5;
text-shadow: 0 0 8px rgba(30, 136, 229, 0.5); /* 藍色標題特效 */
}
.highlight {
color: #FF4B4B;
font-weight: bold;
text-shadow: 0 0 8px rgba(255, 75, 75, 0.5); /* 高亮文字特效 */
}
/* 加強霓虹效果 */
.rainbow-box:hover {
transform: scale(1.01);
transition: transform 0.3s ease;
}
</style>
""", unsafe_allow_html=True)
# 顯示標題
st.markdown("<h1 style='text-align: center; color: #FF4B4B;'>🐮 哞哞文章相似度檢測</h1>", unsafe_allow_html=True)
# 創建兩列佈局
col1, col2 = st.columns(2)
with col1:
st.markdown("### 📝 文章1")
text1 = st.text_area("", height=300, placeholder="請在這裡輸入第一篇文章...", key="text1")
with col2:
st.markdown("### 📝 文章2")
text2 = st.text_area("", height=300, placeholder="請在這裡輸入第二篇文章...", key="text2")
# 創建按鈕列
col_btn1, col_btn2, col_btn3 = st.columns([1,1,1])
with col_btn2:
start_btn = st.button("🚀 開始計算相似度", type="primary", use_container_width=True)
def calculate_similarity(text1, text2):
"""計算文本相似度"""
if not text1.strip() or not text2.strip():
return None, None
# 1. 計算字詞重合度
words1 = list(jieba.cut(text1))
words2 = list(jieba.cut(text2))
word_set1 = set(words1)
word_set2 = set(words2)
word_similarity = len(word_set1.intersection(word_set2)) / len(word_set1.union(word_set2))
# 2. 計算句子相似度
sentences1 = text1.split("。")
sentences2 = text2.split("。")
sentence_matcher = difflib.SequenceMatcher(None, sentences1, sentences2)
sentence_similarity = sentence_matcher.ratio()
# 3. 計算TF-IDF相似度
vectorizer = TfidfVectorizer()
try:
tfidf_matrix = vectorizer.fit_transform([text1, text2])
cosine_sim = cosine_similarity(tfidf_matrix[0:1], tfidf_matrix[1:2])[0][0]
except:
cosine_sim = 0
# 計算總相似度
weights = [0.4, 0.3, 0.3]
total_similarity = (word_similarity * weights[0] +
sentence_similarity * weights[1] +
cosine_sim * weights[2]) * 100
similarity_score = round(total_similarity, 2)
# 判定結果
if similarity_score <= 30:
result = "兩篇文章沒有關係"
elif similarity_score <= 60:
result = "兩篇文章似乎有那麼一點關係"
elif similarity_score <= 80:
result = "兩篇文章很類似"
else:
result = "兩篇文章有抄襲犯罪的味道"
return similarity_score, result
if start_btn and text1 and text2:
with st.spinner('🔍 分析中,請稍等...'):
# 顯示進度條
progress_text = "計算中..."
my_bar = st.progress(0, text=progress_text)
for percent_complete in range(100):
time.sleep(0.01)
my_bar.progress(percent_complete + 1, text=progress_text)
# 計算相似度
similarity_score, result = calculate_similarity(text1, text2)
if similarity_score is not None:
# 清除進度條
my_bar.empty()
# 顯示結果
st.markdown("---")
st.markdown("<h3 style='text-align: center;'>✨ 分析結果</h3>", unsafe_allow_html=True)
result_text = f"""
<div style='text-align: center;'>
<p class='big-font'>相似度:{similarity_score}%</p>
<p class='result-font'>分析結果:{result}</p>
</div>
"""
st.markdown(result_text, unsafe_allow_html=True)
# 顯示可愛的表情符號
if similarity_score <= 30:
st.markdown("<h1 style='text-align: center;'>😌</h1>", unsafe_allow_html=True)
elif similarity_score <= 60:
st.markdown("<h1 style='text-align: center;'>🤔</h1>", unsafe_allow_html=True)
elif similarity_score <= 80:
st.markdown("<h1 style='text-align: center;'>😮</h1>", unsafe_allow_html=True)
else:
st.markdown("<h1 style='text-align: center;'>😱</h1>", unsafe_allow_html=True)
else:
st.info('👆 請在上方輸入兩篇要比較的文章,然後點擊"開始計算相似度"按鈕')
# 訴訟資訊文本
lawsuit_info = """
<div class="rainbow-box">
<div class="lawsuit-info">
<div class="lawsuit-title">馬的~這個小王八蛋抄襲我的文章! 一鍵網路告發直通車</div>
·智慧財產局網站:https://www.tipo.gov.tw/
<div class="cost-section">
<span class="cost-title">(備註)♡此次提告訴訟預估花費的公帑估算♡</span>
1. 人員成本(每月)
• 法官薪資:約新台幣 80,000-100,000元
• 書記官薪資:約新台幣 45,000-60,000元
• 其他行政人員:約新台幣 40,000元
2. 訴訟時程與開庭資訊
• 智慧財產法院民事第一審平均結案日數:約240天
• 平均開庭次數:約3-4次
• 每次開庭約需2小時
3. 成本估算(以一個案件計)
直接人事成本:
1. 法官成本:
• 每月薪資÷20工作天÷8小時 × 2小時 × 4次開庭
• = (90,000÷160) × 2 × 4 = 約4,500元
2. 書記官成本:
• 每月薪資÷20工作天÷8小時 × 2小時 × 4次開庭
• = (50,000÷160) × 2 × 4 = 約2,500元
3. 行政人員處理成本:
• 約5,000元(含文書處理、歸檔等)
間接成本:
1. 場地使用成本(含水電):約3,000元
2. 文書處理成本:約2,000元
3. 行政作業成本:約3,000元
<span class="highlight">總計:
一個著作權侵權民事訴訟案件,預估會花費納稅人約新台幣20,000元。</span>
其他考量:
1. 若案件進入第二審,成本將增加約50-80%
2. 如果需要專業鑑定,費用會更高
3. 若有調解程序,可能會縮短訴訟時間,降低成本
<span class="highlight">建議:
你想靠這小賺一點錢的話,不如去新北市樹林區上午的菜市場給無照駕駛的老阿公或老阿罵撞還會理賠更多,有機會中大獎如民國104彭姓少年下樓買珍珠奶茶被阿罵無照駕駛機車撞住院住了半年案,可以獲得的理賠金更多。</span>
</div>
</div>
</div>
"""
# 在info提示後顯示訴訟資訊
st.markdown(lawsuit_info, unsafe_allow_html=True)
# 在底部添加說明
st.markdown("---")
st.markdown("""
<div style='text-align: center;'>
<p style='color: gray; font-size: 14px;'>
💡 判定標準:<br>
0-30%:文章沒有關係 | 31-60%:稍有關係 | 61-80%:很類似 | 81-100%:疑似抄襲
</p>
</div>
""", unsafe_allow_html=True)