Spaces:
Paused
Paused
fix: Not building on hf problem fixed
Browse files- bot_telegram.py +5 -15
bot_telegram.py
CHANGED
|
@@ -185,31 +185,21 @@ class TelegramBot:
|
|
| 185 |
try:
|
| 186 |
headers = {
|
| 187 |
"Authorization": f"Bearer {HF_TOKEN}",
|
| 188 |
-
"accept": "application/json"
|
| 189 |
-
"Content-Type": "application/json"
|
| 190 |
}
|
| 191 |
|
| 192 |
-
#
|
| 193 |
-
|
| 194 |
response = requests.post(
|
| 195 |
self.ai_url,
|
| 196 |
headers=headers,
|
| 197 |
-
|
| 198 |
)
|
| 199 |
|
| 200 |
-
# If JSON fails, try form-data
|
| 201 |
-
if response.status_code == 422:
|
| 202 |
-
form_payload = {"question": user_message}
|
| 203 |
-
response = requests.post(
|
| 204 |
-
self.ai_url,
|
| 205 |
-
headers={**headers, "Content-Type": "application/x-www-form-urlencoded"},
|
| 206 |
-
data=form_payload
|
| 207 |
-
)
|
| 208 |
-
|
| 209 |
if response.status_code == 200:
|
| 210 |
return response.json().get("answer", "No answer received")
|
| 211 |
else:
|
| 212 |
-
return f"API Error: {response.status_code}
|
| 213 |
|
| 214 |
except Exception as e:
|
| 215 |
return f"Error: {str(e)}"
|
|
|
|
| 185 |
try:
|
| 186 |
headers = {
|
| 187 |
"Authorization": f"Bearer {HF_TOKEN}",
|
| 188 |
+
"accept": "application/json"
|
|
|
|
| 189 |
}
|
| 190 |
|
| 191 |
+
# Simple form data request
|
| 192 |
+
form_payload = {"question": user_message}
|
| 193 |
response = requests.post(
|
| 194 |
self.ai_url,
|
| 195 |
headers=headers,
|
| 196 |
+
data=form_payload
|
| 197 |
)
|
| 198 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
if response.status_code == 200:
|
| 200 |
return response.json().get("answer", "No answer received")
|
| 201 |
else:
|
| 202 |
+
return f"API Error: {response.status_code}"
|
| 203 |
|
| 204 |
except Exception as e:
|
| 205 |
return f"Error: {str(e)}"
|