tsengiii commited on
Commit
943166c
·
verified ·
1 Parent(s): 1ce8237

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -5
app.py CHANGED
@@ -1,4 +1,3 @@
1
- #app.py
2
  import time
3
  import gradio as gr
4
  import google.generativeai as genai
@@ -31,6 +30,12 @@ def transform_history(history):
31
  # 回應生成函數
32
  def response(message, history):
33
  global chat
 
 
 
 
 
 
34
  # 將 Gradio 的歷史紀錄轉換為 Gemini 的格式
35
  chat.history = transform_history(history)
36
 
@@ -43,7 +48,9 @@ def response(message, history):
43
  time.sleep(0.05) # 每個字符間隔 0.05 秒
44
  yield response.text[: i+1]
45
 
46
- # 建立 Gradio 聊天界面
47
- gr.ChatInterface(response,
48
- title='Gemini Chat',
49
- textbox=gr.Textbox(placeholder="Question to Gemini")).launch(share=True)
 
 
 
 
1
  import time
2
  import gradio as gr
3
  import google.generativeai as genai
 
30
  # 回應生成函數
31
  def response(message, history):
32
  global chat
33
+
34
+ # 增加問題篩選邏輯:僅回應與面試流程或建議相關的問題
35
+ if not ("面試" in message or "建議" in message):
36
+ yield "螃蟹小助理只能回答面試流程或面試建議的問題喔!"
37
+ return
38
+
39
  # 將 Gradio 的歷史紀錄轉換為 Gemini 的格式
40
  chat.history = transform_history(history)
41
 
 
48
  time.sleep(0.05) # 每個字符間隔 0.05 秒
49
  yield response.text[: i+1]
50
 
51
+ # 建立 Gradio 聊天界面,更新標題與設定
52
+ gr.ChatInterface(
53
+ response,
54
+ title='瑞昱面試小助手🦀',
55
+ textbox=gr.Textbox(placeholder="請問螃蟹小助理有關面試流程或建議的問題")
56
+ ).launch(share=True)