
掌握API網(wǎng)關(guān)認(rèn)證:安全連接的可靠方法
2import json
3import requests
4from tencentcloud.common import credential
5from tencentcloud.common.profile.client_profile import ClientProfile
6from tencentcloud.common.profile.http_profile import HttpProfile
7from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
8from tencentcloud.ecc.v20181213 import ecc_client, models
9from tencentcloud.ocr.v20181119 import ocr_client, models as ocr_models
10
11# 騰訊云賬號(hào)信息
12SECRET_ID = "YOUR_SECRET_ID"
13SECRET_KEY = "YOUR_SECRET_KEY"
14REGION = "ap-guangzhou"
15
16# OCR識(shí)別
17def ocr_image(image_path):
18 try:
19 cred = credential.Credential(SECRET_ID, SECRET_KEY)
20 httpProfile = HttpProfile()
21 httpProfile.endpoint = "ocr.tencentcloudapi.com"
22
23 clientProfile = ClientProfile()
24 clientProfile.httpProfile = httpProfile
25 client = ocr_client.OcrClient(cred, REGION, clientProfile)
26
27 # 加載圖片
28 with open(image_path, 'rb') as f:
29 image_data = f.read()
30
31 # 構(gòu)建請(qǐng)求
32 req = ocr_models.GeneralAccurateOCRRequest()
33 params = {
34 "ImageBase64": base64.b64encode(image_data).decode("utf-8"),
35 "LanguageType": "en"
36 }
37 req.from_json_string(json.dumps(params))
38
39 # 發(fā)送請(qǐng)求
40 resp = client.GeneralAccurateOCR(req)
41 return resp.to_json_string()
42
43 except TencentCloudSDKException as err:
44 print(err)
45
46
47# ECC批改作文
48def correct_essay(text):
49 try:
50 cred = credential.Credential(SECRET_ID, SECRET_KEY)
51 httpProfile = HttpProfile()
52 httpProfile.endpoint = "ecc.tencentcloudapi.com"
53
54 clientProfile = ClientProfile()
55 clientProfile.httpProfile = httpProfile
56 client = ecc_client.EccClient(cred, REGION, clientProfile)
57
58 # 構(gòu)建請(qǐng)求
59 req = models.CorrectEssayRequest()
60 params = {
61 "Text": text,
62 "LanguageType": "EN"
63 }
64 req.from_json_string(json.dumps(params))
65
66 # 發(fā)送請(qǐng)求
67 resp = client.CorrectEssay(req)
68 return resp.to_json_string()
69
70 except TencentCloudSDKException as err:
71 print(err)
72
73
74# 主函數(shù)
75if __name__ == "__main__":
76 # 指定圖片路徑
77 image_path = "path/to/your/image.jpg"
78
79 # OCR識(shí)別
80 ocr_response = ocr_image(image_path)
81 print("OCR Response:", ocr_response)
82
83 # 解析OCR結(jié)果
84 ocr_result = json.loads(ocr_response)
85 essay_text = "\n".join([item["DetectedText"] for item in ocr_result["TextDetections"]])
86
87 # 打印識(shí)別出來(lái)的作文
88 print("Recognized Essay:")
89 print(essay_text)
90
91 # ECC批改作文
92 ecc_response = correct_essay(essay_text)
93 print("ECC Response:", ecc_response)
通過(guò)以上步驟,你可以構(gòu)建一個(gè)完整的英語(yǔ)作文拍照批改程序。確保按照騰訊云提供的文檔和指南進(jìn)行操作,并妥善處理用戶的隱私和數(shù)據(jù)安全問(wèn)題。
掌握API網(wǎng)關(guān)認(rèn)證:安全連接的可靠方法
使用Python調(diào)用Crawlbase Scraper API 抓取AliExpress 網(wǎng)頁(yè)數(shù)據(jù)
使用API安全的基本工具和最佳實(shí)踐預(yù)防API攻擊
AI驅(qū)動(dòng)SEO排名優(yōu)化使工作更省力
2024年頂級(jí)JavaScript REST API框架
從理論到實(shí)踐:Cohere平臺(tái)上LLM大模型的集成案例
Web應(yīng)用程序和API安全的新規(guī)則
很好用的AI寫(xiě)作API推薦
API安全性以及憑證和訪問(wèn)控制的重要性
對(duì)比大模型API的內(nèi)容創(chuàng)意新穎性、情感共鳴力、商業(yè)轉(zhuǎn)化潛力
一鍵對(duì)比試用API 限時(shí)免費(fèi)