1.28寒假每日总结19

今天,我主要尝试了对之前的几个python脚本进行整合,使得可以输入图片路径,题目,总分进行评价

 

参考:百度文心一言的回复

 

复制代码
# -*- coding: utf-8 -*-
import os
import sys
import erniebot
from PIL import Image
from paddleocr import PaddleOCR, draw_ocr


def baidu_paddleocr(input_path, output_path="result.jpg"):
    ocr = PaddleOCR(use_angle_cls=True, lang="ch", show_log=False)
    img_path = input_path
    result = ocr.ocr(img_path, cls=True)
    result = result[0]
    image = Image.open(img_path).convert('RGB')
    boxes = [line[0] for line in result]
    txts = [line[1][0] for line in result]
    scores = [line[1][1] for line in result]
    im_show = draw_ocr(image, boxes, txts, scores, font_path='doc/fonts/simfang.ttf')
    im_show = Image.fromarray(im_show)
    im_show.save(output_path)
    # print(os.path.abspath(output_path))
    return " ".join(txts)


def baidu_erniebot(input_content):
    erniebot.api_type = "aistudio"
    erniebot.access_token = "1234567890"
    response = erniebot.ChatCompletion.create(model="ernie-3.5", messages=[{"role": "user", "content": input_content}])
    return response.get_result()


def getScore(input_path, question, total_score):
    input_content = "题目:" + question + "答案:" + baidu_paddleocr(
        input_path) + "总分:" + total_score + "分。请以”分数:数字+分,评语:评语”的格式给出回复。"
    return baidu_erniebot(input_content)


if __name__ == "__main__":
    if len(sys.argv) == 4:
        input_path = sys.argv[1]
        question = sys.argv[2]
        total_score = sys.argv[3]
        print(getScore(input_path, question, total_score))
    else:
        print("ERROR")
'''
D:\softdata\Anaconda_envs\envs\paddle_env\python.exe D:\develop\PycharmProjects\paddle\test4.py D:\\test0114.png 123456 5

'''
复制代码

 

posted @ 2024-01-28 20:15  风·华正茂  阅读(9)  评论(0编辑  收藏  举报