Spaces:
Sleeping
Sleeping
TuringsSolutions
commited on
Commit
•
d19c2e9
1
Parent(s):
c6b929b
Update app.py
Browse files
app.py
CHANGED
@@ -12,11 +12,18 @@ def call_gpt3_5(prompt, api_key):
|
|
12 |
response = client.chat.completions.create(
|
13 |
model="gpt-3.5-turbo",
|
14 |
messages=[
|
15 |
-
{"role": "system", "content": "You are a Python expert capable of implementing specific functions for a Swarm Neural Network (SNN). Return only the Python code for the requested function."},
|
16 |
{"role": "user", "content": prompt}
|
17 |
]
|
18 |
)
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
except Exception as e:
|
21 |
return f"Error calling GPT-3.5: {str(e)}"
|
22 |
|
@@ -24,16 +31,20 @@ class Agent:
|
|
24 |
def __init__(self, api_url):
|
25 |
self.api_url = api_url
|
26 |
self.data = None
|
|
|
27 |
|
28 |
def make_api_call(self):
|
29 |
try:
|
|
|
30 |
response = requests.get(self.api_url)
|
31 |
if response.status_code == 200:
|
32 |
self.data = response.json()
|
33 |
else:
|
34 |
self.data = {"error": f"API call failed with status code {response.status_code}"}
|
|
|
35 |
except Exception as e:
|
36 |
self.data = {"error": str(e)}
|
|
|
37 |
|
38 |
class SwarmNeuralNetwork:
|
39 |
def __init__(self, api_url, num_agents, calls_per_agent, special_config):
|
@@ -42,6 +53,7 @@ class SwarmNeuralNetwork:
|
|
42 |
self.calls_per_agent = calls_per_agent
|
43 |
self.special_config = special_config
|
44 |
self.agents = [Agent(api_url) for _ in range(num_agents)]
|
|
|
45 |
|
46 |
def run(self):
|
47 |
start_time = time.time()
|
@@ -69,7 +81,7 @@ def execute_snn(api_url, openai_api_key, num_agents, calls_per_agent, special_co
|
|
69 |
- Calls per Agent: {calls_per_agent}
|
70 |
- Special Configuration: {special_config if special_config else 'None'}
|
71 |
|
72 |
-
Provide only the Python code for the process_data method.
|
73 |
"""
|
74 |
|
75 |
process_data_code = call_gpt3_5(prompt, openai_api_key)
|
@@ -95,7 +107,7 @@ def execute_snn(api_url, openai_api_key, num_agents, calls_per_agent, special_co
|
|
95 |
else:
|
96 |
return process_data_code
|
97 |
|
98 |
-
# Define the Gradio interface
|
99 |
iface = gr.Interface(
|
100 |
fn=execute_snn,
|
101 |
inputs=[
|
|
|
12 |
response = client.chat.completions.create(
|
13 |
model="gpt-3.5-turbo",
|
14 |
messages=[
|
15 |
+
{"role": "system", "content": "You are a Python expert capable of implementing specific functions for a Swarm Neural Network (SNN). Return only the Python code for the requested function, without any additional text."},
|
16 |
{"role": "user", "content": prompt}
|
17 |
]
|
18 |
)
|
19 |
+
code = response.choices[0].message.content
|
20 |
+
# Clean up the code: remove leading/trailing whitespace and any markdown code blocks
|
21 |
+
code = code.strip()
|
22 |
+
if code.startswith("```python"):
|
23 |
+
code = code[10:]
|
24 |
+
if code.endswith("```"):
|
25 |
+
code = code[:-3]
|
26 |
+
return code.strip()
|
27 |
except Exception as e:
|
28 |
return f"Error calling GPT-3.5: {str(e)}"
|
29 |
|
|
|
31 |
def __init__(self, api_url):
|
32 |
self.api_url = api_url
|
33 |
self.data = None
|
34 |
+
self.processing_time = 0
|
35 |
|
36 |
def make_api_call(self):
|
37 |
try:
|
38 |
+
start_time = time.time()
|
39 |
response = requests.get(self.api_url)
|
40 |
if response.status_code == 200:
|
41 |
self.data = response.json()
|
42 |
else:
|
43 |
self.data = {"error": f"API call failed with status code {response.status_code}"}
|
44 |
+
self.processing_time = time.time() - start_time
|
45 |
except Exception as e:
|
46 |
self.data = {"error": str(e)}
|
47 |
+
self.processing_time = time.time() - start_time
|
48 |
|
49 |
class SwarmNeuralNetwork:
|
50 |
def __init__(self, api_url, num_agents, calls_per_agent, special_config):
|
|
|
53 |
self.calls_per_agent = calls_per_agent
|
54 |
self.special_config = special_config
|
55 |
self.agents = [Agent(api_url) for _ in range(num_agents)]
|
56 |
+
self.execution_time = 0
|
57 |
|
58 |
def run(self):
|
59 |
start_time = time.time()
|
|
|
81 |
- Calls per Agent: {calls_per_agent}
|
82 |
- Special Configuration: {special_config if special_config else 'None'}
|
83 |
|
84 |
+
Provide only the Python code for the process_data method, without any additional text or markdown formatting.
|
85 |
"""
|
86 |
|
87 |
process_data_code = call_gpt3_5(prompt, openai_api_key)
|
|
|
107 |
else:
|
108 |
return process_data_code
|
109 |
|
110 |
+
# Define the Gradio interface
|
111 |
iface = gr.Interface(
|
112 |
fn=execute_snn,
|
113 |
inputs=[
|