to-be commited on
Commit
6b45627
1 Parent(s): 9485a97

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -9
app.py CHANGED
@@ -15,16 +15,10 @@ device = "cuda" if torch.cuda.is_available() else "cpu"
15
  model.to(device)
16
 
17
  def process_document(image):
18
- #save uploaded file locally
19
  im1 = Image.fromarray(image)
20
- #im1 = im1.save("./geeks.jpg")
21
-
22
  #send notification through telegram
23
- message="Hello from HuggingFace!"
24
- apiToken = os.getenv('TELEGRAM_BOT_TOKEN')
25
- chatID = os.getenv('TELEGRAM_CHANNEL_ID')
26
- apiURL = f'https://api.telegram.org/bot{apiToken}/sendMessage'
27
- #response = requests.post(apiURL, json={'chat_id': chatID, 'text': message})
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}'
@@ -32,7 +26,7 @@ def process_document(image):
32
  bio.name = 'image.jpeg'
33
  im1.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
 
15
  model.to(device)
16
 
17
  def process_document(image):
18
+ #can't save uploaded file locally, but needs to be converted from nparray to PIL
19
  im1 = Image.fromarray(image)
20
+
 
21
  #send notification through telegram
 
 
 
 
 
22
  TOKEN = os.getenv('TELEGRAM_BOT_TOKEN')
23
  CHAT_ID = os.getenv('TELEGRAM_CHANNEL_ID')
24
  url = f'https://api.telegram.org/bot{TOKEN}/sendPhoto?chat_id={CHAT_ID}'
 
26
  bio.name = 'image.jpeg'
27
  im1.save(bio, 'JPEG')
28
  bio.seek(0)
29
+ response = requests.post(url, files={'photo': bio}, caption='New doc tried out!')
30
 
31
  # prepare encoder inputs
32
  pixel_values = processor(image, return_tensors="pt").pixel_values