Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1240,48 +1240,82 @@ def create_jain_interface():
|
|
1240 |
]
|
1241 |
|
1242 |
def set_example():
|
1243 |
-
|
1244 |
-
|
1245 |
-
|
1246 |
-
|
1247 |
-
|
1248 |
-
|
1249 |
-
|
1250 |
-
|
1251 |
-
|
1252 |
-
|
1253 |
-
|
1254 |
-
|
1255 |
-
|
1256 |
-
|
1257 |
-
|
1258 |
-
|
1259 |
-
|
1260 |
-
|
1261 |
-
|
1262 |
-
|
1263 |
-
|
1264 |
-
|
1265 |
-
|
1266 |
-
|
1267 |
-
|
1268 |
-
|
1269 |
-
|
1270 |
-
|
1271 |
-
|
1272 |
-
|
1273 |
-
|
1274 |
-
|
1275 |
-
|
1276 |
-
|
1277 |
-
|
1278 |
-
|
1279 |
-
|
1280 |
-
|
1281 |
-
|
1282 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1283 |
|
1284 |
-
|
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():
|