3a05chatgpt commited on
Commit
2fafc2b
·
verified ·
1 Parent(s): 21fc196

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +286 -70
app.py CHANGED
@@ -163,88 +163,304 @@ with gr.Blocks(
163
  theme=gr.themes.Soft(),
164
  title="PDF 摘要助手",
165
  css="""
 
166
  .gradio-container {
167
  max-width: 1200px !important;
 
 
168
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  .tab-nav {
170
- background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171
  }
172
- """
173
- ) as demo:
174
- gr.Markdown("""
175
- # 📄 PDF 摘要 & 問答助手
176
 
177
- 🚀 **歡迎使用 PDF 智能分析工具!**
 
 
 
 
 
 
 
 
 
 
178
 
179
- 這個工具可以幫助您:
180
- - 📋 自動生成 PDF 文檔摘要
181
- - 🤖 基於文檔內容回答問題
182
- - 💡 快速理解長篇文檔的核心內容
 
 
 
 
 
 
 
183
 
184
- ⚠️ **使用前請先在「設定」頁面輸入您的 OpenAI API Key**
 
 
185
 
186
- ---
187
- """)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
188
 
189
- with gr.Tab("🔧 設定"):
190
- with gr.Row():
191
- with gr.Column():
192
- api_key_input = gr.Textbox(
193
- label="🔑 輸入 OpenAI API Key",
194
- type="password",
195
- placeholder="請輸入您的 OpenAI API Key"
196
- )
197
- api_key_status = gr.Textbox(
198
- label="API 狀態",
199
- interactive=False,
200
- value="等待設定 API Key..."
201
- )
202
-
203
- with gr.Column():
204
- model_choice = gr.Radio(
205
- ["gpt-4", "gpt-4.1", "gpt-4.5"],
206
- label="🤖 選擇模型",
207
- value="gpt-4"
208
- )
209
- model_status = gr.Textbox(
210
- label="模型狀態",
211
- interactive=False,
212
- value="✅ 模型已選擇:gpt-4"
213
- )
 
 
 
 
 
214
 
