TuringsSolutions commited on
Commit
63a5233
·
verified ·
1 Parent(s): a961001

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -20,7 +20,7 @@ class Agent:
20
  print(f"Agent {self.id} is making an API call to '{self.task}'")
21
  headers = {"Authorization": f"Bearer {self.api_key}"} if self.api_key else {}
22
  try:
23
- response = requests.get(self.task, headers=headers)
24
  if response.status_code == 200:
25
  self.results = response.json()
26
  else:
@@ -59,10 +59,14 @@ def generate_tasks_from_model(api_url, num_tasks):
59
  prompt = f"Generate an API call task for the following API URL: {api_url}"
60
  inputs = tokenizer(prompt, return_tensors="pt")
61
  print(f"Generating task with prompt: {prompt}")
62
- outputs = model.generate(**inputs, max_length=100)
63
- task = tokenizer.decode(outputs[0], skip_special_tokens=True)
64
- print(f"Generated task: {task}")
65
- tasks.append(task)
 
 
 
 
66
  return tasks
67
 
68
  def run_swarm(api_url, api_key, num_agents, num_tasks):
@@ -121,4 +125,4 @@ iface = gr.Interface(
121
  """
122
  )
123
 
124
- iface.launch()
 
20
  print(f"Agent {self.id} is making an API call to '{self.task}'")
21
  headers = {"Authorization": f"Bearer {self.api_key}"} if self.api_key else {}
22
  try:
23
+ response = requests.get(self.task, headers=headers, timeout=10) # Add timeout
24
  if response.status_code == 200:
25
  self.results = response.json()
26
  else:
 
59
  prompt = f"Generate an API call task for the following API URL: {api_url}"
60
  inputs = tokenizer(prompt, return_tensors="pt")
61
  print(f"Generating task with prompt: {prompt}")
62
+ try:
63
+ outputs = model.generate(**inputs, max_length=50) # Limit max length for speed
64
+ task = tokenizer.decode(outputs[0], skip_special_tokens=True)
65
+ print(f"Generated task: {task}")
66
+ tasks.append(task)
67
+ except Exception as e:
68
+ print(f"Error generating task: {str(e)}")
69
+ tasks.append(f"Error generating task: {str(e)}")
70
  return tasks
71
 
72
  def run_swarm(api_url, api_key, num_agents, num_tasks):
 
125
  """
126
  )
127
 
128
+ iface.launch()