Nevaehni commited on
Commit
dd323bf
·
1 Parent(s): 50b28d6
Files changed (1) hide show
  1. app.py +5 -6
app.py CHANGED
@@ -112,12 +112,11 @@ async def generate(ctx: commands.Context, *, args: str = None):
112
  try:
113
  logger.info(f"Received prompt: {prompt}")
114
 
115
- # Define an asynchronous wrapper for the predict call
116
- async def call_predict():
117
- return GRADIO_CLIENT.predict(param_0=prompt, api_name="/predict")
118
-
119
- # Set a timeout for the predict call (e.g., 60 seconds)
120
- response = await asyncio.wait_for(call_predict(), timeout=60)
121
 
122
  logger.info(f"API response: {response}")
123
 
 
112
  try:
113
  logger.info(f"Received prompt: {prompt}")
114
 
115
+ # Non-blocking call to predict using asyncio.to_thread
116
+ response = await asyncio.wait_for(
117
+ asyncio.to_thread(GRADIO_CLIENT.predict, param_0=prompt, api_name="/predict"),
118
+ timeout=60
119
+ )
 
120
 
121
  logger.info(f"API response: {response}")
122