215
- with gr.Tab("📄 PDF 處理"):
216
- with gr.Row():
217
- with gr.Column():
218
- pdf_upload = gr.File(
219
- label="📁 上傳 PDF 文件",
220
- file_types=[".pdf"]
221
- )
222
- with gr.Row():
223
- summary_btn = gr.Button("🔄 生成摘要", variant="primary")
224
- clear_btn = gr.Button("🗑️ 清除資料", variant="secondary")
225
-
226
- with gr.Column():
227
- summary_output = gr.Textbox(
228
- label="📋 PDF 摘要",
229
- lines=15,
230
- placeholder="上傳 PDF 文件並點擊 '生成摘要' 按鈕"
231
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
232
 
233
- with gr.Tab("❓ 問答"):
234
- with gr.Row():
235
- with gr.Column():
236
- question_input = gr.Textbox(
237
- label="💬 請輸入您的問題",
238
- placeholder="例如:這份文件的主要結論是什麼?"
239
- )
240
- question_btn = gr.Button("📤 送出問題", variant="primary")
241
-
242
- with gr.Column():
243
- answer_output = gr.Textbox(
244
- label="🤖 AI 回答",
245
- lines=10,
246
- placeholder="AI 回答將顯示在這裡"
247
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
248
 
249
  # 事件處理器
250
  api_key_input.submit(set_api_key, inputs=api_key_input, outputs=api_key_status)
 
163
  theme=gr.themes.Soft(),
164
  title="PDF 摘要助手",
165
  css="""
166
+ /* 全域樣式 */
167
  .gradio-container {
168
  max-width: 1200px !important;
169
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
170
+ min-height: 100vh;
171
  }
172
+
173
+ /* 主要內容區域 */
174
+ .main-content {
175
+ background: rgba(255, 255, 255, 0.95) !important;
176
+ border-radius: 20px !important;
177
+ margin: 20px !important;
178
+ padding: 30px !important;
179
+ box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1) !important;
180
+ backdrop-filter: blur(10px) !important;
181
+ }
182
+
183
+ /* 標題樣式 */
184
+ .main-header {
185
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
186
+ -webkit-background-clip: text !important;
187
+ -webkit-text-fill-color: transparent !important;
188
+ text-align: center !important;
189
+ font-size: 2.5em !important;
190
+ font-weight: bold !important;
191
+ margin-bottom: 20px !important;
192
+ }
193
+
194
+ /* 分頁導航 */
195
  .tab-nav {
196
+ background: linear-gradient(90deg, #667eea 0%, #764ba2 100%) !important;
197
+ border-radius: 15px 15px 0 0 !important;
198
+ padding: 10px !important;
199
+ }
200
+
201
+ .tab-nav button {
202
+ background: rgba(255, 255, 255, 0.2) !important;
203
+ color: white !important;
204
+ border: none !important;
205
+ border-radius: 10px !important;
206
+ margin: 0 5px !important;
207
+ padding: 12px 24px !important;
208
+ font-weight: 600 !important;
209
+ transition: all 0.3s ease !important;
210
+ }
211
+
212
+ .tab-nav button:hover {
213
+ background: rgba(255, 255, 255, 0.3) !important;
214
+ transform: translateY(-2px) !important;
215
+ }
216
+
217
+ .tab-nav button.selected {
218
+ background: white !important;
219
+ color: #764ba2 !important;
220
+ box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2) !important;
221
+ }
222
+
223
+ /* 輸入框樣式 */
224
+ .gr-textbox input, .gr-textbox textarea {
225
+ border: 2px solid #e0e6ff !important;
226
+ border-radius: 12px !important;
227
+ padding: 15px !important;
228
+ font-size: 16px !important;
229
+ transition: all 0.3s ease !important;
230
+ }
231
+
232
+ .gr-textbox input:focus, .gr-textbox textarea:focus {
233
+ border-color: #667eea !important;
234
+ box-shadow: 0 0 20px rgba(102, 126, 234, 0.3) !important;
235
+ outline: none !important;
236
+ }
237
+
238
+ /* 按鈕樣式 */
239
+ .gr-button {
240
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
241
+ border: none !important;
242
+ border-radius: 12px !important;
243
+ color: white !important;
244
+ font-weight: 600 !important;
245
+ padding: 15px 30px !important;
246
+ font-size: 16px !important;
247
+ transition: all 0.3s ease !important;
248
+ box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4) !important;
249
+ }
250
+
251
+ .gr-button:hover {
252
+ transform: translateY(-3px) !important;
253
+ box-shadow: 0 8px 25px rgba(102, 126, 234, 0.6) !important;
254
+ }
255
+
256
+ .gr-button.secondary {
257
+ background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%) !important;
258
+ }
259
+
260
+ /* 文件上傳區域 */
261
+ .gr-file {
262
+ border: 3px dashed #667eea !important;
263
+ border-radius: 15px !important;
264
+ background: rgba(102, 126, 234, 0.05) !important;
265
+ padding: 40px !important;
266
+ text-align: center !important;
267
+ transition: all 0.3s ease !important;
268
+ }
269
+
270
+ .gr-file:hover {
271
+ background: rgba(102, 126, 234, 0.1) !important;
272
+ border-color: #764ba2 !important;
273
+ }
274
+
275
+ /* 單選按鈕樣式 */
276
+ .gr-radio {
277
+ background: rgba(102, 126, 234, 0.05) !important;
278
+ border-radius: 12px !important;
279
+ padding: 20px !important;
280
+ }
281
+
282
+ /* 卡片樣式 */
283
+ .gr-panel {
284
+ background: rgba(255, 255, 255, 0.9) !important;
285
+ border-radius: 15px !important;
286
+ border: 1px solid rgba(102, 126, 234, 0.2) !important;
287
+ box-shadow: 0 5px 20px rgba(0, 0, 0, 0.08) !important;
288
+ padding: 25px !important;
289
+ margin: 10px 0 !important;
290
+ }
291
+
292
+ /* 隱藏 Gradio logo */
293
+ .gradio-container footer {
294
+ display: none !important;
295
  }
 
 
 
 
296
 
297
+ .footer {
298
+ display: none !important;
299
+ }
300
+
301
+ /* 隱藏底部所有元素 */
302
+ div[class*="footer"],
303
+ div[class*="Footer"],
304
+ .gr-footer,
305
+ footer {
306
+ display: none !important;
307
+ }
308
 
309
+ /* 頁面動畫 */
310
+ @keyframes fadeInUp {
311
+ from {
312
+ opacity: 0;
313
+ transform: translateY(30px);
314
+ }
315
+ to {
316
+ opacity: 1;
317
+ transform: translateY(0);
318
+ }
319
+ }
320
 
321
+ .gr-panel {
322
+ animation: fadeInUp 0.6s ease-out !important;
323
+ }
324
 
325
+ /* 響應式設計 */
326
+ @media (max-width: 768px) {
327
+ .gradio-container {
328
+ margin: 10px !important;
329
+ }
330
+
331
+ .main-content {
332
+ padding: 20px !important;
333
+ margin: 10px !important;
334
+ }
335
+
336
+ .main-header {
337
+ font-size: 2em !important;
338
+ }
339
+ }
340
+ """
341
+ ) as demo:
342
+ with gr.Column(elem_classes="main-content"):
343
+ gr.Markdown("""
344
+ <div class="main-header">📄 PDF 摘要 & 問答助手</div>
345
+
346
+ <div style="text-align: center; margin-bottom: 30px; padding: 25px; background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%); border-radius: 15px; border-left: 5px solid #667eea;">
347
+ <h3 style="color: #667eea; margin-bottom: 15px;">🚀 歡迎使用 PDF 智能分析工具!</h3>
348
+ <div style="display: flex; justify-content: space-around; flex-wrap: wrap; margin: 20px 0;">
349
+ <div style="margin: 10px; padding: 15px; background: white; border-radius: 10px; box-shadow: 0 3px 10px rgba(0,0,0,0.1); min-width: 200px;">
350
+ <div style="font-size: 24px; margin-bottom: 10px;">📋</div>
351
+ <strong>智能摘要生成</strong><br>
352
+ <span style="color: #666;">自動分析 PDF 內容並生成結構化摘要</span>
353
+ </div>
354
+ <div style="margin: 10px; padding: 15px; background: white; border-radius: 10px; box-shadow: 0 3px 10px rgba(0,0,0,0.1); min-width: 200px;">
355
+ <div style="font-size: 24px; margin-bottom: 10px;">🤖</div>
356
+ <strong>AI 問答系統</strong><br>
357
+ <span style="color: #666;">基於文檔內容回答您的問題</span>
358
+ </div>
359
+ <div style="margin: 10px; padding: 15px; background: white; border-radius: 10px; box-shadow: 0 3px 10px rgba(0,0,0,0.1); min-width: 200px;">
360
+ <div style="font-size: 24px; margin-bottom: 10px;">💡</div>
361
+ <strong>快速理解</strong><br>
362
+ <span style="color: #666;">快速掌握長篇文檔的核心內容</span>
363
+ </div>
364
+ </div>
365
+ <div style="background: rgba(255, 193, 7, 0.1); padding: 15px; border-radius: 10px; border-left: 4px solid #ffc107; margin-top: 20px;">
366
+ <strong style="color: #e65100;">⚠️ 重要提醒:</strong> 使用前請先在「🔧 設定」頁面輸入您的 OpenAI API Key
367
+ </div>
368
+ </div>
369
+ """)
370
 
371
+ with gr.Tab("🔧 設定", elem_classes="settings-tab"):
372
+ gr.Markdown("### ⚙️ 基本設定")
373
+ with gr.Row():
374
+ with gr.Column():
375
+ api_key_input = gr.Textbox(
376
+ label="🔑 輸入 OpenAI API Key",
377
+ type="password",
378
+ placeholder="請輸入您的 OpenAI API Key (sk-...)",
379
+ elem_classes="api-input"
380
+ )
381
+ api_key_status = gr.Textbox(
382
+ label="📊 API 連接狀態",
383
+ interactive=False,
384
+ value="🔄 等待設定 API Key...",
385
+ elem_classes="status-display"
386
+ )
387
+
388
+ with gr.Column():
389
+ model_choice = gr.Radio(
390
+ ["gpt-4", "gpt-4.1", "gpt-4.5"],
391
+ label="🤖 選擇 AI 模型",
392
+ value="gpt-4",
393
+ elem_classes="model-selector"
394
+ )
395
+ model_status = gr.Textbox(
396
+ label="🎯 當前模型",
397
+ interactive=False,
398
+ value="✅ 已選擇:gpt-4",
399
+ elem_classes="status-display"
400
+ )
401
 
402
+ with gr.Tab("📄 PDF 處理", elem_classes="pdf-tab"):
403
+ gr.Markdown("### 📁 文件上傳與摘要生成")
404
+ with gr.Row():
405
+ with gr.Column():
406
+ pdf_upload = gr.File(
407
+ label="📎 選擇 PDF 文件",
408
+ file_types=[".pdf"],
409
+ elem_classes="file-upload"
410
+ )
411
+ gr.Markdown("**支援格式**:PDF 文件 (建議 < 10MB)")
412
+
413
+ with gr.Row():
414
+ summary_btn = gr.Button(
415
+ "🔄 開始生成摘要",
416
+ variant="primary",
417
+ elem_classes="primary-btn"
418
+ )
419
+ clear_btn = gr.Button(
420
+ "🗑️ 清除所有資料",
421
+ variant="secondary",
422
+ elem_classes="secondary-btn"
423
+ )
424
+
425
+ with gr.Column():
426
+ summary_output = gr.Textbox(
427
+ label="📋 AI 生成的文檔摘要",
428
+ lines=15,
429
+ placeholder="📄 上傳 PDF 文件並點擊「開始生成摘要」按鈕,AI 將為您分析文檔內容...",
430
+ elem_classes="summary-output"
431
+ )
432
 
433
+ with gr.Tab("❓ 智能問答", elem_classes="qa-tab"):
434
+ gr.Markdown("### 💬 基於文檔內容的 AI 問答")
435
+ with gr.Row():
436
+ with gr.Column():
437
+ question_input = gr.Textbox(
438
+ label="💭 請輸入您的問題",
439
+ placeholder="例如:這份文件的主要結論是什麼?文中提到的關鍵數據有哪些?",
440
+ lines=3,
441
+ elem_classes="question-input"
442
+ )
443
+ question_btn = gr.Button(
444
+ "📤 發送問題",
445
+ variant="primary",
446
+ elem_classes="primary-btn"
447
+ )
448
+
449
+ gr.Markdown("""
450
+ **💡 問題範例:**
451
+ - 這份文件討論的主要議題是什麼?
452
+ - 文中有哪些重要的統計數據?
453
+ - 作者的主要觀點和結論是什麼?
454
+ - 文件中提到的建議有哪些?
455
+ """)
456
+
457
+ with gr.Column():
458
+ answer_output = gr.Textbox(
459
+ label="🤖 AI 智能回答",
460
+ lines=12,
461
+ placeholder="🤖 請先上傳並生成 PDF 摘要,然後在左側輸入問題,AI 將基於文檔內容為您提供詳細回答...",
462
+ elem_classes="answer-output"
463
+ )
464
 
465
  # 事件處理器
466
  api_key_input.submit(set_api_key, inputs=api_key_input, outputs=api_key_status)