to-be commited on
Commit
dea123e
1 Parent(s): a5edcbf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -7
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
- async def telegram(image):
17
- bot = Bot(os.getenv('TELEGRAM_BOT_TOKEN'))
18
-
19
-
20
- await bot.send_message('OK')
 
 
 
 
 
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
- curl -X POST -H "Content-Type:multipart/form-data" -F chat_id=os.getenv('TELEGRAM_CHANNEL_ID') -F text="message" "https://api.telegram.org/"+os.getenv('TELEGRAM_BOT_TOKEN')+"/sendMessage"
29
- #curl -X POST -H 'Content-Type: application/json' -d '{"chat_id": "123456789", "text": "This is a test from curl", "disable_notification": true}' https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendMessage
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