main
HuangHai 2 weeks ago
parent ebd5b08933
commit c7af163b7a

Before

Width:  |  Height:  |  Size: 148 KiB

After

Width:  |  Height:  |  Size: 148 KiB

@ -1,16 +1,11 @@
import os
from openai import OpenAI from openai import OpenAI
client = OpenAI( client = OpenAI(
# 若没有配置环境变量请用百炼API Key将下行替换为api_key="sk-xxx",
api_key='sk-f6da0c787eff4b0389e4ad03a35a911f', api_key='sk-f6da0c787eff4b0389e4ad03a35a911f',
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1", base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
) )
prompt = "请提取图片中的试题" prompt = "请提取图片中的试题"
#prompt += "1、需要Latex公式输出的注意加上 $$ 或 $ 进行包含。"
#prompt += "2、以中文数字开头的行请忽律掉此行比如 一、单项选择题 二、填空题 ..."
#prompt += "3、输出格式 【题型】xxx 【题目内容】 xxx 【答案】 xxxx 【解析】 xxxx。"
completion = client.chat.completions.create( completion = client.chat.completions.create(
model="qwen-vl-ocr-latest", model="qwen-vl-ocr-latest",
messages=[ messages=[
@ -36,7 +31,7 @@ completion = client.chat.completions.create(
print(completion.choices[0].message.content) print(completion.choices[0].message.content)
# 将返回的内容保存到 2、识别出结果.md 中 # 将返回的内容保存到 2、识别出结果.md 中
with open('2、识别出结果.md', 'w', encoding='utf-8') as f: with open('Res/2、识别出结果.md', 'w', encoding='utf-8') as f:
f.write(completion.choices[0].message.content) f.write(completion.choices[0].message.content)
print("保存成功!") print("保存成功!")

@ -1,4 +1,3 @@
import os
from openai import OpenAI from openai import OpenAI
try: try:
@ -8,7 +7,7 @@ try:
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1", base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
) )
# 读取md文件内容 # 读取md文件内容
with open("2、识别出结果.md", "r", encoding="utf-8") as f: with open("Res/2、识别出结果.md", "r", encoding="utf-8") as f:
text = f.read() text = f.read()
prompt = """ prompt = """
@ -38,7 +37,7 @@ try:
) )
print(completion.choices[0].message.content) print(completion.choices[0].message.content)
# 将上面的返回内容写入到文件 3、整理后的结果.md 中 # 将上面的返回内容写入到文件 3、整理后的结果.md 中
with open("3、整理后的结果.md", "w", encoding="utf-8") as f: with open("Res/3、整理后的结果.md", "w", encoding="utf-8") as f:
f.write(completion.choices[0].message.content) f.write(completion.choices[0].message.content)
print("保存成功!") print("保存成功!")
except Exception as e: except Exception as e:

Loading…
Cancel
Save