add students for verification, update prompt for qwen and update Report.md

This commit is contained in:
chubinho 2026-04-02 21:58:08 +03:00
parent 710e9a8b64
commit 3c87f998dd
31 changed files with 632 additions and 86 deletions

View file

@ -4,26 +4,35 @@ import time
from dotenv import load_dotenv
from openai import OpenAI
import httpx
from PIL import Image
load_dotenv()
# Наш финальный список "выживших"
MODELS_TO_TEST = [
"openai/claude-opus-4-6",
"openai/gpt-4o",
"openai/gpt-5-pro"
"qwen3.5-122b"
]
client = OpenAI(
api_key=os.getenv("LAOZHANG_API_KEY"),
api_key=os.getenv("API_KEY"),
base_url=os.getenv("LAOZHANG_BASE_URL"),
http_client=httpx.Client(timeout=httpx.Timeout(600.0, connect=30.0))
)
def encode_image(image_path):
with open(image_path, "rb") as img:
return base64.b64encode(img.read()).decode('utf-8')
"""Кодирует изображение в base64, конвертируя TIFF в JPEG при необходимости"""
if image_path.lower().endswith('.tif') or image_path.lower().endswith('.tiff'):
with Image.open(image_path) as img:
if img.mode not in ('RGB', 'L'):
img = img.convert('RGB')
import io
buffer = io.BytesIO()
img.save(buffer, format='JPEG', quality=95)
buffer.seek(0)
return base64.b64encode(buffer.read()).decode('utf-8')
else:
with open(image_path, "rb") as img:
return base64.b64encode(img.read()).decode('utf-8')
def get_instructions(criteria_file):
@ -36,9 +45,9 @@ def get_instructions(criteria_file):
def run_mass_check(base_dir="photo", criteria_file="russian-essay-criteria.md"):
# 1. Находим все папки учеников
students = [d for d in os.listdir(
base_dir) if os.path.isdir(os.path.join(base_dir, d))]
if not students:
print("[!] В папке photo пусто. Создай там папки с именами учеников.")
return
@ -49,7 +58,7 @@ def run_mass_check(base_dir="photo", criteria_file="russian-essay-criteria.md"):
for student in students:
student_path = os.path.join(base_dir, student)
photos = sorted([f for f in os.listdir(student_path)
if f.lower().endswith(('.jpg', '.jpeg', '.png'))])
if f.lower().endswith(('.jpg', '.jpeg', '.png', '.tif', '.tiff'))])
if not photos:
print(f"[SKIP] У {student} нет фото.")
@ -57,9 +66,9 @@ def run_mass_check(base_dir="photo", criteria_file="russian-essay-criteria.md"):
print(f"\n>>> РАБОТАЕМ С: {student.upper()} ({len(photos)} листа)")
# Подготовка контента ОДИН РАЗ для всех моделей (экономим время)
message_content = [
{"type": "text", "text": "Распознай рукописный текст и проверь сочинение строго по критериям ФИПИ."}]
for p in photos:
b64 = encode_image(os.path.join(student_path, p))
message_content.append({
@ -69,10 +78,16 @@ def run_mass_check(base_dir="photo", criteria_file="russian-essay-criteria.md"):
for model_id in MODELS_TO_TEST:
safe_name = model_id.replace("/", "_")
output_file = f"REPORT_{student}_{safe_name}.md"
# Проверка: если файл уже есть — пропускаем
if os.path.exists(output_file):
# ✅ ОТРЕДАКТИРОВАНО: отчёт сохраняется ВНУТРЬ папки ученика
output_file = os.path.join(student_path, f"REPORT_{safe_name}.md")
old_file = os.path.join(
student_path, f"REPORT_{student}_{safe_name}.md")
new_file = os.path.join(student_path, f"REPORT_{safe_name}.md")
if os.path.exists(old_file) or os.path.exists(new_file):
print(f" [-] {model_id}: Уже проверено.")
continue
@ -97,7 +112,8 @@ def run_mass_check(base_dir="photo", criteria_file="russian-essay-criteria.md"):
f.write(header + res_text)
print(f" [OK] Готово! ({duration} сек.)")
time.sleep(12) # Безопасная пауза для лимитов
print(f" 📁 Сохранено: {output_file}")
time.sleep(12)
except Exception as e:
print(f" [ERR] Ошибка у {model_id}: {str(e)}")