kenken999's picture
test
9df0420
raw
history blame
1.28 kB
from flask import Flask, request, jsonify
import gradio as gr
import pytesseract
from google.oauth2 import service_account
from googleapiclient.discovery import build
app = Flask(__name__)
# Google Apps Script API credentials
SCOPES = ['https://www.googleapis.com/auth/script.projects']
SERVICE_ACCOUNT_FILE = 'service_account_key.json'
# Load credentials from service account file
creds = service_account.Credentials.from_service_account_file(
SERVICE_ACCOUNT_FILE, SCOPES=SCOPES)
# Create Google Apps Script API client
script_service = build('script', 'v1', credentials=creds)
# Create Gradio interface
iface = gr.Interface(
fn=lambda img: ocr(img),
inputs="image",
outputs="text",
title="OCR App",
description="Upload an image to extract text"
)
@app.route('/ocr', methods=['POST'])
def ocr(img):
# Perform OCR using Tesseract
text = pytesseract.image_to_string(img)
return text
@app.route('/google_chat_insert', methods=['POST'])
def google_chat_insert(text):
# Insert text into Google Chat using Google Apps Script API
script_service.scripts().run(body={'function': 'insertText', 'parameters': [text]}).execute()
return 'Text inserted into Google Chat'
if __name__ == '__main__':
iface.launch()
app.run(debug=True)