KuberMehta commited on
Commit
048c938
·
verified ·
1 Parent(s): 78b0825

Adding a "best answer"

Browse files
Files changed (1) hide show
  1. App.py +77 -1
App.py CHANGED
@@ -8,6 +8,10 @@ import google.generativeai as genai
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)
@@ -472,7 +476,28 @@ class PolyThinkOrchestrator:
472
  <h3 class="problem-title">Problem Statement</h3>
473
  <div class="problem-content">{problem}</div>
474
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
475
 
 
476
  <div class="timeline-container">
477
  """
478
 
@@ -877,6 +902,47 @@ def create_polythink_interface():
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,7 +965,7 @@ def create_polythink_interface():
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
@@ -917,6 +983,16 @@ def create_polythink_interface():
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"]}
 
8
  from anthropic import Anthropic
9
  import openai
10
  from typing import List, Dict, Any, Optional
11
+ from dotenv import load_dotenv
12
+
13
+ # Load environment variables from .env file if it exists
14
+ load_dotenv()
15
 
16
  # Configure logging
17
  logging.basicConfig(level=logging.INFO)
 
476
  <h3 class="problem-title">Problem Statement</h3>
477
  <div class="problem-content">{problem}</div>
478
  </div>
479
+ """
480
+
481
+ # Add best answer section if there's agreement
482
+ last_judgment = next((step.get("judgment", "") for step in reversed(history) if "judgment" in step), "")
483
+ if "AGREEMENT: YES" in last_judgment.upper():
484
+ # Get the last solutions before agreement
485
+ last_solutions = next((step["solutions"] for step in reversed(history) if "solutions" in step), None)
486
+ if last_solutions:
487
+ report += f"""
488
+ <div class="best-answer-container agreement">
489
+ <h3>Best Answer</h3>
490
+ <div class="best-answer-content">
491
+ <div class="best-answer-icon">✨</div>
492
+ <div class="best-answer-text">
493
+ <p><strong>Agreed Solution:</strong> {last_solutions[0]['solution']}</p>
494
+ <p><strong>Models:</strong> {last_solutions[0]['model_name']} & {last_solutions[1]['model_name']}</p>
495
+ </div>
496
+ </div>
497
+ </div>
498
+ """
499
 
500
+ report += """
501
  <div class="timeline-container">
502
  """
503
 
 
902
  box-shadow: 0 6px 15px rgba(0, 0, 0, 0.4) !important;
903
  background: linear-gradient(45deg, #666666, #888888) !important;
904
  }
905
+
906
+ /* Best Answer styling */
907
+ .best-answer-container {
908
+ background: #1a1a1a;
909
+ border-radius: 8px;
910
+ padding: 20px;
911
+ margin: 20px 0;
912
+ box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
913
+ border: 1px solid #4CAF50;
914
+ }
915
+
916
+ .best-answer-container h3 {
917
+ color: #4CAF50;
918
+ margin-top: 0;
919
+ margin-bottom: 15px;
920
+ font-size: 1.5em;
921
+ }
922
+
923
+ .best-answer-content {
924
+ display: flex;
925
+ align-items: flex-start;
926
+ gap: 15px;
927
+ }
928
+
929
+ .best-answer-icon {
930
+ font-size: 24px;
931
+ color: #4CAF50;
932
+ }
933
+
934
+ .best-answer-text {
935
+ flex: 1;
936
+ }
937
+
938
+ .best-answer-text p {
939
+ margin: 5px 0;
940
+ color: #ffffff;
941
+ }
942
+
943
+ .best-answer-text strong {
944
+ color: #4CAF50;
945
+ }
946
  """
947
 
948
  # Hardcoded model configurations
 
965
  }
966
 
967
  async def solve_problem(problem: str, max_rounds: int):
968
+ # Get API keys from environment variables or Hugging Face secrets
969
  api_clients = {}
970
 
971
  # Cohere client
 
983
  if gemini_key:
984
  genai.configure(api_key=gemini_key)
985
  api_clients["gemini"] = genai
986
+
987
+ # Anthropic client
988
+ anthropic_key = os.getenv("ANTHROPIC_API_KEY")
989
+ if anthropic_key:
990
+ api_clients["anthropic"] = Anthropic(api_key=anthropic_key)
991
+
992
+ # OpenAI client
993
+ openai_key = os.getenv("OPENAI_API_KEY")
994
+ if openai_key:
995
+ api_clients["openai"] = openai.OpenAI(api_key=openai_key)
996
 
997
  # Check if all required API keys are present
998
  required_providers = {solver1_config["provider"], solver2_config["provider"], judge_config["provider"]}