Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import time
|
| 2 |
import gradio as gr
|
| 3 |
import google.generativeai as genai
|
|
@@ -27,22 +28,12 @@ def transform_history(history):
|
|
| 27 |
new_history.append({"parts": [{"text": chat[1]}], "role": "model"})
|
| 28 |
return new_history
|
| 29 |
|
| 30 |
-
# 檢查問題是否與設備維護相關的函數
|
| 31 |
-
def is_maintenance_related(question):
|
| 32 |
-
keywords = ["maintenance", "repair", "inspection", "equipment", "servicing", "troubleshooting", "machine", "calibration", "preventive", "predictive", "breakdown"]
|
| 33 |
-
return any(keyword in question.lower() for keyword in keywords)
|
| 34 |
-
|
| 35 |
# 回應生成函數
|
| 36 |
def response(message, history):
|
| 37 |
global chat
|
| 38 |
# 將 Gradio 的歷史紀錄轉換為 Gemini 的格式
|
| 39 |
chat.history = transform_history(history)
|
| 40 |
|
| 41 |
-
# 檢查問題是否與設備維護相關
|
| 42 |
-
if not is_maintenance_related(message):
|
| 43 |
-
yield "抱歉,我只能回答與設備維護相關的問題。請輸入有關設備維護的問題。"
|
| 44 |
-
return
|
| 45 |
-
|
| 46 |
# 發送訊息到 Gemini API
|
| 47 |
response = chat.send_message(message)
|
| 48 |
response.resolve()
|
|
@@ -54,5 +45,5 @@ def response(message, history):
|
|
| 54 |
|
| 55 |
# 建立 Gradio 聊天界面
|
| 56 |
gr.ChatInterface(response,
|
| 57 |
-
title='
|
| 58 |
-
textbox=gr.Textbox(placeholder="
|
|
|
|
| 1 |
+
#app.py
|
| 2 |
import time
|
| 3 |
import gradio as gr
|
| 4 |
import google.generativeai as genai
|
|
|
|
| 28 |
new_history.append({"parts": [{"text": chat[1]}], "role": "model"})
|
| 29 |
return new_history
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
# 回應生成函數
|
| 32 |
def response(message, history):
|
| 33 |
global chat
|
| 34 |
# 將 Gradio 的歷史紀錄轉換為 Gemini 的格式
|
| 35 |
chat.history = transform_history(history)
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
# 發送訊息到 Gemini API
|
| 38 |
response = chat.send_message(message)
|
| 39 |
response.resolve()
|
|
|
|
| 45 |
|
| 46 |
# 建立 Gradio 聊天界面
|
| 47 |
gr.ChatInterface(response,
|
| 48 |
+
title='Gemini Chat',
|
| 49 |
+
textbox=gr.Textbox(placeholder="Question to Gemini")).launch(share=True)
|