Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -38,21 +38,22 @@ def handle_update():
|
|
| 38 |
if message_text:
|
| 39 |
try:
|
| 40 |
# Forward message to Gradio and get the response
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
-
|
| 48 |
-
logger.debug(f"Generated response: {response_text}")
|
| 49 |
-
bot_send_message(chat_id, response_text)
|
| 50 |
logger.info(f"Response sent to chat_id {chat_id}")
|
| 51 |
|
| 52 |
except Exception as e:
|
| 53 |
logger.error(f"Error during processing: {e}")
|
| 54 |
error_message = "Sorry, I can't answer this query right now but I will improve from time to time."
|
| 55 |
-
bot_send_message(chat_id, error_message)
|
| 56 |
logger.error(f"Error message sent to chat_id {chat_id}")
|
| 57 |
|
| 58 |
return jsonify({'status': 'ok'}), 200
|
|
|
|
| 38 |
if message_text:
|
| 39 |
try:
|
| 40 |
# Forward message to Gradio and get the response
|
| 41 |
+
async def forward_message():
|
| 42 |
+
async with httpx.AsyncClient(proxies=PROXY_URL) as client:
|
| 43 |
+
response = await client.post('http://localhost:7860/gradio', json={'message': message_text})
|
| 44 |
+
if response.status_code == 200:
|
| 45 |
+
response_text = response.json().get('response', 'Sorry, I cannot process this request.')
|
| 46 |
+
else:
|
| 47 |
+
response_text = 'Error occurred while processing your request.'
|
| 48 |
+
await bot_send_message(chat_id, response_text)
|
| 49 |
|
| 50 |
+
asyncio.run(forward_message())
|
|
|
|
|
|
|
| 51 |
logger.info(f"Response sent to chat_id {chat_id}")
|
| 52 |
|
| 53 |
except Exception as e:
|
| 54 |
logger.error(f"Error during processing: {e}")
|
| 55 |
error_message = "Sorry, I can't answer this query right now but I will improve from time to time."
|
| 56 |
+
asyncio.run(bot_send_message(chat_id, error_message))
|
| 57 |
logger.error(f"Error message sent to chat_id {chat_id}")
|
| 58 |
|
| 59 |
return jsonify({'status': 'ok'}), 200
|