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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# app.py
|
2 |
+
import streamlit as st
|
3 |
+
import jieba
|
4 |
+
from sklearn.feature_extraction.text import TfidfVectorizer
|
5 |
+
from sklearn.metrics.pairwise import cosine_similarity
|
6 |
+
import difflib
|
7 |
+
import numpy as np
|
8 |
+
import time
|
9 |
+
|
10 |
+
# 設置網頁標題等信息
|
11 |
+
st.set_page_config(
|
12 |
+
page_title="哞哞文章相似度檢測",
|
13 |
+
page_icon="🐮",
|
14 |
+
layout="wide",
|
15 |
+
initial_sidebar_state="collapsed"
|
16 |
+
)
|
17 |
+
|
18 |
+
# 自定義CSS樣式
|
19 |
+
st.markdown("""
|
20 |
+
<style>
|
21 |
+
.stTextArea textarea {
|
22 |
+
font-size: 16px !important;
|
23 |
+
}
|
24 |
+
.big-font {
|
25 |
+
font-size: 24px !important;
|
26 |
+
font-weight: bold !important;
|
27 |
+
color: #FF4B4B !important;
|
28 |
+
}
|
29 |
+
.result-font {
|
30 |
+
font-size: 20px !important;
|
31 |
+
color: #1E88E5 !important;
|
32 |
+
}
|
33 |
+
|
34 |
+
@keyframes rainbow {
|
35 |
+
0% { border-color: red; box-shadow: 0 0 15px red; }
|
36 |
+
14% { border-color: orange; box-shadow: 0 0 15px orange; }
|
37 |
+
28% { border-color: yellow; box-shadow: 0 0 15px yellow; }
|
38 |
+
42% { border-color: green; box-shadow: 0 0 15px green; }
|
39 |
+
56% { border-color: blue; box-shadow: 0 0 15px blue; }
|
40 |
+
70% { border-color: indigo; box-shadow: 0 0 15px indigo; }
|
41 |
+
84% { border-color: violet; box-shadow: 0 0 15px violet; }
|
42 |
+
100% { border-color: red; box-shadow: 0 0 15px red; }
|
43 |
+
}
|
44 |
+
|
45 |
+
.rainbow-box {
|
46 |
+
border: 3px solid red;
|
47 |
+
border-radius: 15px;
|
48 |
+
padding: 25px;
|
49 |
+
margin: 20px 0;
|
50 |
+
animation: rainbow 5s linear infinite;
|
51 |
+
background: rgba(0, 0, 0, 0); /* 完全透明背景 */
|
52 |
+
}
|
53 |
+
|
54 |
+
.lawsuit-info {
|
55 |
+
font-family: "Microsoft JhengHei", sans-serif;
|
56 |
+
line-height: 1.6;
|
57 |
+
white-space: pre-line;
|
58 |
+
text-shadow: 0 0 5px rgba(255, 255, 255, 0.8); /* 添加文字陰影讓文字更清晰 */
|
59 |
+
}
|
60 |
+
|
61 |
+
.lawsuit-title {
|
62 |
+
font-weight: bold;
|
63 |
+
font-size: 1.5em;
|
64 |
+
color: #FF4B4B;
|
65 |
+
margin-bottom: 15px;
|
66 |
+
text-shadow: 0 0 10px rgba(255, 75, 75, 0.5); /* 紅色標題特效 */
|
67 |
+
}
|
68 |
+
|
69 |
+
.cost-section {
|
70 |
+
margin: 15px 0;
|
71 |
+
}
|
72 |
+
|
73 |
+
.cost-title {
|
74 |
+
font-weight: bold;
|
75 |
+
color: #1E88E5;
|
76 |
+
text-shadow: 0 0 8px rgba(30, 136, 229, 0.5); /* 藍色標題特效 */
|
77 |
+
}
|
78 |
+
|
79 |
+
.highlight {
|
80 |
+
color: #FF4B4B;
|
81 |
+
font-weight: bold;
|
82 |
+
text-shadow: 0 0 8px rgba(255, 75, 75, 0.5); /* 高亮文字特效 */
|
83 |
+
}
|
84 |
+
|
85 |
+
/* 加強霓虹效果 */
|
86 |
+
.rainbow-box:hover {
|
87 |
+
transform: scale(1.01);
|
88 |
+
transition: transform 0.3s ease;
|
89 |
+
}
|
90 |
+
</style>
|
91 |
+
""", unsafe_allow_html=True)
|
92 |
+
|
93 |
+
# 顯示標題
|
94 |
+
st.markdown("<h1 style='text-align: center; color: #FF4B4B;'>🐮 哞哞文章相似度檢測</h1>", unsafe_allow_html=True)
|
95 |
+
|
96 |
+
# 創建兩列佈局
|
97 |
+
col1, col2 = st.columns(2)
|
98 |
+
|
99 |
+
with col1:
|
100 |
+
st.markdown("### 📝 文章1")
|
101 |
+
text1 = st.text_area("", height=300, placeholder="請在這裡輸入第一篇文章...", key="text1")
|
102 |
+
|
103 |
+
with col2:
|
104 |
+
st.markdown("### 📝 文章2")
|
105 |
+
text2 = st.text_area("", height=300, placeholder="請在這裡輸入第二篇文章...", key="text2")
|
106 |
+
|
107 |
+
# 創建按鈕列
|
108 |
+
col_btn1, col_btn2, col_btn3 = st.columns([1,1,1])
|
109 |
+
|
110 |
+
with col_btn2:
|
111 |
+
start_btn = st.button("🚀 開始計算相似度", type="primary", use_container_width=True)
|
112 |
+
|
113 |
+
def calculate_similarity(text1, text2):
|
114 |
+
"""計算文本相似度"""
|
115 |
+
if not text1.strip() or not text2.strip():
|
116 |
+
return None, None
|
117 |
+
|
118 |
+
# 1. 計算字詞重合度
|
119 |
+
words1 = list(jieba.cut(text1))
|
120 |
+
words2 = list(jieba.cut(text2))
|
121 |
+
word_set1 = set(words1)
|
122 |
+
word_set2 = set(words2)
|
123 |
+
word_similarity = len(word_set1.intersection(word_set2)) / len(word_set1.union(word_set2))
|
124 |
+
|
125 |
+
# 2. 計算句子相似度
|
126 |
+
sentences1 = text1.split("。")
|
127 |
+
sentences2 = text2.split("。")
|
128 |
+
sentence_matcher = difflib.SequenceMatcher(None, sentences1, sentences2)
|
129 |
+
sentence_similarity = sentence_matcher.ratio()
|
130 |
+
|
131 |
+
# 3. 計算TF-IDF相似度
|
132 |
+
vectorizer = TfidfVectorizer()
|
133 |
+
try:
|
134 |
+
tfidf_matrix = vectorizer.fit_transform([text1, text2])
|
135 |
+
cosine_sim = cosine_similarity(tfidf_matrix[0:1], tfidf_matrix[1:2])[0][0]
|
136 |
+
except:
|
137 |
+
cosine_sim = 0
|
138 |
+
|
139 |
+
# 計算總相似度
|
140 |
+
weights = [0.4, 0.3, 0.3]
|
141 |
+
total_similarity = (word_similarity * weights[0] +
|
142 |
+
sentence_similarity * weights[1] +
|
143 |
+
cosine_sim * weights[2]) * 100
|
144 |
+
|
145 |
+
similarity_score = round(total_similarity, 2)
|
146 |
+
|
147 |
+
# 判定結果
|
148 |
+
if similarity_score <= 30:
|
149 |
+
result = "兩篇文章沒有關係"
|
150 |
+
elif similarity_score <= 60:
|
151 |
+
result = "兩篇文章似乎有那麼一點關係"
|
152 |
+
elif similarity_score <= 80:
|
153 |
+
result = "兩篇文章很類似"
|
154 |
+
else:
|
155 |
+
result = "兩篇文章有抄襲犯罪的味道"
|
156 |
+
|
157 |
+
return similarity_score, result
|
158 |
+
|
159 |
+
if start_btn and text1 and text2:
|
160 |
+
with st.spinner('🔍 分析中,請稍等...'):
|
161 |
+
# 顯示進度條
|
162 |
+
progress_text = "計算中..."
|
163 |
+
my_bar = st.progress(0, text=progress_text)
|
164 |
+
for percent_complete in range(100):
|
165 |
+
time.sleep(0.01)
|
166 |
+
my_bar.progress(percent_complete + 1, text=progress_text)
|
167 |
+
|
168 |
+
# 計算相似度
|
169 |
+
similarity_score, result = calculate_similarity(text1, text2)
|
170 |
+
|
171 |
+
if similarity_score is not None:
|
172 |
+
# 清除進度條
|
173 |
+
my_bar.empty()
|
174 |
+
|
175 |
+
# 顯示結果
|
176 |
+
st.markdown("---")
|
177 |
+
st.markdown("<h3 style='text-align: center;'>✨ 分析結果</h3>", unsafe_allow_html=True)
|
178 |
+
|
179 |
+
result_text = f"""
|
180 |
+
<div style='text-align: center;'>
|
181 |
+
<p class='big-font'>相似度:{similarity_score}%</p>
|
182 |
+
<p class='result-font'>分析結果:{result}</p>
|
183 |
+
</div>
|
184 |
+
"""
|
185 |
+
st.markdown(result_text, unsafe_allow_html=True)
|
186 |
+
|
187 |
+
# 顯示可愛的表情符號
|
188 |
+
if similarity_score <= 30:
|
189 |
+
st.markdown("<h1 style='text-align: center;'>😌</h1>", unsafe_allow_html=True)
|
190 |
+
elif similarity_score <= 60:
|
191 |
+
st.markdown("<h1 style='text-align: center;'>🤔</h1>", unsafe_allow_html=True)
|
192 |
+
elif similarity_score <= 80:
|
193 |
+
st.markdown("<h1 style='text-align: center;'>😮</h1>", unsafe_allow_html=True)
|
194 |
+
else:
|
195 |
+
st.markdown("<h1 style='text-align: center;'>😱</h1>", unsafe_allow_html=True)
|
196 |
+
else:
|
197 |
+
st.info('👆 請在上方輸入兩篇要比較的文章,然後點擊"開始計算相似度"按鈕')
|
198 |
+
|
199 |
+
# 訴訟資訊文本
|
200 |
+
lawsuit_info = """
|
201 |
+
<div class="rainbow-box">
|
202 |
+
<div class="lawsuit-info">
|
203 |
+
<div class="lawsuit-title">馬的~這個小王八蛋抄襲我的文章! 一鍵網路告發直通車</div>
|
204 |
+
·智慧財產局網站:https://www.tipo.gov.tw/
|
205 |
+
|
206 |
+
<div class="cost-section">
|
207 |
+
<span class="cost-title">(備註)♡此次提告訴訟預估花費的公帑估算♡</span>
|
208 |
+
|
209 |
+
1. 人員成本(每月)
|
210 |
+
• 法官薪資:約新台幣 80,000-100,000元
|
211 |
+
• 書記官薪資:約新台幣 45,000-60,000元
|
212 |
+
• 其他行政人員:約新台幣 40,000元
|
213 |
+
|
214 |
+
2. 訴訟時程與開庭資訊
|
215 |
+
• 智慧財產法院民事第一審平均結案日數:約240天
|
216 |
+
• 平均開庭次數:約3-4次
|
217 |
+
• 每次開庭約需2小時
|
218 |
+
|
219 |
+
3. 成本估算(以一個案件計)
|
220 |
+
直接人事成本:
|
221 |
+
1. 法官成本:
|
222 |
+
• 每月薪資÷20工作天÷8小時 × 2小時 × 4次開庭
|
223 |
+
• = (90,000÷160) × 2 × 4 = 約4,500元
|
224 |
+
2. 書記官成本:
|
225 |
+
• 每月薪資÷20工作天÷8小時 × 2小時 × 4次開庭
|
226 |
+
• = (50,000÷160) × 2 × 4 = 約2,500元
|
227 |
+
3. 行政人員處理成本:
|
228 |
+
• 約5,000元(含文書處理、歸檔等)
|
229 |
+
|
230 |
+
間接成本:
|
231 |
+
1. 場地使用成本(含水電):約3,000元
|
232 |
+
2. 文書處理成本:約2,000元
|
233 |
+
3. 行政作業成本:約3,000元
|
234 |
+
|
235 |
+
<span class="highlight">總計:
|
236 |
+
一個著作權侵權民事訴訟案件,預估會花費納稅人約新台幣20,000元。</span>
|
237 |
+
|
238 |
+
其他考量:
|
239 |
+
1. 若案件進入第二審,成本將增加約50-80%
|
240 |
+
2. 如果需要專業鑑定,費用會更高
|
241 |
+
3. 若有調解程序,可能會縮短訴訟時間,降低成本
|
242 |
+
|
243 |
+
<span class="highlight">建議:
|
244 |
+
你想靠這小賺一點錢的話,不如去新北市樹林區上午的菜市場給無照駕駛的老阿公或老阿罵撞還會理賠更多,有機會中大獎如民國104彭姓少年下樓買珍珠奶茶被阿罵無照駕駛機車撞住院住了半年案,可以獲得的理賠金更多。</span>
|
245 |
+
</div>
|
246 |
+
</div>
|
247 |
+
</div>
|
248 |
+
"""
|
249 |
+
|
250 |
+
# 在info提示後顯示訴訟資訊
|
251 |
+
st.markdown(lawsuit_info, unsafe_allow_html=True)
|
252 |
+
|
253 |
+
# 在底部添加說明
|
254 |
+
st.markdown("---")
|
255 |
+
st.markdown("""
|
256 |
+
<div style='text-align: center;'>
|
257 |
+
<p style='color: gray; font-size: 14px;'>
|
258 |
+
💡 判定標準:<br>
|
259 |
+
0-30%:文章沒有關係 | 31-60%:稍有關係 | 61-80%:很類似 | 81-100%:疑似抄襲
|
260 |
+
</p>
|
261 |
+
</div>
|
262 |
+
""", unsafe_allow_html=True)
|