Prompthumanizer commited on
Commit
ae36be6
ยท
verified ยท
1 Parent(s): 9ddc37f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -41
app.py CHANGED
@@ -1240,48 +1240,82 @@ def create_jain_interface():
1240
  ]
1241
 
1242
  def set_example():
1243
- return random.choice(example_messages)
1244
-
1245
- def submit_message(message, history):
1246
- """๋ฉ”์‹œ์ง€ ์ „์†ก ์ฒ˜๋ฆฌ"""
1247
- return chat_function(message, history)
1248
-
1249
- # ์ด๋ฒคํŠธ ์—ฐ๊ฒฐ
1250
- send_btn.click(
1251
- fn=submit_message,
1252
- inputs=[msg_input, chatbot],
1253
- outputs=[chatbot, msg_input]
1254
- )
1255
-
1256
- msg_input.submit(
1257
- fn=submit_message,
1258
- inputs=[msg_input, chatbot],
1259
- outputs=[chatbot, msg_input]
1260
- )
1261
-
1262
- refresh_btn.click(
1263
- fn=get_system_status,
1264
- outputs=system_status,
1265
- )
1266
-
1267
- clear_btn.click(
1268
- fn=clear_memory,
1269
- outputs=[chatbot, msg_input]
1270
- )
1271
-
1272
- example_btn.click(
1273
- fn=set_example,
1274
- outputs=msg_input,
1275
- )
1276
-
1277
- # ์ฑ„ํŒ… ์ž…๋ ฅ ๊ธฐ๋Šฅ ์ถ”๊ฐ€
1278
- msg_input.submit(
1279
- fn=submit_message,
1280
- inputs=[msg_input, chatbot],
1281
- outputs=[chatbot, msg_input]
1282
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1283
 
1284
- return interface
1285
 
1286
  # ๋ฉ”์ธ ์‹คํ–‰ ํ•จ์ˆ˜
1287
  def main():
 
1240
  ]
1241
 
1242
  def set_example():
1243
+ return random.choice(example_messages)
1244
+
1245
+ def submit_message(message, history):
1246
+ """๋ฉ”์‹œ์ง€ ์ „์†ก ์ฒ˜๋ฆฌ"""
1247
+ return chat_function(message, history)
1248
+
1249
+ def get_system_status():
1250
+ return "์‹œ์Šคํ…œ ์ •์ƒ ์ž‘๋™ ์ค‘"
1251
+
1252
+ def clear_memory():
1253
+ return [], ""
1254
+
1255
+ with gr.Blocks() as interface:
1256
+ chatbot = gr.Chatbot()
1257
+ msg_input = gr.Textbox(
1258
+ placeholder="๋ฉ”์‹œ์ง€๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”...",
1259
+ lines=2,
1260
+ max_lines=10,
1261
+ elem_id="msg_input"
1262
+ )
1263
+ send_btn = gr.Button("์ „์†ก")
1264
+ refresh_btn = gr.Button("์ƒˆ๋กœ๊ณ ์นจ")
1265
+ clear_btn = gr.Button("์ดˆ๊ธฐํ™”")
1266
+ example_btn = gr.Button("์˜ˆ์ œ")
1267
+
1268
+ send_btn.click(
1269
+ fn=submit_message,
1270
+ inputs=[msg_input, chatbot],
1271
+ outputs=[chatbot, msg_input]
1272
+ )
1273
+
1274
+ msg_input.submit(
1275
+ fn=submit_message,
1276
+ inputs=[msg_input, chatbot],
1277
+ outputs=[chatbot, msg_input]
1278
+ )
1279
+
1280
+ refresh_btn.click(
1281
+ fn=get_system_status,
1282
+ outputs=chatbot,
1283
+ )
1284
+
1285
+ clear_btn.click(
1286
+ fn=clear_memory,
1287
+ outputs=[chatbot, msg_input]
1288
+ )
1289
+
1290
+ example_btn.click(
1291
+ fn=set_example,
1292
+ outputs=msg_input,
1293
+ )
1294
+
1295
+ msg_input.submit(
1296
+ fn=submit_message,
1297
+ inputs=[msg_input, chatbot],
1298
+ outputs=[chatbot, msg_input]
1299
+ )
1300
+
1301
+ # JS ์Šคํฌ๋ฆฝํŠธ ์ถ”๊ฐ€ (Enter=์ „์†ก, Shift+Enter=์ค„๋ฐ”๊ฟˆ)
1302
+ interface.load(
1303
+ _js="""
1304
+ () => {
1305
+ const textarea = document.querySelector('#msg_input textarea');
1306
+ if (textarea) {
1307
+ textarea.addEventListener('keydown', function(e) {
1308
+ if (e.key === 'Enter' && !e.shiftKey) {
1309
+ e.preventDefault();
1310
+ textarea.form.requestSubmit(); // ๋ฉ”์‹œ์ง€ ์ „์†ก
1311
+ }
1312
+ });
1313
+ }
1314
+ }
1315
+ """
1316
+ )
1317
 
1318
+ interface.launch()
1319
 
1320
  # ๋ฉ”์ธ ์‹คํ–‰ ํ•จ์ˆ˜
1321
  def main():