Update app.py
Browse files
app.py
CHANGED
|
@@ -9,6 +9,7 @@ import asyncio
|
|
| 9 |
from transformers import pipeline
|
| 10 |
from langdetect import detect
|
| 11 |
from huggingface_hub import login
|
|
|
|
| 12 |
|
| 13 |
|
| 14 |
# Global variables
|
|
@@ -22,6 +23,14 @@ if not HF_HUB_TOKEN:
|
|
| 22 |
login(token=HF_HUB_TOKEN)
|
| 23 |
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
# Load Hebrew and English text generation models
|
| 26 |
hebrew_generator = pipeline("text-generation", model="Norod78/hebrew-gpt_neo-small")
|
| 27 |
english_generator = pipeline("text-generation", model="distilgpt2")
|
|
@@ -112,17 +121,27 @@ async def receive_update(request: Request):
|
|
| 112 |
await telegram_app.process_update(update)
|
| 113 |
return {"status": "ok"}
|
| 114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
-
async def check_internet():
|
| 117 |
-
try:
|
| 118 |
-
async with httpx.AsyncClient() as client:
|
| 119 |
-
response = await client.get("https://api.telegram.org")
|
| 120 |
-
print(f"Network test successful! Status Code: {response.status_code}")
|
| 121 |
-
except Exception as e:
|
| 122 |
-
print(f"Network test failed: {e}")
|
| 123 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
-
|
| 126 |
|
| 127 |
|
| 128 |
# Run the server
|
|
|
|
| 9 |
from transformers import pipeline
|
| 10 |
from langdetect import detect
|
| 11 |
from huggingface_hub import login
|
| 12 |
+
import socket
|
| 13 |
|
| 14 |
|
| 15 |
# Global variables
|
|
|
|
| 23 |
login(token=HF_HUB_TOKEN)
|
| 24 |
|
| 25 |
|
| 26 |
+
try:
|
| 27 |
+
response = httpx.get(f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/getMe")
|
| 28 |
+
print(f"Using TELEGRAM_TOKEN: {TOKEN[:5]}***") # Part of the token
|
| 29 |
+
print(response.json())
|
| 30 |
+
except httpx.RequestError as e:
|
| 31 |
+
print(f"Request failed: {e}")
|
| 32 |
+
|
| 33 |
+
|
| 34 |
# Load Hebrew and English text generation models
|
| 35 |
hebrew_generator = pipeline("text-generation", model="Norod78/hebrew-gpt_neo-small")
|
| 36 |
english_generator = pipeline("text-generation", model="distilgpt2")
|
|
|
|
| 121 |
await telegram_app.process_update(update)
|
| 122 |
return {"status": "ok"}
|
| 123 |
|
| 124 |
+
|
| 125 |
+
# async def check_internet():
|
| 126 |
+
# try:
|
| 127 |
+
# async with httpx.AsyncClient() as client:
|
| 128 |
+
# response = await client.get("https://api.telegram.org")
|
| 129 |
+
# print(f"Network test successful! Status Code: {response.status_code}")
|
| 130 |
+
# except Exception as e:
|
| 131 |
+
# print(f"Network test failed: {e}")
|
| 132 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
|
| 134 |
+
# asyncio.run(check_internet())
|
| 135 |
+
|
| 136 |
+
# Network test
|
| 137 |
+
def test_network():
|
| 138 |
+
try:
|
| 139 |
+
socket.gethostbyname("api.telegram.org")
|
| 140 |
+
print("Network test passed!")
|
| 141 |
+
except socket.gaierror:
|
| 142 |
+
print("Network test failed: No address associated with hostname")
|
| 143 |
|
| 144 |
+
test_network()
|
| 145 |
|
| 146 |
|
| 147 |
# Run the server
|