Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,6 +15,7 @@ import httpx
|
|
| 15 |
|
| 16 |
API_BASE_URL = os.getenv("API_BASE_URL", "http://localhost:9999/v1")
|
| 17 |
MODEL_NAME = os.getenv("MODEL_NAME", "Step-Audio-R1")
|
|
|
|
| 18 |
|
| 19 |
def escape_html(text):
|
| 20 |
"""Escape HTML special characters to prevent XSS"""
|
|
@@ -298,6 +299,8 @@ def chat(system_prompt, user_text, audio_file, history, max_tokens, temperature,
|
|
| 298 |
"stream": True,
|
| 299 |
"repetition_penalty": 1.0,
|
| 300 |
"stop_token_ids": [151665]
|
|
|
|
|
|
|
| 301 |
})
|
| 302 |
|
| 303 |
if response.status_code != 200:
|
|
@@ -419,7 +422,6 @@ custom_css = """
|
|
| 419 |
max-width: 100% !important;
|
| 420 |
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
| 421 |
}
|
| 422 |
-
|
| 423 |
/* 标题样式 */
|
| 424 |
.app-header {
|
| 425 |
text-align: center;
|
|
@@ -431,7 +433,6 @@ custom_css = """
|
|
| 431 |
margin-bottom: 1.5rem;
|
| 432 |
box-shadow: 0 8px 24px rgba(102, 126, 234, 0.35);
|
| 433 |
}
|
| 434 |
-
|
| 435 |
/* 标题背景装饰 */
|
| 436 |
.app-header::before {
|
| 437 |
content: '';
|
|
@@ -443,12 +444,10 @@ custom_css = """
|
|
| 443 |
background: radial-gradient(circle, rgba(255, 255, 255, 0.1) 0%, transparent 70%);
|
| 444 |
animation: rotate 20s linear infinite;
|
| 445 |
}
|
| 446 |
-
|
| 447 |
@keyframes rotate {
|
| 448 |
from { transform: rotate(0deg); }
|
| 449 |
to { transform: rotate(360deg); }
|
| 450 |
}
|
| 451 |
-
|
| 452 |
.app-header h1 {
|
| 453 |
margin: 0;
|
| 454 |
font-size: 2.8rem;
|
|
@@ -459,7 +458,6 @@ custom_css = """
|
|
| 459 |
position: relative;
|
| 460 |
z-index: 1;
|
| 461 |
}
|
| 462 |
-
|
| 463 |
.app-header p {
|
| 464 |
color: rgba(255, 255, 255, 0.95) !important;
|
| 465 |
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
|
|
@@ -467,14 +465,12 @@ custom_css = """
|
|
| 467 |
z-index: 1;
|
| 468 |
line-height: 1.5;
|
| 469 |
}
|
| 470 |
-
|
| 471 |
/* 聊天框样式 */
|
| 472 |
.chatbot-container {
|
| 473 |
border-radius: 12px;
|
| 474 |
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
|
| 475 |
overflow: hidden;
|
| 476 |
}
|
| 477 |
-
|
| 478 |
/* 思考过程样式 - 模仿Claude/ChatGPT的风格 */
|
| 479 |
.thinking-block {
|
| 480 |
background: linear-gradient(135deg, #f5f7fa 0%, #eef2f7 100%);
|
|
@@ -484,7 +480,6 @@ custom_css = """
|
|
| 484 |
border-radius: 8px;
|
| 485 |
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
|
| 486 |
}
|
| 487 |
-
|
| 488 |
.thinking-header {
|
| 489 |
display: flex;
|
| 490 |
align-items: center;
|
|
@@ -493,7 +488,6 @@ custom_css = """
|
|
| 493 |
margin-bottom: 10px;
|
| 494 |
font-size: 0.95rem;
|
| 495 |
}
|
| 496 |
-
|
| 497 |
.thinking-content {
|
| 498 |
background: #ffffff;
|
| 499 |
padding: 12px 16px;
|
|
@@ -506,7 +500,6 @@ custom_css = """
|
|
| 506 |
word-wrap: break-word;
|
| 507 |
border: 1px solid #e5e7eb;
|
| 508 |
}
|
| 509 |
-
|
| 510 |
/* 回复分隔线 */
|
| 511 |
.response-divider {
|
| 512 |
border: none;
|
|
@@ -514,19 +507,16 @@ custom_css = """
|
|
| 514 |
background: linear-gradient(to right, transparent, #e5e7eb, transparent);
|
| 515 |
margin: 20px 0;
|
| 516 |
}
|
| 517 |
-
|
| 518 |
/* 按钮样式 */
|
| 519 |
.primary-btn {
|
| 520 |
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
|
| 521 |
border: none !important;
|
| 522 |
transition: all 0.3s ease !important;
|
| 523 |
}
|
| 524 |
-
|
| 525 |
.primary-btn:hover {
|
| 526 |
transform: translateY(-2px);
|
| 527 |
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4) !important;
|
| 528 |
}
|
| 529 |
-
|
| 530 |
/* 左侧面板样式 */
|
| 531 |
.left-panel {
|
| 532 |
background: #f9fafb;
|
|
@@ -534,49 +524,41 @@ custom_css = """
|
|
| 534 |
padding: 1rem;
|
| 535 |
height: 100%;
|
| 536 |
}
|
| 537 |
-
|
| 538 |
/* 输入框样式 */
|
| 539 |
.input-box textarea {
|
| 540 |
border-radius: 8px !important;
|
| 541 |
border: 2px solid #e5e7eb !important;
|
| 542 |
transition: border-color 0.3s ease !important;
|
| 543 |
}
|
| 544 |
-
|
| 545 |
.input-box textarea:focus {
|
| 546 |
border-color: #667eea !important;
|
| 547 |
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1) !important;
|
| 548 |
}
|
| 549 |
-
|
| 550 |
/* 输入区域标题 */
|
| 551 |
h3 {
|
| 552 |
color: #374151;
|
| 553 |
font-size: 1.1rem;
|
| 554 |
margin: 1rem 0 0.5rem 0;
|
| 555 |
}
|
| 556 |
-
|
| 557 |
/* 聊天消息样式优化 */
|
| 558 |
.message-wrap {
|
| 559 |
padding: 1rem !important;
|
| 560 |
}
|
| 561 |
-
|
| 562 |
.message {
|
| 563 |
padding: 1rem !important;
|
| 564 |
border-radius: 12px !important;
|
| 565 |
line-height: 1.6 !important;
|
| 566 |
}
|
| 567 |
-
|
| 568 |
/* 用户消息 */
|
| 569 |
.message.user {
|
| 570 |
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
|
| 571 |
color: white !important;
|
| 572 |
}
|
| 573 |
-
|
| 574 |
/* 助手消息 */
|
| 575 |
.message.bot {
|
| 576 |
background: #f9fafb !important;
|
| 577 |
border: 1px solid #e5e7eb !important;
|
| 578 |
}
|
| 579 |
-
|
| 580 |
/* 左侧面板整体样式 */
|
| 581 |
.left-column {
|
| 582 |
background: linear-gradient(to bottom, #ffffff 0%, #f9fafb 100%);
|
|
@@ -584,29 +566,24 @@ h3 {
|
|
| 584 |
padding: 1rem;
|
| 585 |
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
|
| 586 |
}
|
| 587 |
-
|
| 588 |
/* 按钮容器样式 */
|
| 589 |
.button-row {
|
| 590 |
margin-top: 1rem;
|
| 591 |
gap: 0.5rem;
|
| 592 |
}
|
| 593 |
-
|
| 594 |
/* 滚动条美化 */
|
| 595 |
::-webkit-scrollbar {
|
| 596 |
width: 8px;
|
| 597 |
height: 8px;
|
| 598 |
}
|
| 599 |
-
|
| 600 |
::-webkit-scrollbar-track {
|
| 601 |
background: #f1f1f1;
|
| 602 |
border-radius: 4px;
|
| 603 |
}
|
| 604 |
-
|
| 605 |
::-webkit-scrollbar-thumb {
|
| 606 |
background: #888;
|
| 607 |
border-radius: 4px;
|
| 608 |
}
|
| 609 |
-
|
| 610 |
::-webkit-scrollbar-thumb:hover {
|
| 611 |
background: #555;
|
| 612 |
}
|
|
@@ -751,4 +728,4 @@ if __name__ == "__main__":
|
|
| 751 |
print(f"API地址: {API_BASE_URL}")
|
| 752 |
print(f"模型: {MODEL_NAME}")
|
| 753 |
|
| 754 |
-
demo.launch(server_name=args.host, server_port=args.port, share=False)
|
|
|
|
| 15 |
|
| 16 |
API_BASE_URL = os.getenv("API_BASE_URL", "http://localhost:9999/v1")
|
| 17 |
MODEL_NAME = os.getenv("MODEL_NAME", "Step-Audio-R1")
|
| 18 |
+
SECRET = os.getenv("API_SECRET", "")
|
| 19 |
|
| 20 |
def escape_html(text):
|
| 21 |
"""Escape HTML special characters to prevent XSS"""
|
|
|
|
| 299 |
"stream": True,
|
| 300 |
"repetition_penalty": 1.0,
|
| 301 |
"stop_token_ids": [151665]
|
| 302 |
+
}, headers={
|
| 303 |
+
"Authorization": f"Bearer {SECRET}",
|
| 304 |
})
|
| 305 |
|
| 306 |
if response.status_code != 200:
|
|
|
|
| 422 |
max-width: 100% !important;
|
| 423 |
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
| 424 |
}
|
|
|
|
| 425 |
/* 标题样式 */
|
| 426 |
.app-header {
|
| 427 |
text-align: center;
|
|
|
|
| 433 |
margin-bottom: 1.5rem;
|
| 434 |
box-shadow: 0 8px 24px rgba(102, 126, 234, 0.35);
|
| 435 |
}
|
|
|
|
| 436 |
/* 标题背景装饰 */
|
| 437 |
.app-header::before {
|
| 438 |
content: '';
|
|
|
|
| 444 |
background: radial-gradient(circle, rgba(255, 255, 255, 0.1) 0%, transparent 70%);
|
| 445 |
animation: rotate 20s linear infinite;
|
| 446 |
}
|
|
|
|
| 447 |
@keyframes rotate {
|
| 448 |
from { transform: rotate(0deg); }
|
| 449 |
to { transform: rotate(360deg); }
|
| 450 |
}
|
|
|
|
| 451 |
.app-header h1 {
|
| 452 |
margin: 0;
|
| 453 |
font-size: 2.8rem;
|
|
|
|
| 458 |
position: relative;
|
| 459 |
z-index: 1;
|
| 460 |
}
|
|
|
|
| 461 |
.app-header p {
|
| 462 |
color: rgba(255, 255, 255, 0.95) !important;
|
| 463 |
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
|
|
|
|
| 465 |
z-index: 1;
|
| 466 |
line-height: 1.5;
|
| 467 |
}
|
|
|
|
| 468 |
/* 聊天框样式 */
|
| 469 |
.chatbot-container {
|
| 470 |
border-radius: 12px;
|
| 471 |
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
|
| 472 |
overflow: hidden;
|
| 473 |
}
|
|
|
|
| 474 |
/* 思考过程样式 - 模仿Claude/ChatGPT的风格 */
|
| 475 |
.thinking-block {
|
| 476 |
background: linear-gradient(135deg, #f5f7fa 0%, #eef2f7 100%);
|
|
|
|
| 480 |
border-radius: 8px;
|
| 481 |
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
|
| 482 |
}
|
|
|
|
| 483 |
.thinking-header {
|
| 484 |
display: flex;
|
| 485 |
align-items: center;
|
|
|
|
| 488 |
margin-bottom: 10px;
|
| 489 |
font-size: 0.95rem;
|
| 490 |
}
|
|
|
|
| 491 |
.thinking-content {
|
| 492 |
background: #ffffff;
|
| 493 |
padding: 12px 16px;
|
|
|
|
| 500 |
word-wrap: break-word;
|
| 501 |
border: 1px solid #e5e7eb;
|
| 502 |
}
|
|
|
|
| 503 |
/* 回复分隔线 */
|
| 504 |
.response-divider {
|
| 505 |
border: none;
|
|
|
|
| 507 |
background: linear-gradient(to right, transparent, #e5e7eb, transparent);
|
| 508 |
margin: 20px 0;
|
| 509 |
}
|
|
|
|
| 510 |
/* 按钮样式 */
|
| 511 |
.primary-btn {
|
| 512 |
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
|
| 513 |
border: none !important;
|
| 514 |
transition: all 0.3s ease !important;
|
| 515 |
}
|
|
|
|
| 516 |
.primary-btn:hover {
|
| 517 |
transform: translateY(-2px);
|
| 518 |
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4) !important;
|
| 519 |
}
|
|
|
|
| 520 |
/* 左侧面板样式 */
|
| 521 |
.left-panel {
|
| 522 |
background: #f9fafb;
|
|
|
|
| 524 |
padding: 1rem;
|
| 525 |
height: 100%;
|
| 526 |
}
|
|
|
|
| 527 |
/* 输入框样式 */
|
| 528 |
.input-box textarea {
|
| 529 |
border-radius: 8px !important;
|
| 530 |
border: 2px solid #e5e7eb !important;
|
| 531 |
transition: border-color 0.3s ease !important;
|
| 532 |
}
|
|
|
|
| 533 |
.input-box textarea:focus {
|
| 534 |
border-color: #667eea !important;
|
| 535 |
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1) !important;
|
| 536 |
}
|
|
|
|
| 537 |
/* 输入区域标题 */
|
| 538 |
h3 {
|
| 539 |
color: #374151;
|
| 540 |
font-size: 1.1rem;
|
| 541 |
margin: 1rem 0 0.5rem 0;
|
| 542 |
}
|
|
|
|
| 543 |
/* 聊天消息样式优化 */
|
| 544 |
.message-wrap {
|
| 545 |
padding: 1rem !important;
|
| 546 |
}
|
|
|
|
| 547 |
.message {
|
| 548 |
padding: 1rem !important;
|
| 549 |
border-radius: 12px !important;
|
| 550 |
line-height: 1.6 !important;
|
| 551 |
}
|
|
|
|
| 552 |
/* 用户消息 */
|
| 553 |
.message.user {
|
| 554 |
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
|
| 555 |
color: white !important;
|
| 556 |
}
|
|
|
|
| 557 |
/* 助手消息 */
|
| 558 |
.message.bot {
|
| 559 |
background: #f9fafb !important;
|
| 560 |
border: 1px solid #e5e7eb !important;
|
| 561 |
}
|
|
|
|
| 562 |
/* 左侧面板整体样式 */
|
| 563 |
.left-column {
|
| 564 |
background: linear-gradient(to bottom, #ffffff 0%, #f9fafb 100%);
|
|
|
|
| 566 |
padding: 1rem;
|
| 567 |
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
|
| 568 |
}
|
|
|
|
| 569 |
/* 按钮容器样式 */
|
| 570 |
.button-row {
|
| 571 |
margin-top: 1rem;
|
| 572 |
gap: 0.5rem;
|
| 573 |
}
|
|
|
|
| 574 |
/* 滚动条美化 */
|
| 575 |
::-webkit-scrollbar {
|
| 576 |
width: 8px;
|
| 577 |
height: 8px;
|
| 578 |
}
|
|
|
|
| 579 |
::-webkit-scrollbar-track {
|
| 580 |
background: #f1f1f1;
|
| 581 |
border-radius: 4px;
|
| 582 |
}
|
|
|
|
| 583 |
::-webkit-scrollbar-thumb {
|
| 584 |
background: #888;
|
| 585 |
border-radius: 4px;
|
| 586 |
}
|
|
|
|
| 587 |
::-webkit-scrollbar-thumb:hover {
|
| 588 |
background: #555;
|
| 589 |
}
|
|
|
|
| 728 |
print(f"API地址: {API_BASE_URL}")
|
| 729 |
print(f"模型: {MODEL_NAME}")
|
| 730 |
|
| 731 |
+
demo.launch(server_name=args.host, server_port=args.port, share=False)
|