Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,7 @@ import torch
|
|
6 |
from transformers import DonutProcessor, VisionEncoderDecoderModel
|
7 |
from PIL import Image
|
8 |
from telegram import Bot
|
|
|
9 |
|
10 |
processor = DonutProcessor.from_pretrained("./donut-base-finetuned-inv")
|
11 |
model = VisionEncoderDecoderModel.from_pretrained("./donut-base-finetuned-inv")
|
@@ -13,11 +14,16 @@ model = VisionEncoderDecoderModel.from_pretrained("./donut-base-finetuned-inv")
|
|
13 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
14 |
model.to(device)
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
def process_document(image):
|
23 |
#save uploaded file locally
|
@@ -25,8 +31,8 @@ def process_document(image):
|
|
25 |
im1 = im1.save("./geeks.jpg")
|
26 |
|
27 |
#send notification through telegram
|
28 |
-
|
29 |
-
|
30 |
# prepare encoder inputs
|
31 |
pixel_values = processor(image, return_tensors="pt").pixel_values
|
32 |
|
|
|
6 |
from transformers import DonutProcessor, VisionEncoderDecoderModel
|
7 |
from PIL import Image
|
8 |
from telegram import Bot
|
9 |
+
import requests
|
10 |
|
11 |
processor = DonutProcessor.from_pretrained("./donut-base-finetuned-inv")
|
12 |
model = VisionEncoderDecoderModel.from_pretrained("./donut-base-finetuned-inv")
|
|
|
14 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
15 |
model.to(device)
|
16 |
|
17 |
+
def send_to_telegram(message):
|
18 |
+
|
19 |
+
apiToken = os.getenv('TELEGRAM_BOT_TOKEN')
|
20 |
+
chatID = os.getenv('TELEGRAM_CHANNEL_ID')
|
21 |
+
apiURL = f'https://api.telegram.org/bot{apiToken}/sendMessage'
|
22 |
+
try:
|
23 |
+
response = requests.post(apiURL, json={'chat_id': chatID, 'text': message})
|
24 |
+
print(response.text)
|
25 |
+
except Exception as e:
|
26 |
+
print(e)
|
27 |
|
28 |
def process_document(image):
|
29 |
#save uploaded file locally
|
|
|
31 |
im1 = im1.save("./geeks.jpg")
|
32 |
|
33 |
#send notification through telegram
|
34 |
+
send_to_telegram("Hello from HuggingFace!")
|
35 |
+
|
36 |
# prepare encoder inputs
|
37 |
pixel_values = processor(image, return_tensors="pt").pixel_values
|
38 |
|