acecalisto3 commited on
Commit
3c5d009
1 Parent(s): ba67100

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -10
app.py CHANGED
@@ -2,10 +2,14 @@ import asyncio
2
  import logging
3
  from typing import Dict, Any
4
  from functools import partial
 
5
 
6
  from flask import Flask, request, jsonify
7
  from transformers import pipeline
8
 
 
 
 
9
  logging.basicConfig(level=logging.INFO)
10
 
11
  # Define core component classes
@@ -155,19 +159,19 @@ class EliteDeveloperCluster:
155
  app = Flask(__name__)
156
 
157
  @app.route('/agent', methods=['POST'])
158
- def agent_request():
159
  data = request.get_json()
160
  if data.get('input_value'):
161
  # Process request from any agent (Agent 2, Agent 3, etc.)
162
  task = Task(f"Process request from {data.get('agent_name', 'unknown agent')}", data.get('input_value'), data.get('agent_name', 'unknown agent'))
163
- cluster.task_queue.put_nowait(task)
164
  return jsonify({'response': 'Received input: from an agent, task added to queue.'})
165
  else:
166
  return jsonify({'response': 'Invalid input'})
167
 
168
  # Chat Interface
169
- def get_response(query: str) -> str:
170
- return cluster.route_request(query)
171
 
172
  def response_streaming(text: str):
173
  try:
@@ -188,7 +192,7 @@ class ChatApp:
188
  await self.cluster.stop()
189
 
190
  async def handle_request(self, query: str) -> str:
191
- response = await self.cluster.process_tasks()
192
  return response
193
 
194
  # Configuration
@@ -202,13 +206,23 @@ config = {
202
  "max_workers": 4,
203
  }
204
 
205
- if __name__ == "__main__":
 
206
  # Initialize the cluster
207
  cluster = EliteDeveloperCluster(config, model=None)
208
 
209
- # Start the cluster and task processing loop
210
- asyncio.run(cluster.start())
211
- asyncio.create_task(cluster.process_tasks())
 
 
212
 
213
  # Run Flask app
214
- app.run(debug=True)
 
 
 
 
 
 
 
 
2
  import logging
3
  from typing import Dict, Any
4
  from functools import partial
5
+ import warnings
6
 
7
  from flask import Flask, request, jsonify
8
  from transformers import pipeline
9
 
10
+ # Suppress the FutureWarning
11
+ warnings.filterwarnings("ignore", category=FutureWarning)
12
+
13
  logging.basicConfig(level=logging.INFO)
14
 
15
  # Define core component classes
 
159
  app = Flask(__name__)
160
 
161
  @app.route('/agent', methods=['POST'])
162
+ async def agent_request():
163
  data = request.get_json()
164
  if data.get('input_value'):
165
  # Process request from any agent (Agent 2, Agent 3, etc.)
166
  task = Task(f"Process request from {data.get('agent_name', 'unknown agent')}", data.get('input_value'), data.get('agent_name', 'unknown agent'))
167
+ await cluster.task_queue.put(task)
168
  return jsonify({'response': 'Received input: from an agent, task added to queue.'})
169
  else:
170
  return jsonify({'response': 'Invalid input'})
171
 
172
  # Chat Interface
173
+ async def get_response(query: str) -> str:
174
+ return await cluster.route_request(query)
175
 
176
  def response_streaming(text: str):
177
  try:
 
192
  await self.cluster.stop()
193
 
194
  async def handle_request(self, query: str) -> str:
195
+ response = await anext(self.cluster.process_tasks())
196
  return response
197
 
198
  # Configuration
 
206
  "max_workers": 4,
207
  }
208
 
209
+ async def main():
210
+ global cluster
211
  # Initialize the cluster
212
  cluster = EliteDeveloperCluster(config, model=None)
213
 
214
+ # Start the cluster
215
+ await cluster.start()
216
+
217
+ # Create a task for processing tasks
218
+ asyncio.create_task(anext(cluster.process_tasks()))
219
 
220
  # Run Flask app
221
+ from hypercorn.asyncio import serve
222
+ from hypercorn.config import Config
223
+ config = Config()
224
+ config.bind = ["localhost:5000"]
225
+ await serve(app, config)
226
+
227
+ if __name__ == "__main__":
228
+ asyncio.run(main())