python+qwen api实现作业照片批改返回照片代码

代码语言:python

所属分类:其他

代码描述:python+qwen api实现作业照片批改返回照片代码,可在每一题后面通过红色与绿色点标注是否答对。

代码标签: python qwen api 作业 照片 批改 返回

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

#!/usr/local/python3/bin/python3
# -*- coding: utf-8 -*-
import os
import requests
import json
from PIL import Image, ImageDraw, ImageFont
from io import BytesIO

class HomeworkCorrector:
    def __init__(self, api_key):
        self.api_url = "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions"
        self.api_key = api_key
        self.font_path = "/data/wwwroot/default/asset/msyh.ttf"
    
    def call_ai_api(self, image_url):
        """调用大模型API分析作业图片"""
        messages = [
            {
                "role": "system",
                "content": '你是一个老师,请分析这张作业图片,找出所有题目并判断对错。对每个题目,请提供:1. 题目位置坐标(右下角xy坐标)2. 是否正确,以JSON格式返回。{"questions": [{"position": {"x": 100, "y": 200},"is_correct": true},...]}'
            },
            {
                "role": "user",
                "content": [
                    {"type": "text", "text": ""},
                    {"type": "image_url", "image_url": {"url": image_url}}
                ]
            }
        ]

        payload = {
            "model": "qwen-vl-max-latest",
            &q.........完整代码请登录后点击上方下载按钮下载查看

网友评论0