AUXteam commited on
Commit
ec0049d
·
verified ·
1 Parent(s): ad851f7

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +21 -6
app.py CHANGED
@@ -28,9 +28,12 @@ class RunRequest(BaseModel):
28
  num_ideas: int
29
  openai_key: Optional[str] = None
30
  anthropic_key: Optional[str] = None
 
31
  engine: Optional[str] = "semanticscholar"
32
  s2_api_key: Optional[str] = None
33
  openalex_mail: Optional[str] = None
 
 
34
 
35
  @app.get("/health")
36
  def health():
@@ -38,13 +41,13 @@ def health():
38
 
39
  @app.post("/run")
40
  def run_api(req: RunRequest):
41
- return {"message": start_scientist(req.model, req.experiment, req.num_ideas, req.openai_key, req.anthropic_key, req.engine, req.s2_api_key, req.openalex_mail)}
42
 
43
  @app.get("/logs")
44
  def get_logs():
45
  return {"logs": process_output}
46
 
47
- def run_scientist_cmd(model, experiment, num_ideas, openai_key, anthropic_key, engine, s2_api_key, openalex_mail):
48
  global current_process, process_output
49
  process_output = "--- Starting AI Scientist ---\n"
50
 
@@ -53,6 +56,8 @@ def run_scientist_cmd(model, experiment, num_ideas, openai_key, anthropic_key, e
53
  env["OPENAI_API_KEY"] = openai_key
54
  if anthropic_key:
55
  env["ANTHROPIC_API_KEY"] = anthropic_key
 
 
56
  if s2_api_key:
57
  env["S2_API_KEY"] = s2_api_key
58
  if openalex_mail:
@@ -65,6 +70,10 @@ def run_scientist_cmd(model, experiment, num_ideas, openai_key, anthropic_key, e
65
  "--num-ideas", str(int(num_ideas)),
66
  "--engine", engine
67
  ]
 
 
 
 
68
 
69
  process_output += f"Running command: {' '.join(cmd)}\n\n"
70
 
@@ -90,12 +99,12 @@ def run_scientist_cmd(model, experiment, num_ideas, openai_key, anthropic_key, e
90
  finally:
91
  current_process = None
92
 
93
- def start_scientist(model, experiment, num_ideas, openai_key, anthropic_key, engine="semanticscholar", s2_api_key=None, openalex_mail=None):
94
  global current_process
95
  if current_process is not None:
96
  return "A process is already running."
97
 
98
- thread = threading.Thread(target=run_scientist_cmd, args=(model, experiment, num_ideas, openai_key, anthropic_key, engine, s2_api_key, openalex_mail))
99
  thread.start()
100
  return "Process started."
101
 
@@ -127,6 +136,8 @@ with gr.Blocks(title="The AI Scientist") as demo:
127
  gr.Markdown("### ⚙️ Experiment Configuration")
128
  model_input = gr.Dropdown(
129
  choices=[
 
 
130
  "gpt-4o-2024-05-13",
131
  "claude-3-5-sonnet-20241022",
132
  "gpt-4o-mini",
@@ -134,7 +145,7 @@ with gr.Blocks(title="The AI Scientist") as demo:
134
  "deepseek-reasoner"
135
  ],
136
  label="Model",
137
- value="gpt-4o-2024-05-13"
138
  )
139
  exp_input = gr.Dropdown(
140
  choices=[
@@ -153,11 +164,15 @@ with gr.Blocks(title="The AI Scientist") as demo:
153
  label="Literature Search Engine",
154
  value="semanticscholar"
155
  )
 
 
 
156
 
157
  with gr.Column():
158
  gr.Markdown("### 🔑 API Keys")
159
  openai_key_input = gr.Textbox(label="OpenAI API Key (Required for GPT models)", type="password")
160
  anthropic_key_input = gr.Textbox(label="Anthropic API Key (Required for Claude models)", type="password")
 
161
  s2_api_key_input = gr.Textbox(label="Semantic Scholar API Key (Optional)", type="password")
162
  openalex_mail_input = gr.Textbox(label="OpenAlex Email (Optional but recommended for OpenAlex)")
163
 
@@ -173,7 +188,7 @@ with gr.Blocks(title="The AI Scientist") as demo:
173
  refresh_results_btn = gr.Button("Refresh Results List")
174
 
175
  # Event handlers
176
- run_btn.click(start_scientist, inputs=[model_input, exp_input, num_ideas_input, openai_key_input, anthropic_key_input, engine_input, s2_api_key_input, openalex_mail_input], outputs=output_text)
177
  stop_btn.click(stop_process, None, output_text)
178
  refresh_btn.click(get_output, None, output_text)
179
  refresh_results_btn.click(list_results, None, results_list)
 
28
  num_ideas: int
29
  openai_key: Optional[str] = None
30
  anthropic_key: Optional[str] = None
31
+ blablador_key: Optional[str] = None
32
  engine: Optional[str] = "semanticscholar"
33
  s2_api_key: Optional[str] = None
34
  openalex_mail: Optional[str] = None
35
+ topic: Optional[str] = ""
36
+ research_questions: Optional[str] = ""
37
 
38
  @app.get("/health")
39
  def health():
 
41
 
42
  @app.post("/run")
43
  def run_api(req: RunRequest):
44
+ return {"message": start_scientist(req.model, req.experiment, req.num_ideas, req.openai_key, req.anthropic_key, req.blablador_key, req.engine, req.s2_api_key, req.openalex_mail, req.topic, req.research_questions)}
45
 
46
  @app.get("/logs")
47
  def get_logs():
48
  return {"logs": process_output}
49
 
50
+ def run_scientist_cmd(model, experiment, num_ideas, openai_key, anthropic_key, blablador_key, engine, s2_api_key, openalex_mail, topic, research_questions):
51
  global current_process, process_output
52
  process_output = "--- Starting AI Scientist ---\n"
53
 
 
56
  env["OPENAI_API_KEY"] = openai_key
57
  if anthropic_key:
58
  env["ANTHROPIC_API_KEY"] = anthropic_key
59
+ if blablador_key:
60
+ env["BLABLADOR_API_KEY"] = blablador_key
61
  if s2_api_key:
62
  env["S2_API_KEY"] = s2_api_key
63
  if openalex_mail:
 
70
  "--num-ideas", str(int(num_ideas)),
71
  "--engine", engine
72
  ]
73
+ if topic:
74
+ cmd.extend(["--topic", topic])
75
+ if research_questions:
76
+ cmd.extend(["--research-questions", research_questions])
77
 
78
  process_output += f"Running command: {' '.join(cmd)}\n\n"
79
 
 
99
  finally:
100
  current_process = None
101
 
102
+ def start_scientist(model, experiment, num_ideas, openai_key, anthropic_key, blablador_key, engine="semanticscholar", s2_api_key=None, openalex_mail=None, topic="", research_questions=""):
103
  global current_process
104
  if current_process is not None:
105
  return "A process is already running."
106
 
107
+ thread = threading.Thread(target=run_scientist_cmd, args=(model, experiment, num_ideas, openai_key, anthropic_key, blablador_key, engine, s2_api_key, openalex_mail, topic, research_questions))
108
  thread.start()
109
  return "Process started."
110
 
 
136
  gr.Markdown("### ⚙️ Experiment Configuration")
137
  model_input = gr.Dropdown(
138
  choices=[
139
+ "alias-large",
140
+ "alias-fast",
141
  "gpt-4o-2024-05-13",
142
  "claude-3-5-sonnet-20241022",
143
  "gpt-4o-mini",
 
145
  "deepseek-reasoner"
146
  ],
147
  label="Model",
148
+ value="alias-large"
149
  )
150
  exp_input = gr.Dropdown(
151
  choices=[
 
164
  label="Literature Search Engine",
165
  value="semanticscholar"
166
  )
167
+
168
+ topic_input = gr.Textbox(label="Research Topic (Optional)", placeholder="e.g. Efficient Attention Mechanisms")
169
+ rq_input = gr.Textbox(label="Research Questions (Optional)", placeholder="e.g. Can we reduce the complexity to O(N log N)?", lines=3)
170
 
171
  with gr.Column():
172
  gr.Markdown("### 🔑 API Keys")
173
  openai_key_input = gr.Textbox(label="OpenAI API Key (Required for GPT models)", type="password")
174
  anthropic_key_input = gr.Textbox(label="Anthropic API Key (Required for Claude models)", type="password")
175
+ blablador_key_input = gr.Textbox(label="BLABLADOR_API_KEY (Optional if set in Space secrets)", type="password")
176
  s2_api_key_input = gr.Textbox(label="Semantic Scholar API Key (Optional)", type="password")
177
  openalex_mail_input = gr.Textbox(label="OpenAlex Email (Optional but recommended for OpenAlex)")
178
 
 
188
  refresh_results_btn = gr.Button("Refresh Results List")
189
 
190
  # Event handlers
191
+ run_btn.click(start_scientist, inputs=[model_input, exp_input, num_ideas_input, openai_key_input, anthropic_key_input, blablador_key_input, engine_input, s2_api_key_input, openalex_mail_input, topic_input, rq_input], outputs=output_text)
192
  stop_btn.click(stop_process, None, output_text)
193
  refresh_btn.click(get_output, None, output_text)
194
  refresh_results_btn.click(list_results, None, results_list)