Spaces:
Paused
Paused
fix: Not building on hf problem fixed.3
Browse files- bot_telegram.py +26 -20
bot_telegram.py
CHANGED
|
@@ -182,28 +182,38 @@ class TelegramBot:
|
|
| 182 |
self.active_requests[message_id]['end_time'] = time.time()
|
| 183 |
|
| 184 |
def _make_api_request(self, user_message):
|
| 185 |
-
"""Make API request
|
| 186 |
try:
|
|
|
|
| 187 |
headers = {
|
| 188 |
-
"Authorization":
|
| 189 |
"accept": "application/json"
|
| 190 |
}
|
| 191 |
|
| 192 |
-
|
| 193 |
form_payload = {"question": user_message}
|
| 194 |
-
response = requests.post(
|
| 195 |
-
self.ai_url,
|
| 196 |
-
headers=headers,
|
| 197 |
-
data=form_payload
|
| 198 |
-
)
|
| 199 |
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
|
|
|
|
|
|
| 204 |
|
| 205 |
-
|
| 206 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
|
| 208 |
async def handle_excel(self, update: Update, context: CallbackContext):
|
| 209 |
"""Handle Excel files concurrently"""
|
|
@@ -286,7 +296,7 @@ class TelegramBot:
|
|
| 286 |
self.active_excel_files[message_id]['end_time'] = time.time()
|
| 287 |
|
| 288 |
def _process_excel_sync(self, file_bytes, filename):
|
| 289 |
-
"""Synchronous function to process Excel file
|
| 290 |
try:
|
| 291 |
headers = {
|
| 292 |
"Authorization": f"Bearer {HF_TOKEN}",
|
|
@@ -301,7 +311,6 @@ class TelegramBot:
|
|
| 301 |
)
|
| 302 |
}
|
| 303 |
|
| 304 |
-
# No timeout specified - will wait indefinitely
|
| 305 |
response = requests.post(
|
| 306 |
self.excel_url,
|
| 307 |
headers=headers,
|
|
@@ -311,10 +320,7 @@ class TelegramBot:
|
|
| 311 |
if response.status_code == 200:
|
| 312 |
return response.content
|
| 313 |
else:
|
| 314 |
-
|
| 315 |
-
if response.text:
|
| 316 |
-
error_msg += f" - {response.text}"
|
| 317 |
-
logging.error(error_msg)
|
| 318 |
return None
|
| 319 |
|
| 320 |
except Exception as e:
|
|
|
|
| 182 |
self.active_requests[message_id]['end_time'] = time.time()
|
| 183 |
|
| 184 |
def _make_api_request(self, user_message):
|
| 185 |
+
"""Make API request"""
|
| 186 |
try:
|
| 187 |
+
hf_authorization = "Bearer " + HF_TOKEN
|
| 188 |
headers = {
|
| 189 |
+
"Authorization": hf_authorization,
|
| 190 |
"accept": "application/json"
|
| 191 |
}
|
| 192 |
|
| 193 |
+
json_payload = {"question": user_message}
|
| 194 |
form_payload = {"question": user_message}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
|
| 196 |
+
try:
|
| 197 |
+
response = requests.post(
|
| 198 |
+
self.ai_url,
|
| 199 |
+
headers={**headers, "Content-Type": "application/json"},
|
| 200 |
+
json=json_payload
|
| 201 |
+
)
|
| 202 |
|
| 203 |
+
if response.status_code == 422:
|
| 204 |
+
response = requests.post(
|
| 205 |
+
self.ai_url,
|
| 206 |
+
headers={**headers, "Content-Type": "application/x-www-form-urlencoded"},
|
| 207 |
+
data=form_payload
|
| 208 |
+
)
|
| 209 |
+
|
| 210 |
+
if response.status_code == 200:
|
| 211 |
+
return response.json().get("answer", "I didn't understand that.")
|
| 212 |
+
else:
|
| 213 |
+
return f"Error: {response.status_code}"
|
| 214 |
+
|
| 215 |
+
except Exception as e:
|
| 216 |
+
return f"Connection error: {e}"
|
| 217 |
|
| 218 |
async def handle_excel(self, update: Update, context: CallbackContext):
|
| 219 |
"""Handle Excel files concurrently"""
|
|
|
|
| 296 |
self.active_excel_files[message_id]['end_time'] = time.time()
|
| 297 |
|
| 298 |
def _process_excel_sync(self, file_bytes, filename):
|
| 299 |
+
"""Synchronous function to process Excel file"""
|
| 300 |
try:
|
| 301 |
headers = {
|
| 302 |
"Authorization": f"Bearer {HF_TOKEN}",
|
|
|
|
| 311 |
)
|
| 312 |
}
|
| 313 |
|
|
|
|
| 314 |
response = requests.post(
|
| 315 |
self.excel_url,
|
| 316 |
headers=headers,
|
|
|
|
| 320 |
if response.status_code == 200:
|
| 321 |
return response.content
|
| 322 |
else:
|
| 323 |
+
logging.error(f"Excel API Error: {response.status_code} - {response.text}")
|
|
|
|
|
|
|
|
|
|
| 324 |
return None
|
| 325 |
|
| 326 |
except Exception as e:
|