Uhhy commited on
Commit
84e0fec
1 Parent(s): a4da55f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -12
app.py CHANGED
@@ -116,23 +116,22 @@ def generate_chat_response(request, model_data):
116
  try:
117
  user_input = normalize_input(request.message)
118
  response = model(user_input, top_k=request.top_k, top_p=request.top_p, temperature=request.temperature)
119
- return {"model": model_data['name'], "response": response}
120
  except Exception:
121
  pass
122
 
123
- @spaces.GPU(duration=0)
124
  async def generate(request: ChatRequest):
125
  try:
126
  responses = []
127
- with ThreadPoolExecutor() as executor:
128
- futures = [executor.submit(generate_chat_response, request, model_data) for model_data in global_data['models']]
129
- for future in as_completed(futures):
130
- try:
131
- response = future.result()
132
- if response:
133
- responses.append(response)
134
- except Exception:
135
- pass
136
 
137
  if not responses:
138
  raise HTTPException(status_code=500, detail="Error: No responses generated.")
@@ -152,7 +151,7 @@ async def handle_request(method_name: str, request: Request):
152
  body = await request.json()
153
  return {"message": "Request handled successfully", "body": body}
154
  except Exception:
155
- raise HTTPException(status_code=500, detail="Error: Internal Server Error")
156
 
157
  if __name__ == "__main__":
158
  uvicorn.run(app, host="0.0.0.0", port=7860)
 
116
  try:
117
  user_input = normalize_input(request.message)
118
  response = model(user_input, top_k=request.top_k, top_p=request.top_p, temperature=request.temperature)
119
+ return response
120
  except Exception:
121
  pass
122
 
123
+ @app.post("/generate")
124
  async def generate(request: ChatRequest):
125
  try:
126
  responses = []
127
+ models = global_data['models']
128
+ for model_data in models:
129
+ response = generate_chat_response(request, model_data)
130
+ if response:
131
+ responses.append({
132
+ "model": model_data['name'],
133
+ "response": response
134
+ })
 
135
 
136
  if not responses:
137
  raise HTTPException(status_code=500, detail="Error: No responses generated.")
 
151
  body = await request.json()
152
  return {"message": "Request handled successfully", "body": body}
153
  except Exception:
154
+ pass
155
 
156
  if __name__ == "__main__":
157
  uvicorn.run(app, host="0.0.0.0", port=7860)