kb2022 commited on
Commit
9c8197a
·
verified ·
1 Parent(s): 3e9fdcb

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -84,7 +84,7 @@ def estimate_ng_probability(input_text, thresold=0.3):
84
  # 会話履歴用リスト型変数
85
  message_history = []
86
 
87
- def chat(user_msg, mode, threshold):
88
  """
89
  AIとの会話を実行後、全会話履歴を返す
90
  user_msg: 入力されたユーザのメッセージ
@@ -118,11 +118,13 @@ with gr.Blocks() as demo:
118
  chatbot = gr.Chatbot()
119
  input = gr.Textbox(show_label=False, placeholder="チェックしたい文章を入力してください")
120
  mode = gr.Radio(["理由を出力", "確率を出力"], label="モードを選択")
121
- if mode == "確率を出力":
 
 
 
122
  threshold = gr.Slider(minimum=0, maximum=1, value=0.3, step=0.05, label="NG度の閾値")
123
- else:
124
- threshold = None
125
- input.submit(fn=chat, inputs=[input, mode, threshold], outputs=chatbot) # メッセージ送信されたら、AIと会話してチャット欄に全会話内容を表示
126
  input.submit(fn=lambda: "", inputs=None, outputs=input) # (上記に加えて)入力欄をクリア
127
 
128
  demo.launch(share=True)
 
84
  # 会話履歴用リスト型変数
85
  message_history = []
86
 
87
+ def chat(user_msg, mode, threshold=None):
88
  """
89
  AIとの会話を実行後、全会話履歴を返す
90
  user_msg: 入力されたユーザのメッセージ
 
118
  chatbot = gr.Chatbot()
119
  input = gr.Textbox(show_label=False, placeholder="チェックしたい文章を入力してください")
120
  mode = gr.Radio(["理由を出力", "確率を出力"], label="モードを選択")
121
+
122
+ if mode == "理由を出力":
123
+ input.submit(fn=chat, inputs=[input, mode], outputs=chatbot) # メッセージ送信されたら、AIと会話してチャット欄に全会話内容を表示
124
+ elif mode == "確率を出力":
125
  threshold = gr.Slider(minimum=0, maximum=1, value=0.3, step=0.05, label="NG度の閾値")
126
+ input.submit(fn=chat, inputs=[input, mode, threshold], outputs=chatbot) # メッセージ送信されたら、AIと会話してチャット欄に全会話内容を表示
127
+
 
128
  input.submit(fn=lambda: "", inputs=None, outputs=input) # (上記に加えて)入力欄をクリア
129
 
130
  demo.launch(share=True)