Spaces:
Running
on
Zero
Running
on
Zero
File size: 1,087 Bytes
a746d34 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
from django.shortcuts import render
from .models import ImageModel
from .ocr import ocr_extract_text
from googleapiclient.discovery import build
from google.oauth2 import service_account
def index(request):
if request.method == 'POST':
image = request.FILES['image']
img_obj = ImageModel(image=image)
img_obj.save()
ocr_text = ocr_extract_text(img_obj.image.path)
img_obj.ocr_text = ocr_text
img_obj.save()
return render(request, 'polls/index.html', {'ocr_text': ocr_text})
return render(request, 'polls/index.html')
def google_chat_insert(text):
SCOPES = ['https://www.googleapis.com/auth/chat.service']
SERVICE_ACCOUNT_FILE = 'path/to/service_account_key.json'
credentials = service_account.Credentials.from_service_account_file(
SERVICE_ACCOUNT_FILE, scopes=SCOPES)
chat_service = build('chat', 'v1', credentials=credentials)
request_body = {'text': text}
response = chat_service.spaces().messages().create(
parent='spaces/AAAA', body=request_body).execute()
print(response) |