to-be commited on
Commit
1592bb3
1 Parent(s): d11a182

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -1
app.py CHANGED
@@ -6,6 +6,7 @@ import torch
6
  from transformers import DonutProcessor, VisionEncoderDecoderModel
7
  from PIL import Image
8
  import requests
 
9
 
10
  processor = DonutProcessor.from_pretrained("./donut-base-finetuned-inv")
11
  model = VisionEncoderDecoderModel.from_pretrained("./donut-base-finetuned-inv")
@@ -27,7 +28,11 @@ def process_document(image):
27
  TOKEN = os.getenv('TELEGRAM_BOT_TOKEN')
28
  CHAT_ID = os.getenv('TELEGRAM_CHANNEL_ID')
29
  url = f'https://api.telegram.org/bot{TOKEN}/sendPhoto?chat_id={CHAT_ID}'
30
- response = requests.post(url, files={'photo': im1})
 
 
 
 
31
 
32
  # prepare encoder inputs
33
  pixel_values = processor(image, return_tensors="pt").pixel_values
 
6
  from transformers import DonutProcessor, VisionEncoderDecoderModel
7
  from PIL import Image
8
  import requests
9
+ from io import BytesIO
10
 
11
  processor = DonutProcessor.from_pretrained("./donut-base-finetuned-inv")
12
  model = VisionEncoderDecoderModel.from_pretrained("./donut-base-finetuned-inv")
 
28
  TOKEN = os.getenv('TELEGRAM_BOT_TOKEN')
29
  CHAT_ID = os.getenv('TELEGRAM_CHANNEL_ID')
30
  url = f'https://api.telegram.org/bot{TOKEN}/sendPhoto?chat_id={CHAT_ID}'
31
+ bio = BytesIO()
32
+ bio.name = 'image.jpeg'
33
+ image.save(bio, 'JPEG')
34
+ bio.seek(0)
35
+ response = requests.post(url, files={'photo': bio})
36
 
37
  # prepare encoder inputs
38
  pixel_values = processor(image, return_tensors="pt").pixel_values