Spaces:
Sleeping
Sleeping
Going Back to Older Version
Browse files
App.py
CHANGED
|
@@ -8,7 +8,6 @@ import google.generativeai as genai
|
|
| 8 |
from anthropic import Anthropic
|
| 9 |
import openai
|
| 10 |
from typing import List, Dict, Any, Optional
|
| 11 |
-
from datetime import datetime
|
| 12 |
|
| 13 |
# Configure logging
|
| 14 |
logging.basicConfig(level=logging.INFO)
|
|
@@ -488,20 +487,10 @@ class PolyThinkOrchestrator:
|
|
| 488 |
"""
|
| 489 |
|
| 490 |
for sol in step["solutions"]:
|
| 491 |
-
# Fix the backslash issue by using a different approach to escape single quotes
|
| 492 |
-
escaped_solution = sol['solution'].replace("'", "'")
|
| 493 |
report += f"""
|
| 494 |
<div class="solution-item">
|
| 495 |
-
<div class="solution-header">
|
| 496 |
-
|
| 497 |
-
<div class="solution-controls">
|
| 498 |
-
<button class="copy-btn" onclick="copyToClipboard('{escaped_solution}')" title="Copy solution">📋</button>
|
| 499 |
-
<button class="toggle-btn" onclick="toggleSolution(this)" title="Toggle solution">▼</button>
|
| 500 |
-
</div>
|
| 501 |
-
</div>
|
| 502 |
-
<div class="solution-body" style="display: none;">
|
| 503 |
-
{sol['solution']}
|
| 504 |
-
</div>
|
| 505 |
</div>
|
| 506 |
"""
|
| 507 |
|
|
@@ -540,20 +529,10 @@ class PolyThinkOrchestrator:
|
|
| 540 |
"""
|
| 541 |
|
| 542 |
for sol in step["solutions"]:
|
| 543 |
-
# Fix the backslash issue by using a different approach to escape single quotes
|
| 544 |
-
escaped_solution = sol['solution'].replace("'", "'")
|
| 545 |
report += f"""
|
| 546 |
<div class="solution-item">
|
| 547 |
-
<div class="solution-header">
|
| 548 |
-
|
| 549 |
-
<div class="solution-controls">
|
| 550 |
-
<button class="copy-btn" onclick="copyToClipboard('{escaped_solution}')" title="Copy solution">📋</button>
|
| 551 |
-
<button class="toggle-btn" onclick="toggleSolution(this)" title="Toggle solution">▼</button>
|
| 552 |
-
</div>
|
| 553 |
-
</div>
|
| 554 |
-
<div class="solution-body" style="display: none;">
|
| 555 |
-
{sol['solution']}
|
| 556 |
-
</div>
|
| 557 |
</div>
|
| 558 |
"""
|
| 559 |
|
|
@@ -566,40 +545,18 @@ class PolyThinkOrchestrator:
|
|
| 566 |
last_judgment = next((step.get("judgment", "") for step in reversed(history) if "judgment" in step), "")
|
| 567 |
if "AGREEMENT: YES" in last_judgment.upper():
|
| 568 |
confidence = "100%" if len(history) == 2 else "80%"
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
| 572 |
-
|
| 573 |
-
|
| 574 |
-
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
report += f"""
|
| 578 |
-
<div class="conclusion-container agreement">
|
| 579 |
-
<h3>Final Agreed Solution</h3>
|
| 580 |
-
<div class="conclusion-content">
|
| 581 |
-
<div class="conclusion-icon">✅</div>
|
| 582 |
-
<div class="conclusion-text">
|
| 583 |
-
<p><strong>Answer:</strong> {answer}</p>
|
| 584 |
-
<p><strong>Reasoning:</strong> {reasoning}</p>
|
| 585 |
-
<p>Confidence level: <strong>{confidence}</strong></p>
|
| 586 |
-
</div>
|
| 587 |
-
</div>
|
| 588 |
-
</div>
|
| 589 |
-
"""
|
| 590 |
-
else:
|
| 591 |
-
report += f"""
|
| 592 |
-
<div class="conclusion-container agreement">
|
| 593 |
-
<h3>Conclusion</h3>
|
| 594 |
-
<div class="conclusion-content">
|
| 595 |
-
<div class="conclusion-icon">✅</div>
|
| 596 |
-
<div class="conclusion-text">
|
| 597 |
-
<p>Models reached <strong>AGREEMENT</strong></p>
|
| 598 |
-
<p>Confidence level: <strong>{confidence}</strong></p>
|
| 599 |
-
</div>
|
| 600 |
</div>
|
| 601 |
</div>
|
| 602 |
-
|
|
|
|
| 603 |
else:
|
| 604 |
report += f"""
|
| 605 |
<div class="conclusion-container disagreement">
|
|
@@ -617,33 +574,13 @@ class PolyThinkOrchestrator:
|
|
| 617 |
report += """
|
| 618 |
</div>
|
| 619 |
</div>
|
| 620 |
-
<script>
|
| 621 |
-
function copyToClipboard(text) {
|
| 622 |
-
navigator.clipboard.writeText(text).then(() => {
|
| 623 |
-
// Show a temporary success message
|
| 624 |
-
const btn = event.target;
|
| 625 |
-
const originalText = btn.textContent;
|
| 626 |
-
btn.textContent = '✓';
|
| 627 |
-
setTimeout(() => {
|
| 628 |
-
btn.textContent = originalText;
|
| 629 |
-
}, 1000);
|
| 630 |
-
});
|
| 631 |
-
}
|
| 632 |
-
|
| 633 |
-
function toggleSolution(btn) {
|
| 634 |
-
const solutionBody = btn.closest('.solution-item').querySelector('.solution-body');
|
| 635 |
-
const isHidden = solutionBody.style.display === 'none';
|
| 636 |
-
solutionBody.style.display = isHidden ? 'block' : 'none';
|
| 637 |
-
btn.textContent = isHidden ? '▲' : '▼';
|
| 638 |
-
}
|
| 639 |
-
</script>
|
| 640 |
"""
|
| 641 |
|
| 642 |
return report
|
| 643 |
|
| 644 |
# --- Gradio Interface ---
|
| 645 |
def create_polythink_interface():
|
| 646 |
-
|
| 647 |
/* Reverted to Original Black Theme */
|
| 648 |
body {
|
| 649 |
background: #000000;
|
|
@@ -707,56 +644,13 @@ def create_polythink_interface():
|
|
| 707 |
.step-section strong {
|
| 708 |
color: #ffffff;
|
| 709 |
}
|
| 710 |
-
|
| 711 |
-
/* Enhanced Status Bar */
|
| 712 |
.status-bar {
|
| 713 |
background: #1a1a1a;
|
| 714 |
-
padding:
|
| 715 |
border-radius: 5px;
|
| 716 |
font-size: 1.1em;
|
| 717 |
margin-bottom: 20px;
|
| 718 |
border-left: 4px solid #666666;
|
| 719 |
-
position: relative;
|
| 720 |
-
overflow: hidden;
|
| 721 |
-
}
|
| 722 |
-
|
| 723 |
-
.status-progress {
|
| 724 |
-
position: absolute;
|
| 725 |
-
bottom: 0;
|
| 726 |
-
left: 0;
|
| 727 |
-
height: 3px;
|
| 728 |
-
background: linear-gradient(90deg, #4CAF50, #2196F3);
|
| 729 |
-
transition: width 0.3s ease;
|
| 730 |
-
}
|
| 731 |
-
|
| 732 |
-
.status-icon {
|
| 733 |
-
display: inline-block;
|
| 734 |
-
margin-right: 10px;
|
| 735 |
-
font-size: 1.2em;
|
| 736 |
-
}
|
| 737 |
-
|
| 738 |
-
.status-message {
|
| 739 |
-
display: inline-block;
|
| 740 |
-
vertical-align: middle;
|
| 741 |
-
}
|
| 742 |
-
|
| 743 |
-
.status-stage {
|
| 744 |
-
display: inline-block;
|
| 745 |
-
margin-left: 15px;
|
| 746 |
-
padding: 4px 8px;
|
| 747 |
-
border-radius: 12px;
|
| 748 |
-
font-size: 0.9em;
|
| 749 |
-
background: rgba(255, 255, 255, 0.1);
|
| 750 |
-
}
|
| 751 |
-
|
| 752 |
-
.status-stage.active {
|
| 753 |
-
background: rgba(76, 175, 80, 0.2);
|
| 754 |
-
color: #4CAF50;
|
| 755 |
-
}
|
| 756 |
-
|
| 757 |
-
.status-stage.completed {
|
| 758 |
-
background: rgba(33, 150, 243, 0.2);
|
| 759 |
-
color: #2196F3;
|
| 760 |
}
|
| 761 |
|
| 762 |
/* Agreement/Disagreement styling */
|
|
@@ -891,12 +785,6 @@ def create_polythink_interface():
|
|
| 891 |
border-radius: 5px;
|
| 892 |
overflow: hidden;
|
| 893 |
border: 1px solid #383838;
|
| 894 |
-
transition: all 0.3s ease;
|
| 895 |
-
}
|
| 896 |
-
|
| 897 |
-
.solution-item:hover {
|
| 898 |
-
transform: translateY(-2px);
|
| 899 |
-
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
|
| 900 |
}
|
| 901 |
|
| 902 |
.solution-header {
|
|
@@ -905,9 +793,6 @@ def create_polythink_interface():
|
|
| 905 |
font-weight: bold;
|
| 906 |
color: #dddddd;
|
| 907 |
border-bottom: 1px solid #444444;
|
| 908 |
-
display: flex;
|
| 909 |
-
justify-content: space-between;
|
| 910 |
-
align-items: center;
|
| 911 |
}
|
| 912 |
|
| 913 |
.solution-body {
|
|
@@ -951,41 +836,14 @@ def create_polythink_interface():
|
|
| 951 |
margin: 5px 0;
|
| 952 |
}
|
| 953 |
|
| 954 |
-
/*
|
| 955 |
.app-header {
|
| 956 |
-
background: linear-gradient(
|
| 957 |
-
background-size: 400% 400%;
|
| 958 |
-
animation: gradient 15s ease infinite;
|
| 959 |
padding: 20px;
|
| 960 |
border-radius: 10px;
|
| 961 |
margin-bottom: 20px;
|
| 962 |
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
|
| 963 |
border: 1px solid #444444;
|
| 964 |
-
position: relative;
|
| 965 |
-
overflow: hidden;
|
| 966 |
-
}
|
| 967 |
-
|
| 968 |
-
@keyframes gradient {
|
| 969 |
-
0% {
|
| 970 |
-
background-position: 0% 50%;
|
| 971 |
-
}
|
| 972 |
-
50% {
|
| 973 |
-
background-position: 100% 50%;
|
| 974 |
-
}
|
| 975 |
-
100% {
|
| 976 |
-
background-position: 0% 50%;
|
| 977 |
-
}
|
| 978 |
-
}
|
| 979 |
-
|
| 980 |
-
.app-header::before {
|
| 981 |
-
content: '';
|
| 982 |
-
position: absolute;
|
| 983 |
-
top: 0;
|
| 984 |
-
left: 0;
|
| 985 |
-
right: 0;
|
| 986 |
-
bottom: 0;
|
| 987 |
-
background: linear-gradient(45deg, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0) 100%);
|
| 988 |
-
pointer-events: none;
|
| 989 |
}
|
| 990 |
|
| 991 |
.app-title {
|
|
@@ -995,14 +853,12 @@ def create_polythink_interface():
|
|
| 995 |
-webkit-background-clip: text;
|
| 996 |
-webkit-text-fill-color: transparent;
|
| 997 |
display: inline-block;
|
| 998 |
-
position: relative;
|
| 999 |
}
|
| 1000 |
|
| 1001 |
.app-subtitle {
|
| 1002 |
font-size: 16px;
|
| 1003 |
color: #aaaaaa;
|
| 1004 |
margin: 0;
|
| 1005 |
-
position: relative;
|
| 1006 |
}
|
| 1007 |
|
| 1008 |
/* Button style */
|
|
@@ -1021,194 +877,6 @@ def create_polythink_interface():
|
|
| 1021 |
box-shadow: 0 6px 15px rgba(0, 0, 0, 0.4) !important;
|
| 1022 |
background: linear-gradient(45deg, #666666, #888888) !important;
|
| 1023 |
}
|
| 1024 |
-
|
| 1025 |
-
/* Mobile Responsiveness */
|
| 1026 |
-
@media (max-width: 768px) {
|
| 1027 |
-
.solutions-container {
|
| 1028 |
-
flex-direction: column;
|
| 1029 |
-
}
|
| 1030 |
-
|
| 1031 |
-
.solution-item {
|
| 1032 |
-
min-width: 100%;
|
| 1033 |
-
margin-bottom: 10px;
|
| 1034 |
-
}
|
| 1035 |
-
|
| 1036 |
-
.app-title {
|
| 1037 |
-
font-size: 24px;
|
| 1038 |
-
}
|
| 1039 |
-
|
| 1040 |
-
.app-subtitle {
|
| 1041 |
-
font-size: 14px;
|
| 1042 |
-
}
|
| 1043 |
-
|
| 1044 |
-
.timeline-item {
|
| 1045 |
-
flex-direction: column;
|
| 1046 |
-
}
|
| 1047 |
-
|
| 1048 |
-
.timeline-marker {
|
| 1049 |
-
margin-bottom: 10px;
|
| 1050 |
-
}
|
| 1051 |
-
}
|
| 1052 |
-
|
| 1053 |
-
/* Solution Controls */
|
| 1054 |
-
.solution-controls {
|
| 1055 |
-
display: flex;
|
| 1056 |
-
gap: 8px;
|
| 1057 |
-
}
|
| 1058 |
-
|
| 1059 |
-
.copy-btn, .toggle-btn {
|
| 1060 |
-
background: none;
|
| 1061 |
-
border: none;
|
| 1062 |
-
color: #bbbbbb;
|
| 1063 |
-
cursor: pointer;
|
| 1064 |
-
padding: 4px 8px;
|
| 1065 |
-
border-radius: 4px;
|
| 1066 |
-
transition: all 0.2s ease;
|
| 1067 |
-
font-size: 1.1em;
|
| 1068 |
-
}
|
| 1069 |
-
|
| 1070 |
-
.copy-btn:hover, .toggle-btn:hover {
|
| 1071 |
-
background: rgba(255, 255, 255, 0.1);
|
| 1072 |
-
color: #ffffff;
|
| 1073 |
-
}
|
| 1074 |
-
|
| 1075 |
-
.copy-btn:active, .toggle-btn:active {
|
| 1076 |
-
transform: scale(0.95);
|
| 1077 |
-
}
|
| 1078 |
-
|
| 1079 |
-
/* Solution Item Enhancements */
|
| 1080 |
-
.solution-item {
|
| 1081 |
-
position: relative;
|
| 1082 |
-
overflow: hidden;
|
| 1083 |
-
}
|
| 1084 |
-
|
| 1085 |
-
.solution-item::before {
|
| 1086 |
-
content: '';
|
| 1087 |
-
position: absolute;
|
| 1088 |
-
top: 0;
|
| 1089 |
-
left: 0;
|
| 1090 |
-
width: 4px;
|
| 1091 |
-
height: 100%;
|
| 1092 |
-
background: linear-gradient(to bottom, #4CAF50, #2196F3);
|
| 1093 |
-
opacity: 0.5;
|
| 1094 |
-
}
|
| 1095 |
-
|
| 1096 |
-
.solution-body {
|
| 1097 |
-
padding: 15px;
|
| 1098 |
-
background: rgba(0, 0, 0, 0.2);
|
| 1099 |
-
border-top: 1px solid rgba(255, 255, 255, 0.1);
|
| 1100 |
-
transition: all 0.3s ease;
|
| 1101 |
-
}
|
| 1102 |
-
|
| 1103 |
-
/* Loading States */
|
| 1104 |
-
.loading-skeleton {
|
| 1105 |
-
background: linear-gradient(90deg, var(--card-bg) 25%, var(--border-color) 50%, var(--card-bg) 75%);
|
| 1106 |
-
background-size: 200% 100%;
|
| 1107 |
-
animation: loading 1.5s infinite;
|
| 1108 |
-
border-radius: 8px;
|
| 1109 |
-
margin: 10px 0;
|
| 1110 |
-
}
|
| 1111 |
-
|
| 1112 |
-
@keyframes loading {
|
| 1113 |
-
0% { background-position: 200% 0; }
|
| 1114 |
-
100% { background-position: -200% 0; }
|
| 1115 |
-
}
|
| 1116 |
-
|
| 1117 |
-
/* Error States */
|
| 1118 |
-
.error-message {
|
| 1119 |
-
background: rgba(255, 59, 48, 0.1);
|
| 1120 |
-
border: 1px solid rgba(255, 59, 48, 0.2);
|
| 1121 |
-
border-radius: 8px;
|
| 1122 |
-
padding: 15px;
|
| 1123 |
-
margin: 10px 0;
|
| 1124 |
-
color: #ff3b30;
|
| 1125 |
-
font-size: 14px;
|
| 1126 |
-
line-height: 1.5;
|
| 1127 |
-
}
|
| 1128 |
-
|
| 1129 |
-
.error-message::before {
|
| 1130 |
-
content: "⚠️";
|
| 1131 |
-
margin-right: 8px;
|
| 1132 |
-
}
|
| 1133 |
-
|
| 1134 |
-
/* Light Theme Error States */
|
| 1135 |
-
body.light-theme .error-message {
|
| 1136 |
-
background: rgba(255, 59, 48, 0.05);
|
| 1137 |
-
border-color: rgba(255, 59, 48, 0.1);
|
| 1138 |
-
}
|
| 1139 |
-
|
| 1140 |
-
/* Status Bar States */
|
| 1141 |
-
.status-bar {
|
| 1142 |
-
display: flex;
|
| 1143 |
-
align-items: center;
|
| 1144 |
-
gap: 10px;
|
| 1145 |
-
padding: 10px;
|
| 1146 |
-
background: var(--card-bg);
|
| 1147 |
-
border-radius: 8px;
|
| 1148 |
-
margin: 10px 0;
|
| 1149 |
-
font-size: 14px;
|
| 1150 |
-
}
|
| 1151 |
-
|
| 1152 |
-
.status-icon {
|
| 1153 |
-
font-size: 16px;
|
| 1154 |
-
}
|
| 1155 |
-
|
| 1156 |
-
.status-message {
|
| 1157 |
-
flex: 1;
|
| 1158 |
-
color: var(--text-color);
|
| 1159 |
-
}
|
| 1160 |
-
|
| 1161 |
-
.status-stage {
|
| 1162 |
-
padding: 4px 8px;
|
| 1163 |
-
border-radius: 4px;
|
| 1164 |
-
font-size: 12px;
|
| 1165 |
-
background: var(--border-color);
|
| 1166 |
-
color: var(--text-color);
|
| 1167 |
-
opacity: 0.7;
|
| 1168 |
-
}
|
| 1169 |
-
|
| 1170 |
-
.status-stage.active {
|
| 1171 |
-
background: var(--primary-color);
|
| 1172 |
-
color: white;
|
| 1173 |
-
opacity: 1;
|
| 1174 |
-
}
|
| 1175 |
-
|
| 1176 |
-
.status-stage.completed {
|
| 1177 |
-
background: var(--success-color);
|
| 1178 |
-
color: white;
|
| 1179 |
-
opacity: 1;
|
| 1180 |
-
}
|
| 1181 |
-
|
| 1182 |
-
.status-progress {
|
| 1183 |
-
height: 4px;
|
| 1184 |
-
background: var(--primary-color);
|
| 1185 |
-
border-radius: 2px;
|
| 1186 |
-
transition: width 0.3s ease;
|
| 1187 |
-
}
|
| 1188 |
-
|
| 1189 |
-
/* Light Theme Status Bar */
|
| 1190 |
-
body.light-theme .status-bar {
|
| 1191 |
-
background: white;
|
| 1192 |
-
border: 1px solid var(--border-color);
|
| 1193 |
-
}
|
| 1194 |
-
|
| 1195 |
-
body.light-theme .status-stage {
|
| 1196 |
-
background: #f0f0f0;
|
| 1197 |
-
}
|
| 1198 |
-
|
| 1199 |
-
/* Mobile Responsive Status Bar */
|
| 1200 |
-
@media (max-width: 768px) {
|
| 1201 |
-
.status-bar {
|
| 1202 |
-
flex-direction: column;
|
| 1203 |
-
align-items: flex-start;
|
| 1204 |
-
gap: 5px;
|
| 1205 |
-
}
|
| 1206 |
-
|
| 1207 |
-
.status-stage {
|
| 1208 |
-
font-size: 10px;
|
| 1209 |
-
padding: 2px 4px;
|
| 1210 |
-
}
|
| 1211 |
-
}
|
| 1212 |
"""
|
| 1213 |
|
| 1214 |
# Hardcoded model configurations
|
|
@@ -1231,563 +899,164 @@ def create_polythink_interface():
|
|
| 1231 |
}
|
| 1232 |
|
| 1233 |
async def solve_problem(problem: str, max_rounds: int):
|
| 1234 |
-
|
| 1235 |
-
|
| 1236 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1237 |
|
| 1238 |
-
|
| 1239 |
-
|
| 1240 |
-
|
| 1241 |
-
|
| 1242 |
-
|
| 1243 |
-
|
| 1244 |
-
|
| 1245 |
-
|
| 1246 |
-
|
| 1247 |
-
|
| 1248 |
-
# Gemini client
|
| 1249 |
-
gemini_key = os.getenv("GEMINI_API_KEY")
|
| 1250 |
-
if gemini_key:
|
| 1251 |
-
genai.configure(api_key=gemini_key)
|
| 1252 |
-
api_clients["gemini"] = genai
|
| 1253 |
-
|
| 1254 |
-
# Check if all required API keys are present
|
| 1255 |
-
required_providers = {solver1_config["provider"], solver2_config["provider"], judge_config["provider"]}
|
| 1256 |
-
missing_keys = [p for p in required_providers if p not in api_clients]
|
| 1257 |
-
if missing_keys:
|
| 1258 |
-
yield [
|
| 1259 |
-
gr.update(value=f"""
|
| 1260 |
-
<div class="error-message">
|
| 1261 |
-
Missing API keys for {', '.join(missing_keys)}. Please check your environment variables.
|
| 1262 |
-
</div>
|
| 1263 |
-
""", visible=True),
|
| 1264 |
-
*[gr.update(visible=False) for _ in range(6)],
|
| 1265 |
-
gr.update(visible=False),
|
| 1266 |
-
gr.update(value=f"""
|
| 1267 |
-
<div class="status-bar">
|
| 1268 |
-
<span class="status-icon">❌</span>
|
| 1269 |
-
<span class="status-message">Missing API keys for {', '.join(missing_keys)}</span>
|
| 1270 |
-
<div class="status-progress" style="width: 0%"></div>
|
| 1271 |
-
</div>
|
| 1272 |
-
""", visible=True),
|
| 1273 |
-
gr.update(visible=False)
|
| 1274 |
-
]
|
| 1275 |
-
return
|
| 1276 |
|
| 1277 |
-
|
|
|
|
|
|
|
|
|
|
| 1278 |
yield [
|
| 1279 |
-
gr.update(value=""
|
| 1280 |
-
<div class="loading-skeleton" style="height: 100px;"></div>
|
| 1281 |
-
""", visible=True),
|
| 1282 |
-
*[gr.update(visible=False) for _ in range(6)],
|
| 1283 |
gr.update(visible=False),
|
| 1284 |
-
gr.update(
|
| 1285 |
-
|
| 1286 |
-
|
| 1287 |
-
|
| 1288 |
-
|
| 1289 |
-
|
| 1290 |
-
""
|
| 1291 |
-
gr.update(visible=False)
|
| 1292 |
]
|
|
|
|
| 1293 |
|
| 1294 |
-
|
| 1295 |
|
| 1296 |
-
|
| 1297 |
-
|
| 1298 |
-
|
| 1299 |
-
|
| 1300 |
-
|
| 1301 |
-
|
| 1302 |
-
|
| 1303 |
-
|
| 1304 |
-
|
| 1305 |
-
|
| 1306 |
-
|
| 1307 |
-
|
| 1308 |
-
|
| 1309 |
-
|
| 1310 |
-
gr.update(visible=False)
|
| 1311 |
-
]
|
| 1312 |
|
| 1313 |
-
|
| 1314 |
-
|
| 1315 |
-
|
| 1316 |
-
|
| 1317 |
-
gr.update(value=f"""
|
| 1318 |
-
<div class="error-message">
|
| 1319 |
-
Error generating initial solutions: {str(e)}
|
| 1320 |
-
<br><br>
|
| 1321 |
-
This appears to be a server-side issue with the AI APIs. Please try again later.
|
| 1322 |
-
</div>
|
| 1323 |
-
""", visible=True),
|
| 1324 |
-
*[gr.update(visible=False) for _ in range(6)],
|
| 1325 |
-
gr.update(visible=False),
|
| 1326 |
-
gr.update(value=f"""
|
| 1327 |
-
<div class="status-bar">
|
| 1328 |
-
<span class="status-icon">❌</span>
|
| 1329 |
-
<span class="status-message">Error: Failed to generate initial solutions</span>
|
| 1330 |
-
<div class="status-progress" style="width: 0%"></div>
|
| 1331 |
-
</div>
|
| 1332 |
-
""", visible=True),
|
| 1333 |
-
gr.update(visible=False)
|
| 1334 |
-
]
|
| 1335 |
-
return
|
| 1336 |
|
| 1337 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1338 |
|
| 1339 |
-
# Show initial solutions
|
| 1340 |
yield [
|
| 1341 |
gr.update(value=initial_content, visible=True),
|
| 1342 |
-
|
| 1343 |
-
gr.update(visible=
|
| 1344 |
-
gr.update(value=
|
| 1345 |
-
|
| 1346 |
-
|
| 1347 |
-
|
| 1348 |
-
|
| 1349 |
-
|
| 1350 |
-
</div>
|
| 1351 |
-
""", visible=True),
|
| 1352 |
-
gr.update(visible=True)
|
| 1353 |
]
|
| 1354 |
await asyncio.sleep(1)
|
| 1355 |
|
| 1356 |
-
|
| 1357 |
-
|
| 1358 |
-
round_outputs = [""] * 6
|
| 1359 |
-
|
| 1360 |
-
for round_num in range(int(max_rounds)):
|
| 1361 |
-
# Show loading state for judgment
|
| 1362 |
-
yield [
|
| 1363 |
-
gr.update(value=initial_content, visible=True),
|
| 1364 |
-
*[gr.update(value=output, visible=bool(output)) for output in round_outputs],
|
| 1365 |
-
gr.update(visible=False),
|
| 1366 |
-
gr.update(value=f"""
|
| 1367 |
-
<div class="status-bar">
|
| 1368 |
-
<span class="status-icon">⚖️</span>
|
| 1369 |
-
<span class="status-message">Evaluating solutions (Round {round_num + 1})...</span>
|
| 1370 |
-
<span class="status-stage completed">Initial Solutions</span>
|
| 1371 |
-
<span class="status-stage active">Judgment {round_num + 1}</span>
|
| 1372 |
-
<div class="status-progress" style="width: {(round_num * 2 + 1) / (int(max_rounds) * 2) * 100}%"></div>
|
| 1373 |
-
</div>
|
| 1374 |
-
""", visible=True),
|
| 1375 |
-
gr.update(visible=True)
|
| 1376 |
-
]
|
| 1377 |
-
|
| 1378 |
-
try:
|
| 1379 |
-
judgment = await orchestrator.get_judgment(problem, solutions)
|
| 1380 |
-
except Exception as e:
|
| 1381 |
-
yield [
|
| 1382 |
-
gr.update(value=initial_content, visible=True),
|
| 1383 |
-
*[gr.update(value=output, visible=bool(output)) for output in round_outputs],
|
| 1384 |
-
gr.update(visible=False),
|
| 1385 |
-
gr.update(value=f"""
|
| 1386 |
-
<div class="status-bar">
|
| 1387 |
-
<span class="status-icon">❌</span>
|
| 1388 |
-
<span class="status-message">Error: Failed to evaluate solutions</span>
|
| 1389 |
-
<div class="status-progress" style="width: {(round_num * 2 + 1) / (int(max_rounds) * 2) * 100}%"></div>
|
| 1390 |
-
</div>
|
| 1391 |
-
""", visible=True),
|
| 1392 |
-
gr.update(visible=True)
|
| 1393 |
-
]
|
| 1394 |
-
return
|
| 1395 |
-
|
| 1396 |
-
history.append({"judgment": judgment["judgment"]})
|
| 1397 |
-
|
| 1398 |
-
is_agreement = "AGREEMENT: YES" in judgment["judgment"].upper()
|
| 1399 |
-
agreement_class = "agreement" if is_agreement else "disagreement"
|
| 1400 |
-
agreement_icon = "✅" if is_agreement else "❌"
|
| 1401 |
-
|
| 1402 |
-
judgment_content = f"## Round {round_num + 1} Judgment\n**Evaluation:** <div class='{agreement_class}'>{agreement_icon} {judgment['judgment']}</div>"
|
| 1403 |
-
round_outputs[round_num * 2] = judgment_content
|
| 1404 |
-
|
| 1405 |
-
progress = (round_num * 2 + 1) / (int(max_rounds) * 2) * 100
|
| 1406 |
-
|
| 1407 |
-
# Show judgment
|
| 1408 |
-
yield [
|
| 1409 |
-
gr.update(value=initial_content, visible=True),
|
| 1410 |
-
*[gr.update(value=output, visible=bool(output)) for output in round_outputs],
|
| 1411 |
-
gr.update(visible=False),
|
| 1412 |
-
gr.update(value=f"""
|
| 1413 |
-
<div class="status-bar">
|
| 1414 |
-
<span class="status-icon">🔍</span>
|
| 1415 |
-
<span class="status-message">Round {round_num + 1} judgment complete</span>
|
| 1416 |
-
<span class="status-stage completed">Initial Solutions</span>
|
| 1417 |
-
<span class="status-stage completed">Judgment {round_num + 1}</span>
|
| 1418 |
-
<div class="status-progress" style="width: {progress}%"></div>
|
| 1419 |
-
</div>
|
| 1420 |
-
""", visible=True),
|
| 1421 |
-
gr.update(visible=True)
|
| 1422 |
-
]
|
| 1423 |
-
await asyncio.sleep(1)
|
| 1424 |
-
|
| 1425 |
-
if not judgment["reprompt_needed"]:
|
| 1426 |
-
break
|
| 1427 |
-
|
| 1428 |
-
# Show loading state for revised solutions
|
| 1429 |
-
yield [
|
| 1430 |
-
gr.update(value=initial_content, visible=True),
|
| 1431 |
-
*[gr.update(value=output, visible=bool(output)) for output in round_outputs],
|
| 1432 |
-
gr.update(visible=False),
|
| 1433 |
-
gr.update(value=f"""
|
| 1434 |
-
<div class="status-bar">
|
| 1435 |
-
<span class="status-icon">🔄</span>
|
| 1436 |
-
<span class="status-message">Generating revised solutions (Round {round_num + 1})...</span>
|
| 1437 |
-
<span class="status-stage completed">Initial Solutions</span>
|
| 1438 |
-
<span class="status-stage completed">Judgment {round_num + 1}</span>
|
| 1439 |
-
<span class="status-stage active">Revision {round_num + 1}</span>
|
| 1440 |
-
<div class="status-progress" style="width: {progress}%"></div>
|
| 1441 |
-
</div>
|
| 1442 |
-
""", visible=True),
|
| 1443 |
-
gr.update(visible=True)
|
| 1444 |
-
]
|
| 1445 |
-
|
| 1446 |
-
try:
|
| 1447 |
-
revised_solutions = await orchestrator.get_revised_solutions(problem, solutions, judgment["judgment"])
|
| 1448 |
-
except Exception as e:
|
| 1449 |
-
yield [
|
| 1450 |
-
gr.update(value=initial_content, visible=True),
|
| 1451 |
-
*[gr.update(value=output, visible=bool(output)) for output in round_outputs],
|
| 1452 |
-
gr.update(visible=False),
|
| 1453 |
-
gr.update(value=f"""
|
| 1454 |
-
<div class="status-bar">
|
| 1455 |
-
<span class="status-icon">❌</span>
|
| 1456 |
-
<span class="status-message">Error: Failed to generate revised solutions</span>
|
| 1457 |
-
<div class="status-progress" style="width: {progress}%"></div>
|
| 1458 |
-
</div>
|
| 1459 |
-
""", visible=True),
|
| 1460 |
-
gr.update(visible=True)
|
| 1461 |
-
]
|
| 1462 |
-
return
|
| 1463 |
-
|
| 1464 |
-
history.append({"solutions": revised_solutions})
|
| 1465 |
-
revision_content = f"## Round {round_num + 1} Revised Solutions\n**Revised Solutions:**\n- **{revised_solutions[0]['model_name']}**: {revised_solutions[0]['solution']}\n- **{revised_solutions[1]['model_name']}**: {revised_solutions[1]['solution']}"
|
| 1466 |
-
round_outputs[round_num * 2 + 1] = revision_content
|
| 1467 |
-
|
| 1468 |
-
progress = (round_num * 2 + 2) / (int(max_rounds) * 2) * 100
|
| 1469 |
-
|
| 1470 |
-
# Show revised solutions
|
| 1471 |
-
yield [
|
| 1472 |
-
gr.update(value=initial_content, visible=True),
|
| 1473 |
-
*[gr.update(value=output, visible=bool(output)) for output in round_outputs],
|
| 1474 |
-
gr.update(visible=False),
|
| 1475 |
-
gr.update(value=f"""
|
| 1476 |
-
<div class="status-bar">
|
| 1477 |
-
<span class="status-icon">🔄</span>
|
| 1478 |
-
<span class="status-message">Round {round_num + 1} revised solutions generated</span>
|
| 1479 |
-
<span class="status-stage completed">Initial Solutions</span>
|
| 1480 |
-
<span class="status-stage completed">Judgment {round_num + 1}</span>
|
| 1481 |
-
<span class="status-stage completed">Revision {round_num + 1}</span>
|
| 1482 |
-
<div class="status-progress" style="width: {progress}%"></div>
|
| 1483 |
-
</div>
|
| 1484 |
-
""", visible=True),
|
| 1485 |
-
gr.update(visible=True)
|
| 1486 |
-
]
|
| 1487 |
-
await asyncio.sleep(1)
|
| 1488 |
-
solutions = revised_solutions
|
| 1489 |
-
|
| 1490 |
-
# Show loading state for final report
|
| 1491 |
-
yield [
|
| 1492 |
-
gr.update(value=initial_content, visible=True),
|
| 1493 |
-
*[gr.update(value=output, visible=bool(output)) for output in round_outputs],
|
| 1494 |
-
gr.update(value="""
|
| 1495 |
-
<div class="loading-skeleton" style="height: 200px;"></div>
|
| 1496 |
-
""", visible=True),
|
| 1497 |
-
gr.update(value=f"""
|
| 1498 |
-
<div class="status-bar">
|
| 1499 |
-
<span class="status-icon">📊</span>
|
| 1500 |
-
<span class="status-message">Generating final report...</span>
|
| 1501 |
-
<span class="status-stage completed">Initial Solutions</span>
|
| 1502 |
-
<span class="status-stage completed">All Judgments</span>
|
| 1503 |
-
<span class="status-stage completed">All Revisions</span>
|
| 1504 |
-
<div class="status-progress" style="width: 95%"></div>
|
| 1505 |
-
</div>
|
| 1506 |
-
""", visible=True),
|
| 1507 |
-
gr.update(visible=True)
|
| 1508 |
-
]
|
| 1509 |
|
| 1510 |
-
|
| 1511 |
-
|
| 1512 |
-
|
|
|
|
| 1513 |
yield [
|
| 1514 |
gr.update(value=initial_content, visible=True),
|
| 1515 |
-
|
| 1516 |
-
gr.update(value=
|
| 1517 |
-
gr.update(value=
|
| 1518 |
-
|
| 1519 |
-
|
| 1520 |
-
|
| 1521 |
-
|
| 1522 |
-
|
| 1523 |
-
<span class="status-stage completed">All Revisions</span>
|
| 1524 |
-
<div class="status-progress" style="width: 100%"></div>
|
| 1525 |
-
</div>
|
| 1526 |
-
""", visible=True),
|
| 1527 |
-
gr.update(visible=True)
|
| 1528 |
-
]
|
| 1529 |
-
|
| 1530 |
-
except Exception as e:
|
| 1531 |
-
yield [
|
| 1532 |
-
gr.update(value=f"""
|
| 1533 |
-
<div class="error-message">
|
| 1534 |
-
An unexpected error occurred: {str(e)}
|
| 1535 |
-
<br><br>
|
| 1536 |
-
This appears to be a server-side issue with the AI APIs. Please try again later.
|
| 1537 |
-
</div>
|
| 1538 |
-
""", visible=True),
|
| 1539 |
-
*[gr.update(visible=False) for _ in range(6)],
|
| 1540 |
-
gr.update(visible=False),
|
| 1541 |
-
gr.update(value=f"""
|
| 1542 |
-
<div class="status-bar">
|
| 1543 |
-
<span class="status-icon">❌</span>
|
| 1544 |
-
<span class="status-message">Error: An unexpected error occurred</span>
|
| 1545 |
-
<div class="status-progress" style="width: 0%"></div>
|
| 1546 |
-
</div>
|
| 1547 |
-
""", visible=True),
|
| 1548 |
-
gr.update(visible=False)
|
| 1549 |
]
|
|
|
|
|
|
|
| 1550 |
|
| 1551 |
-
|
| 1552 |
-
|
| 1553 |
-
|
| 1554 |
-
|
| 1555 |
-
|
| 1556 |
-
|
| 1557 |
-
|
| 1558 |
-
|
| 1559 |
-
|
| 1560 |
-
|
| 1561 |
-
|
| 1562 |
-
|
| 1563 |
-
{report}
|
| 1564 |
-
"""
|
| 1565 |
-
|
| 1566 |
-
# Create a download link
|
| 1567 |
-
html = f"""
|
| 1568 |
-
<a href="data:text/plain;charset=utf-8,{content}"
|
| 1569 |
-
download="{filename}"
|
| 1570 |
-
style="display: none;"
|
| 1571 |
-
id="download-link">
|
| 1572 |
-
</a>
|
| 1573 |
-
<script>
|
| 1574 |
-
document.getElementById('download-link').click();
|
| 1575 |
-
</script>
|
| 1576 |
-
"""
|
| 1577 |
-
|
| 1578 |
-
return gr.update(value=html, visible=True)
|
| 1579 |
-
|
| 1580 |
-
def share_results(problem: str, report: str) -> None:
|
| 1581 |
-
"""Share the problem-solving results."""
|
| 1582 |
-
# Create a shareable text
|
| 1583 |
-
share_text = f"""Check out this problem-solving result from PolyThink!
|
| 1584 |
-
|
| 1585 |
-
Problem: {problem}
|
| 1586 |
-
|
| 1587 |
-
{report}
|
| 1588 |
-
|
| 1589 |
-
Generated with PolyThink Alpha
|
| 1590 |
-
"""
|
| 1591 |
-
|
| 1592 |
-
# Try to use the Web Share API if available
|
| 1593 |
-
html = f"""
|
| 1594 |
-
<script>
|
| 1595 |
-
if (navigator.share) {{
|
| 1596 |
-
navigator.share({{
|
| 1597 |
-
title: 'PolyThink Problem Solving Result',
|
| 1598 |
-
text: `{share_text}`,
|
| 1599 |
-
}}).catch(console.error);
|
| 1600 |
-
}} else {{
|
| 1601 |
-
// Fallback to copying to clipboard
|
| 1602 |
-
navigator.clipboard.writeText(`{share_text}`).then(() => {{
|
| 1603 |
-
alert('Results copied to clipboard!');
|
| 1604 |
-
}}).catch(console.error);
|
| 1605 |
-
}}
|
| 1606 |
-
</script>
|
| 1607 |
-
"""
|
| 1608 |
-
|
| 1609 |
-
return gr.update(value=html, visible=True)
|
| 1610 |
|
| 1611 |
-
with gr.Blocks(title="PolyThink Alpha", css=
|
| 1612 |
with gr.Column(elem_classes=["app-header"]):
|
| 1613 |
gr.Markdown("<h1 class='app-title'>PolyThink Alpha</h1>", show_label=False)
|
| 1614 |
gr.Markdown("<p class='app-subtitle'>Multi-Agent Problem Solving System</p>", show_label=False)
|
| 1615 |
-
|
| 1616 |
-
with gr.Row(elem_classes=["header-controls"]):
|
| 1617 |
-
gr.Button("🌙 Theme", elem_classes=["theme-toggle"], show_label=False)
|
| 1618 |
-
gr.Button("❓ Help", elem_classes=["help-button"], show_label=False)
|
| 1619 |
|
| 1620 |
with gr.Row():
|
| 1621 |
with gr.Column(scale=2):
|
| 1622 |
gr.Markdown("### Problem Input")
|
| 1623 |
-
problem_input = gr.Textbox(
|
| 1624 |
-
|
| 1625 |
-
|
| 1626 |
-
lines=5,
|
| 1627 |
-
elem_classes=["problem-input"]
|
| 1628 |
-
)
|
| 1629 |
-
|
| 1630 |
-
with gr.Row():
|
| 1631 |
-
max_rounds = gr.Slider(
|
| 1632 |
-
minimum=1,
|
| 1633 |
-
maximum=5,
|
| 1634 |
-
value=3,
|
| 1635 |
-
step=1,
|
| 1636 |
-
label="Maximum Rounds",
|
| 1637 |
-
elem_classes=["rounds-slider"]
|
| 1638 |
-
)
|
| 1639 |
-
solve_btn = gr.Button("Solve", variant="primary", elem_classes=["solve-button"])
|
| 1640 |
-
|
| 1641 |
-
status_bar = gr.HTML(
|
| 1642 |
-
value="",
|
| 1643 |
-
elem_classes=["status-bar"],
|
| 1644 |
-
visible=False
|
| 1645 |
-
)
|
| 1646 |
-
|
| 1647 |
-
with gr.Column(scale=3):
|
| 1648 |
-
with gr.Tabs() as output_tabs:
|
| 1649 |
-
with gr.TabItem("Process", elem_classes=["process-tab"]):
|
| 1650 |
-
initial_solutions = gr.Markdown(visible=False)
|
| 1651 |
-
round_outputs = [gr.Markdown(visible=False) for _ in range(6)]
|
| 1652 |
-
|
| 1653 |
-
with gr.TabItem("Final Report", elem_classes=["report-tab"]):
|
| 1654 |
-
final_report = gr.Markdown(visible=False)
|
| 1655 |
-
|
| 1656 |
-
with gr.Row(elem_classes=["action-buttons"], visible=False) as action_buttons:
|
| 1657 |
-
export_btn = gr.Button("Export Report", elem_classes=["action-button"])
|
| 1658 |
-
share_btn = gr.Button("Share Results", elem_classes=["action-button"])
|
| 1659 |
-
|
| 1660 |
-
def toggle_theme():
|
| 1661 |
-
return """
|
| 1662 |
-
<script>
|
| 1663 |
-
function toggleTheme() {
|
| 1664 |
-
document.body.classList.toggle('light-theme');
|
| 1665 |
-
const themeBtn = document.querySelector('.theme-toggle');
|
| 1666 |
-
themeBtn.textContent = document.body.classList.contains('light-theme') ? '🌞 Theme' : '🌙 Theme';
|
| 1667 |
-
|
| 1668 |
-
// Save theme preference
|
| 1669 |
-
localStorage.setItem('theme', document.body.classList.contains('light-theme') ? 'light' : 'dark');
|
| 1670 |
-
}
|
| 1671 |
-
|
| 1672 |
-
// Load saved theme preference
|
| 1673 |
-
const savedTheme = localStorage.getItem('theme');
|
| 1674 |
-
if (savedTheme === 'light') {
|
| 1675 |
-
document.body.classList.add('light-theme');
|
| 1676 |
-
document.querySelector('.theme-toggle').textContent = '🌞 Theme';
|
| 1677 |
-
}
|
| 1678 |
-
|
| 1679 |
-
document.querySelector('.theme-toggle').onclick = toggleTheme;
|
| 1680 |
-
</script>
|
| 1681 |
-
"""
|
| 1682 |
|
| 1683 |
-
|
| 1684 |
-
return """
|
| 1685 |
-
<script>
|
| 1686 |
-
function showHelp() {
|
| 1687 |
-
const modal = document.createElement('div');
|
| 1688 |
-
modal.className = 'help-modal';
|
| 1689 |
-
modal.innerHTML = `
|
| 1690 |
-
<h3>How to Use PolyThink Alpha</h3>
|
| 1691 |
-
<ol>
|
| 1692 |
-
<li>Enter your problem in the input box</li>
|
| 1693 |
-
<li>Adjust the maximum number of rounds if needed</li>
|
| 1694 |
-
<li>Click "Solve Problem" to start the process</li>
|
| 1695 |
-
<li>Watch as the AI team works together to solve your problem</li>
|
| 1696 |
-
<li>Review the final report and export/share if desired</li>
|
| 1697 |
-
</ol>
|
| 1698 |
-
<p>Note: The AI team consists of:</p>
|
| 1699 |
-
<ul>
|
| 1700 |
-
<li>Solver 1: Cohere Command R</li>
|
| 1701 |
-
<li>Solver 2: Llama 3.2 3B Instruct</li>
|
| 1702 |
-
<li>Judge: Gemini 2.0 Flash Thinking Experimental 01-21</li>
|
| 1703 |
-
</ul>
|
| 1704 |
-
<button onclick="closeHelp()" style="
|
| 1705 |
-
background: linear-gradient(45deg, #2196F3, #4CAF50);
|
| 1706 |
-
color: white;
|
| 1707 |
-
border: none;
|
| 1708 |
-
padding: 10px 20px;
|
| 1709 |
-
border-radius: 5px;
|
| 1710 |
-
cursor: pointer;
|
| 1711 |
-
margin-top: 20px;
|
| 1712 |
-
">Close</button>
|
| 1713 |
-
`;
|
| 1714 |
-
|
| 1715 |
-
const overlay = document.createElement('div');
|
| 1716 |
-
overlay.className = 'modal-overlay';
|
| 1717 |
-
|
| 1718 |
-
document.body.appendChild(overlay);
|
| 1719 |
-
document.body.appendChild(modal);
|
| 1720 |
-
|
| 1721 |
-
// Show with animation
|
| 1722 |
-
setTimeout(() => {
|
| 1723 |
-
overlay.classList.add('active');
|
| 1724 |
-
modal.classList.add('active');
|
| 1725 |
-
}, 10);
|
| 1726 |
-
}
|
| 1727 |
-
|
| 1728 |
-
function closeHelp() {
|
| 1729 |
-
const modal = document.querySelector('.help-modal');
|
| 1730 |
-
const overlay = document.querySelector('.modal-overlay');
|
| 1731 |
-
|
| 1732 |
-
modal.classList.remove('active');
|
| 1733 |
-
overlay.classList.remove('active');
|
| 1734 |
-
|
| 1735 |
-
setTimeout(() => {
|
| 1736 |
-
modal.remove();
|
| 1737 |
-
overlay.remove();
|
| 1738 |
-
}, 300);
|
| 1739 |
-
}
|
| 1740 |
-
|
| 1741 |
-
document.querySelector('.help-button').onclick = showHelp;
|
| 1742 |
-
|
| 1743 |
-
// Close modal when clicking overlay
|
| 1744 |
-
document.addEventListener('click', (e) => {
|
| 1745 |
-
if (e.target.classList.contains('modal-overlay')) {
|
| 1746 |
-
closeHelp();
|
| 1747 |
-
}
|
| 1748 |
-
});
|
| 1749 |
-
|
| 1750 |
-
// Close modal with Escape key
|
| 1751 |
-
document.addEventListener('keydown', (e) => {
|
| 1752 |
-
if (e.key === 'Escape') {
|
| 1753 |
-
closeHelp();
|
| 1754 |
-
}
|
| 1755 |
-
});
|
| 1756 |
-
</script>
|
| 1757 |
-
"""
|
| 1758 |
|
| 1759 |
-
|
| 1760 |
-
|
| 1761 |
-
|
| 1762 |
-
|
| 1763 |
-
|
| 1764 |
-
|
| 1765 |
-
|
| 1766 |
-
|
| 1767 |
-
]
|
| 1768 |
-
|
|
|
|
| 1769 |
fn=solve_problem,
|
| 1770 |
-
inputs=[
|
|
|
|
|
|
|
|
|
|
| 1771 |
outputs=[
|
| 1772 |
initial_solutions,
|
| 1773 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1774 |
final_report,
|
| 1775 |
-
|
| 1776 |
-
action_buttons
|
| 1777 |
]
|
| 1778 |
)
|
| 1779 |
-
|
| 1780 |
-
export_btn.click(
|
| 1781 |
-
fn=export_report,
|
| 1782 |
-
inputs=[problem_input, final_report],
|
| 1783 |
-
outputs=None
|
| 1784 |
-
)
|
| 1785 |
-
|
| 1786 |
-
share_btn.click(
|
| 1787 |
-
fn=share_results,
|
| 1788 |
-
inputs=[problem_input, final_report],
|
| 1789 |
-
outputs=None
|
| 1790 |
-
)
|
| 1791 |
|
| 1792 |
return demo.queue()
|
| 1793 |
|
|
|
|
| 8 |
from anthropic import Anthropic
|
| 9 |
import openai
|
| 10 |
from typing import List, Dict, Any, Optional
|
|
|
|
| 11 |
|
| 12 |
# Configure logging
|
| 13 |
logging.basicConfig(level=logging.INFO)
|
|
|
|
| 487 |
"""
|
| 488 |
|
| 489 |
for sol in step["solutions"]:
|
|
|
|
|
|
|
| 490 |
report += f"""
|
| 491 |
<div class="solution-item">
|
| 492 |
+
<div class="solution-header">{sol['model_name']}</div>
|
| 493 |
+
<div class="solution-body">{sol['solution']}</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 494 |
</div>
|
| 495 |
"""
|
| 496 |
|
|
|
|
| 529 |
"""
|
| 530 |
|
| 531 |
for sol in step["solutions"]:
|
|
|
|
|
|
|
| 532 |
report += f"""
|
| 533 |
<div class="solution-item">
|
| 534 |
+
<div class="solution-header">{sol['model_name']}</div>
|
| 535 |
+
<div class="solution-body">{sol['solution']}</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 536 |
</div>
|
| 537 |
"""
|
| 538 |
|
|
|
|
| 545 |
last_judgment = next((step.get("judgment", "") for step in reversed(history) if "judgment" in step), "")
|
| 546 |
if "AGREEMENT: YES" in last_judgment.upper():
|
| 547 |
confidence = "100%" if len(history) == 2 else "80%"
|
| 548 |
+
report += f"""
|
| 549 |
+
<div class="conclusion-container agreement">
|
| 550 |
+
<h3>Conclusion</h3>
|
| 551 |
+
<div class="conclusion-content">
|
| 552 |
+
<div class="conclusion-icon">✅</div>
|
| 553 |
+
<div class="conclusion-text">
|
| 554 |
+
<p>Models reached <strong>AGREEMENT</strong></p>
|
| 555 |
+
<p>Confidence level: <strong>{confidence}</strong></p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 556 |
</div>
|
| 557 |
</div>
|
| 558 |
+
</div>
|
| 559 |
+
"""
|
| 560 |
else:
|
| 561 |
report += f"""
|
| 562 |
<div class="conclusion-container disagreement">
|
|
|
|
| 574 |
report += """
|
| 575 |
</div>
|
| 576 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 577 |
"""
|
| 578 |
|
| 579 |
return report
|
| 580 |
|
| 581 |
# --- Gradio Interface ---
|
| 582 |
def create_polythink_interface():
|
| 583 |
+
custom_css = """
|
| 584 |
/* Reverted to Original Black Theme */
|
| 585 |
body {
|
| 586 |
background: #000000;
|
|
|
|
| 644 |
.step-section strong {
|
| 645 |
color: #ffffff;
|
| 646 |
}
|
|
|
|
|
|
|
| 647 |
.status-bar {
|
| 648 |
background: #1a1a1a;
|
| 649 |
+
padding: 10px;
|
| 650 |
border-radius: 5px;
|
| 651 |
font-size: 1.1em;
|
| 652 |
margin-bottom: 20px;
|
| 653 |
border-left: 4px solid #666666;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 654 |
}
|
| 655 |
|
| 656 |
/* Agreement/Disagreement styling */
|
|
|
|
| 785 |
border-radius: 5px;
|
| 786 |
overflow: hidden;
|
| 787 |
border: 1px solid #383838;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 788 |
}
|
| 789 |
|
| 790 |
.solution-header {
|
|
|
|
| 793 |
font-weight: bold;
|
| 794 |
color: #dddddd;
|
| 795 |
border-bottom: 1px solid #444444;
|
|
|
|
|
|
|
|
|
|
| 796 |
}
|
| 797 |
|
| 798 |
.solution-body {
|
|
|
|
| 836 |
margin: 5px 0;
|
| 837 |
}
|
| 838 |
|
| 839 |
+
/* Header styling */
|
| 840 |
.app-header {
|
| 841 |
+
background: linear-gradient(45deg, #222222, #333333);
|
|
|
|
|
|
|
| 842 |
padding: 20px;
|
| 843 |
border-radius: 10px;
|
| 844 |
margin-bottom: 20px;
|
| 845 |
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
|
| 846 |
border: 1px solid #444444;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 847 |
}
|
| 848 |
|
| 849 |
.app-title {
|
|
|
|
| 853 |
-webkit-background-clip: text;
|
| 854 |
-webkit-text-fill-color: transparent;
|
| 855 |
display: inline-block;
|
|
|
|
| 856 |
}
|
| 857 |
|
| 858 |
.app-subtitle {
|
| 859 |
font-size: 16px;
|
| 860 |
color: #aaaaaa;
|
| 861 |
margin: 0;
|
|
|
|
| 862 |
}
|
| 863 |
|
| 864 |
/* Button style */
|
|
|
|
| 877 |
box-shadow: 0 6px 15px rgba(0, 0, 0, 0.4) !important;
|
| 878 |
background: linear-gradient(45deg, #666666, #888888) !important;
|
| 879 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 880 |
"""
|
| 881 |
|
| 882 |
# Hardcoded model configurations
|
|
|
|
| 899 |
}
|
| 900 |
|
| 901 |
async def solve_problem(problem: str, max_rounds: int):
|
| 902 |
+
# Get API keys from environment variables
|
| 903 |
+
api_clients = {}
|
| 904 |
+
|
| 905 |
+
# Cohere client
|
| 906 |
+
cohere_key = os.getenv("COHERE_API_KEY")
|
| 907 |
+
if cohere_key:
|
| 908 |
+
api_clients["cohere"] = cohere.Client(cohere_key)
|
| 909 |
|
| 910 |
+
# Hugging Face client
|
| 911 |
+
hf_key = os.getenv("HF_API_KEY")
|
| 912 |
+
if hf_key:
|
| 913 |
+
api_clients["huggingface"] = hf_key
|
| 914 |
+
|
| 915 |
+
# Gemini client
|
| 916 |
+
gemini_key = os.getenv("GEMINI_API_KEY")
|
| 917 |
+
if gemini_key:
|
| 918 |
+
genai.configure(api_key=gemini_key)
|
| 919 |
+
api_clients["gemini"] = genai
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 920 |
|
| 921 |
+
# Check if all required API keys are present
|
| 922 |
+
required_providers = {solver1_config["provider"], solver2_config["provider"], judge_config["provider"]}
|
| 923 |
+
missing_keys = [p for p in required_providers if p not in api_clients]
|
| 924 |
+
if missing_keys:
|
| 925 |
yield [
|
| 926 |
+
gr.update(value=f"Error: Missing API keys for {', '.join(missing_keys)}", visible=True),
|
|
|
|
|
|
|
|
|
|
| 927 |
gr.update(visible=False),
|
| 928 |
+
gr.update(visible=False),
|
| 929 |
+
gr.update(visible=False),
|
| 930 |
+
gr.update(visible=False),
|
| 931 |
+
gr.update(visible=False),
|
| 932 |
+
gr.update(visible=False),
|
| 933 |
+
gr.update(visible=False),
|
| 934 |
+
gr.update(value=f"### Status: ❌ Missing API keys for {', '.join(missing_keys)}", visible=True)
|
|
|
|
| 935 |
]
|
| 936 |
+
return
|
| 937 |
|
| 938 |
+
orchestrator = PolyThinkOrchestrator(solver1_config, solver2_config, judge_config, api_clients)
|
| 939 |
|
| 940 |
+
initial_solutions = await orchestrator.get_initial_solutions(problem)
|
| 941 |
+
initial_content = f"## Initial Solutions\n**Problem:** `{problem}`\n\n**Solutions:**\n- **{initial_solutions[0]['model_name']}**: {initial_solutions[0]['solution']}\n- **{initial_solutions[1]['model_name']}**: {initial_solutions[1]['solution']}"
|
| 942 |
+
yield [
|
| 943 |
+
gr.update(value=initial_content, visible=True),
|
| 944 |
+
gr.update(value="", visible=False),
|
| 945 |
+
gr.update(value="", visible=False),
|
| 946 |
+
gr.update(value="", visible=False),
|
| 947 |
+
gr.update(value="", visible=False),
|
| 948 |
+
gr.update(value="", visible=False),
|
| 949 |
+
gr.update(value="", visible=False),
|
| 950 |
+
gr.update(value="", visible=False),
|
| 951 |
+
gr.update(value="### Status: 📋 Initial solutions generated", visible=True)
|
| 952 |
+
]
|
| 953 |
+
await asyncio.sleep(1)
|
|
|
|
|
|
|
| 954 |
|
| 955 |
+
solutions = initial_solutions
|
| 956 |
+
history = [{"solutions": initial_solutions}]
|
| 957 |
+
max_outputs = max(int(max_rounds) * 2, 6)
|
| 958 |
+
round_outputs = [""] * max_outputs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 959 |
|
| 960 |
+
for round_num in range(int(max_rounds)):
|
| 961 |
+
judgment = await orchestrator.get_judgment(problem, solutions)
|
| 962 |
+
history.append({"judgment": judgment["judgment"]})
|
| 963 |
+
|
| 964 |
+
is_agreement = "AGREEMENT: YES" in judgment["judgment"].upper()
|
| 965 |
+
agreement_class = "agreement" if is_agreement else "disagreement"
|
| 966 |
+
agreement_icon = "✅" if is_agreement else "❌"
|
| 967 |
+
|
| 968 |
+
judgment_content = f"## Round {round_num + 1} Judgment\n**Evaluation:** <div class='{agreement_class}'>{agreement_icon} {judgment['judgment']}</div>"
|
| 969 |
+
round_outputs[round_num * 2] = judgment_content
|
| 970 |
|
|
|
|
| 971 |
yield [
|
| 972 |
gr.update(value=initial_content, visible=True),
|
| 973 |
+
gr.update(value=round_outputs[0], visible=bool(round_outputs[0])),
|
| 974 |
+
gr.update(value=round_outputs[1], visible=bool(round_outputs[1])),
|
| 975 |
+
gr.update(value=round_outputs[2], visible=bool(round_outputs[2])),
|
| 976 |
+
gr.update(value=round_outputs[3], visible=bool(round_outputs[3])),
|
| 977 |
+
gr.update(value=round_outputs[4], visible=bool(round_outputs[4])),
|
| 978 |
+
gr.update(value=round_outputs[5], visible=bool(round_outputs[5])),
|
| 979 |
+
gr.update(value="", visible=False),
|
| 980 |
+
gr.update(value=f"### Status: 🔍 Round {round_num + 1} judgment complete", visible=True)
|
|
|
|
|
|
|
|
|
|
| 981 |
]
|
| 982 |
await asyncio.sleep(1)
|
| 983 |
|
| 984 |
+
if not judgment["reprompt_needed"]:
|
| 985 |
+
break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 986 |
|
| 987 |
+
revised_solutions = await orchestrator.get_revised_solutions(problem, solutions, judgment["judgment"])
|
| 988 |
+
history.append({"solutions": revised_solutions})
|
| 989 |
+
revision_content = f"## Round {round_num + 1} Revised Solutions\n**Revised Solutions:**\n- **{revised_solutions[0]['model_name']}**: {revised_solutions[0]['solution']}\n- **{revised_solutions[1]['model_name']}**: {revised_solutions[1]['solution']}"
|
| 990 |
+
round_outputs[round_num * 2 + 1] = revision_content
|
| 991 |
yield [
|
| 992 |
gr.update(value=initial_content, visible=True),
|
| 993 |
+
gr.update(value=round_outputs[0], visible=bool(round_outputs[0])),
|
| 994 |
+
gr.update(value=round_outputs[1], visible=bool(round_outputs[1])),
|
| 995 |
+
gr.update(value=round_outputs[2], visible=bool(round_outputs[2])),
|
| 996 |
+
gr.update(value=round_outputs[3], visible=bool(round_outputs[3])),
|
| 997 |
+
gr.update(value=round_outputs[4], visible=bool(round_outputs[4])),
|
| 998 |
+
gr.update(value=round_outputs[5], visible=bool(round_outputs[5])),
|
| 999 |
+
gr.update(value="", visible=False),
|
| 1000 |
+
gr.update(value=f"### Status: 🔄 Round {round_num + 1} revised solutions generated", visible=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1001 |
]
|
| 1002 |
+
await asyncio.sleep(1)
|
| 1003 |
+
solutions = revised_solutions
|
| 1004 |
|
| 1005 |
+
final_report_content = orchestrator.generate_final_report(problem, history)
|
| 1006 |
+
yield [
|
| 1007 |
+
gr.update(value=initial_content, visible=True),
|
| 1008 |
+
gr.update(value=round_outputs[0], visible=True),
|
| 1009 |
+
gr.update(value=round_outputs[1], visible=bool(round_outputs[1])),
|
| 1010 |
+
gr.update(value=round_outputs[2], visible=bool(round_outputs[2])),
|
| 1011 |
+
gr.update(value=round_outputs[3], visible=bool(round_outputs[3])),
|
| 1012 |
+
gr.update(value=round_outputs[4], visible=bool(round_outputs[4])),
|
| 1013 |
+
gr.update(value=round_outputs[5], visible=bool(round_outputs[5])),
|
| 1014 |
+
gr.update(value=final_report_content, visible=True),
|
| 1015 |
+
gr.update(value=f"### Status: ✨ Process complete! Completed {round_num + 1} round(s)", visible=True)
|
| 1016 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1017 |
|
| 1018 |
+
with gr.Blocks(title="PolyThink Alpha", css=custom_css) as demo:
|
| 1019 |
with gr.Column(elem_classes=["app-header"]):
|
| 1020 |
gr.Markdown("<h1 class='app-title'>PolyThink Alpha</h1>", show_label=False)
|
| 1021 |
gr.Markdown("<p class='app-subtitle'>Multi-Agent Problem Solving System</p>", show_label=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1022 |
|
| 1023 |
with gr.Row():
|
| 1024 |
with gr.Column(scale=2):
|
| 1025 |
gr.Markdown("### Problem Input")
|
| 1026 |
+
problem_input = gr.Textbox(label="Problem", placeholder="e.g., What is 32 + 63?", lines=3)
|
| 1027 |
+
rounds_slider = gr.Slider(2, 6, value=2, step=1, label="Maximum Rounds")
|
| 1028 |
+
solve_button = gr.Button("Solve Problem", elem_classes=["primary-button"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1029 |
|
| 1030 |
+
status_text = gr.Markdown("### Status: Ready", elem_classes=["status-bar"], visible=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1031 |
|
| 1032 |
+
with gr.Column():
|
| 1033 |
+
initial_solutions = gr.Markdown(elem_classes=["step-section"], visible=False)
|
| 1034 |
+
round_judgment_1 = gr.Markdown(elem_classes=["step-section"], visible=False)
|
| 1035 |
+
revised_solutions_1 = gr.Markdown(elem_classes=["step-section"], visible=False)
|
| 1036 |
+
round_judgment_2 = gr.Markdown(elem_classes=["step-section"], visible=False)
|
| 1037 |
+
revised_solutions_2 = gr.Markdown(elem_classes=["step-section"], visible=False)
|
| 1038 |
+
round_judgment_3 = gr.Markdown(elem_classes=["step-section"], visible=False)
|
| 1039 |
+
revised_solutions_3 = gr.Markdown(elem_classes=["step-section"], visible=False)
|
| 1040 |
+
final_report = gr.HTML(elem_classes=["final-report"], visible=False)
|
| 1041 |
+
|
| 1042 |
+
solve_button.click(
|
| 1043 |
fn=solve_problem,
|
| 1044 |
+
inputs=[
|
| 1045 |
+
problem_input,
|
| 1046 |
+
rounds_slider
|
| 1047 |
+
],
|
| 1048 |
outputs=[
|
| 1049 |
initial_solutions,
|
| 1050 |
+
round_judgment_1,
|
| 1051 |
+
revised_solutions_1,
|
| 1052 |
+
round_judgment_2,
|
| 1053 |
+
revised_solutions_2,
|
| 1054 |
+
round_judgment_3,
|
| 1055 |
+
revised_solutions_3,
|
| 1056 |
final_report,
|
| 1057 |
+
status_text
|
|
|
|
| 1058 |
]
|
| 1059 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1060 |
|
| 1061 |
return demo.queue()
|
| 1062 |
|