Yhhxhfh commited on
Commit
5cd11f8
1 Parent(s): db2e73b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -52,7 +52,6 @@ class ModelManager:
52
  for future in tqdm(as_completed(futures), total=len(global_data['model_configs']), desc="Loading models complete"):
53
  future.result()
54
 
55
-
56
  def _load_model(self, model_config):
57
  model_name = model_config['name']
58
  cache_file = os.path.join(self.model_cache_dir, f"{model_name}.pkl")
@@ -69,6 +68,7 @@ class ModelManager:
69
  print(f"Error loading model {model_name}: {e}")
70
  self.models[model_name] = None
71
 
 
72
  def get_model(self, model_name):
73
  return self.models.get(model_name)
74
 
@@ -107,15 +107,18 @@ async def process_message(message):
107
 
108
  with ThreadPoolExecutor(max_workers=len(global_data['model_configs'])) as executor:
109
  futures = [executor.submit(generate_model_response, model_manager.get_model(config['name']), inputs) for config in global_data['model_configs'] if model_manager.get_model(config['name'])]
 
110
  for i, future in enumerate(tqdm(as_completed(futures), total=len([f for f in futures]), desc="Generating responses")):
111
- model_name = global_data['model_configs'][i]['name']
112
- responses[model_name] = future.result()
 
113
 
114
 
115
  formatted_response = "\n\n".join([f"**{model}:**\n{response}" for model, response in responses.items()])
116
  response_cache[inputs] = formatted_response
117
  return formatted_response
118
 
 
119
  @app.post("/generate_multimodel")
120
  async def api_generate_multimodel(request: Request):
121
  try:
@@ -131,6 +134,7 @@ async def api_generate_multimodel(request: Request):
131
  return JSONResponse({"error": str(e)}, status_code=500)
132
 
133
 
 
134
  iface = gr.Interface(
135
  fn=process_message,
136
  inputs=gr.Textbox(lines=2, placeholder="Enter your message here..."),
 
52
  for future in tqdm(as_completed(futures), total=len(global_data['model_configs']), desc="Loading models complete"):
53
  future.result()
54
 
 
55
  def _load_model(self, model_config):
56
  model_name = model_config['name']
57
  cache_file = os.path.join(self.model_cache_dir, f"{model_name}.pkl")
 
68
  print(f"Error loading model {model_name}: {e}")
69
  self.models[model_name] = None
70
 
71
+
72
  def get_model(self, model_name):
73
  return self.models.get(model_name)
74
 
 
107
 
108
  with ThreadPoolExecutor(max_workers=len(global_data['model_configs'])) as executor:
109
  futures = [executor.submit(generate_model_response, model_manager.get_model(config['name']), inputs) for config in global_data['model_configs'] if model_manager.get_model(config['name'])]
110
+
111
  for i, future in enumerate(tqdm(as_completed(futures), total=len([f for f in futures]), desc="Generating responses")):
112
+ model_name = global_data['model_configs'][i]['name']
113
+ responses[model_name] = future.result()
114
+
115
 
116
 
117
  formatted_response = "\n\n".join([f"**{model}:**\n{response}" for model, response in responses.items()])
118
  response_cache[inputs] = formatted_response
119
  return formatted_response
120
 
121
+
122
  @app.post("/generate_multimodel")
123
  async def api_generate_multimodel(request: Request):
124
  try:
 
134
  return JSONResponse({"error": str(e)}, status_code=500)
135
 
136
 
137
+
138
  iface = gr.Interface(
139
  fn=process_message,
140
  inputs=gr.Textbox(lines=2, placeholder="Enter your message here..."),