bowenchen118 commited on
Commit
36e014d
Β·
1 Parent(s): 041d087
Files changed (1) hide show
  1. app.py +25 -12
app.py CHANGED
@@ -8,6 +8,7 @@ import uuid
8
  from PIL import Image
9
  from typing import List, Dict, Any, Iterator
10
  import gradio as gr
 
11
 
12
  # Add the project root to the Python path
13
  current_dir = os.path.dirname(os.path.abspath(__file__))
@@ -89,6 +90,7 @@ class Solver:
89
  self.executor.set_query_cache_dir(_cache_dir)
90
 
91
  # Step 1: Display the received inputs
 
92
  if user_image:
93
  messages.append(ChatMessage(role="assistant", content=f"πŸ“ Received Query: {user_query}\nπŸ–ΌοΈ Image Uploaded"))
94
  else:
@@ -190,17 +192,18 @@ def parse_arguments():
190
  parser.add_argument("--enabled_tools", default="Generalist_Solution_Generator_Tool", help="List of enabled tools.")
191
  parser.add_argument("--root_cache_dir", default="demo_solver_cache", help="Path to solver cache directory.")
192
  parser.add_argument("--output_json_dir", default="demo_results", help="Path to output JSON directory.")
193
- parser.add_argument("--max_steps", type=int, default=10, help="Maximum number of steps to execute.")
194
- parser.add_argument("--max_time", type=int, default=60, help="Maximum time allowed in seconds.")
195
  parser.add_argument("--verbose", type=bool, default=True, help="Enable verbose output.")
196
  return parser.parse_args()
197
 
198
 
199
- def solve_problem_gradio(user_query, user_image, api_key):
200
  """
201
  Wrapper function to connect the solver to Gradio.
202
  Streams responses from `solver.stream_solve_user_problem` for real-time UI updates.
203
  """
 
 
 
204
 
205
  # Initialize Tools
206
  enabled_tools = args.enabled_tools.split(",") if args.enabled_tools else []
@@ -240,8 +243,8 @@ def solve_problem_gradio(user_query, user_image, api_key):
240
  task_description=args.task_description,
241
  output_types=args.output_types, # Add new parameter
242
  verbose=args.verbose,
243
- max_steps=args.max_steps,
244
- max_time=args.max_time,
245
  output_json_dir=args.output_json_dir,
246
  root_cache_dir=args.root_cache_dir
247
  )
@@ -261,16 +264,26 @@ def main(args):
261
  gr.Markdown("# 🧠 OctoTools AI Solver") # Title
262
 
263
  with gr.Row():
264
- with gr.Column(scale=1, min_width=300):
265
- user_query = gr.Textbox(label="Enter your query", placeholder="Type your question here...")
266
- api_key = gr.Textbox(label="API Key", placeholder="Your API key will not be stored in any way.", type="password")
267
  user_image = gr.Image(type="pil", label="Upload an image") # Accepts multiple formats
268
- run_button = gr.Button("Run") # Run button
269
- with gr.Column(scale=3, min_width=300):
270
- chatbot_output = gr.Chatbot(label="Problem-Solving Output")
 
 
 
 
 
 
 
 
 
 
 
271
 
272
  # Link button click to function
273
- run_button.click(fn=solve_problem_gradio, inputs=[user_query, user_image, api_key], outputs=chatbot_output)
274
 
275
  # Launch the Gradio app
276
  demo.launch()
 
8
  from PIL import Image
9
  from typing import List, Dict, Any, Iterator
10
  import gradio as gr
11
+ # from gradio import ChatMessage
12
 
13
  # Add the project root to the Python path
14
  current_dir = os.path.dirname(os.path.abspath(__file__))
 
90
  self.executor.set_query_cache_dir(_cache_dir)
91
 
92
  # Step 1: Display the received inputs
93
+ import pdb; pdb.set_trace()
94
  if user_image:
95
  messages.append(ChatMessage(role="assistant", content=f"πŸ“ Received Query: {user_query}\nπŸ–ΌοΈ Image Uploaded"))
96
  else:
 
192
  parser.add_argument("--enabled_tools", default="Generalist_Solution_Generator_Tool", help="List of enabled tools.")
193
  parser.add_argument("--root_cache_dir", default="demo_solver_cache", help="Path to solver cache directory.")
194
  parser.add_argument("--output_json_dir", default="demo_results", help="Path to output JSON directory.")
 
 
195
  parser.add_argument("--verbose", type=bool, default=True, help="Enable verbose output.")
196
  return parser.parse_args()
197
 
198
 
199
+ def solve_problem_gradio(user_query, user_image, max_steps=10, max_time=60, api_key=None):
200
  """
201
  Wrapper function to connect the solver to Gradio.
202
  Streams responses from `solver.stream_solve_user_problem` for real-time UI updates.
203
  """
204
+
205
+ if api_key is None:
206
+ return [["assistant", "⚠️ Error: API Key is required."]]
207
 
208
  # Initialize Tools
209
  enabled_tools = args.enabled_tools.split(",") if args.enabled_tools else []
 
243
  task_description=args.task_description,
244
  output_types=args.output_types, # Add new parameter
245
  verbose=args.verbose,
246
+ max_steps=max_steps,
247
+ max_time=max_time,
248
  output_json_dir=args.output_json_dir,
249
  root_cache_dir=args.root_cache_dir
250
  )
 
264
  gr.Markdown("# 🧠 OctoTools AI Solver") # Title
265
 
266
  with gr.Row():
267
+ with gr.Column(scale=1):
268
+ api_key = gr.Textbox(show_label=False, placeholder="Your API key will not be stored in any way.", type="password", container=False)
 
269
  user_image = gr.Image(type="pil", label="Upload an image") # Accepts multiple formats
270
+ max_steps = gr.Slider(value=5, minimum=1, maximum=10, step=1)
271
+ max_time = gr.Slider(value=180, minimum=60, maximum=300, step=20)
272
+ with gr.Column(scale=3):
273
+ chatbot_output = gr.Chatbot(label="Problem-Solving Output", show_copy_button=True)
274
+ chatbot_output.like(lambda x: print(f"User liked: {x}"))
275
+ with gr.Row():
276
+ with gr.Column(scale=8):
277
+ user_query = gr.Textbox(show_label=False, placeholder="Type your question here...", container=False)
278
+ with gr.Column(scale=1):
279
+ run_button = gr.Button("Run") # Run button
280
+ with gr.Row(elem_id="buttons") as button_row:
281
+ upvote_btn = gr.Button(value="πŸ‘ Upvote", interactive=False)
282
+ downvote_btn = gr.Button(value="πŸ‘Ž Downvote", interactive=False)
283
+ clear_btn = gr.Button(value="πŸ—‘οΈ Clear history", interactive=False)
284
 
285
  # Link button click to function
286
+ run_button.click(fn=solve_problem_gradio, inputs=[user_query, user_image, max_steps, max_time, api_key], outputs=chatbot_output)
287
 
288
  # Launch the Gradio app
289
  demo.launch()