Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- .gitattributes +1 -0
- workbook.db +0 -0
- workbook_server.py +9 -7
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
workbook.db filter=lfs diff=lfs merge=lfs -text
|
workbook.db
CHANGED
Binary files a/workbook.db and b/workbook.db differ
|
|
workbook_server.py
CHANGED
@@ -55,23 +55,24 @@ class ChapterRequest(BaseModel):
|
|
55 |
def get_questions_by_chapter(request: ChapterRequest):
|
56 |
db = get_db()
|
57 |
cursor = db.cursor()
|
58 |
-
cursor.execute("SELECT question, options, answer, explain FROM question WHERE chapter = ? AND kind = '正誤問題'", (request.chapter_number,))
|
59 |
questions = cursor.fetchall()
|
60 |
if not questions:
|
61 |
raise HTTPException(status_code=404, detail="Questions not found for the given chapter number")
|
62 |
question_list = []
|
63 |
for row in questions:
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
|
|
69 |
question_list.append({
|
70 |
"question_text": row[0],
|
71 |
"options": row[1],
|
72 |
"answer": row[2],
|
73 |
"explanation": row[3],
|
74 |
-
|
75 |
})
|
76 |
return JSONResponse(content=question_list)
|
77 |
|
@@ -83,6 +84,7 @@ class HintRequest(BaseModel):
|
|
83 |
@app.post('/api/hint')
|
84 |
def generate_hint(request: HintRequest):
|
85 |
prompt = f"設問: {request.question_text}\n選択肢: {request.options}\n正解: {request.answer}\nこの設問に対するヒントを生成してください。なおレスポンスはヒント文章のみとせよ。冒頭に「ヒント:」などの見出しをつけるな。"
|
|
|
86 |
try:
|
87 |
response = client.chat.completions.create(
|
88 |
model="gpt-4o-mini",
|
|
|
55 |
def get_questions_by_chapter(request: ChapterRequest):
|
56 |
db = get_db()
|
57 |
cursor = db.cursor()
|
58 |
+
cursor.execute("SELECT question, options, answer, explain, image FROM question WHERE chapter = ? AND kind = '正誤問題'", (request.chapter_number,))
|
59 |
questions = cursor.fetchall()
|
60 |
if not questions:
|
61 |
raise HTTPException(status_code=404, detail="Questions not found for the given chapter number")
|
62 |
question_list = []
|
63 |
for row in questions:
|
64 |
+
if row[4] is None:
|
65 |
+
encoded_string = ''
|
66 |
+
else:
|
67 |
+
image_path = os.path.join('./image', row[4])
|
68 |
+
with open(image_path, "rb") as image_file:
|
69 |
+
encoded_string = base64.b64encode(image_file.read()).decode('utf-8')
|
70 |
question_list.append({
|
71 |
"question_text": row[0],
|
72 |
"options": row[1],
|
73 |
"answer": row[2],
|
74 |
"explanation": row[3],
|
75 |
+
"image": encoded_string,
|
76 |
})
|
77 |
return JSONResponse(content=question_list)
|
78 |
|
|
|
84 |
@app.post('/api/hint')
|
85 |
def generate_hint(request: HintRequest):
|
86 |
prompt = f"設問: {request.question_text}\n選択肢: {request.options}\n正解: {request.answer}\nこの設問に対するヒントを生成してください。なおレスポンスはヒント文章のみとせよ。冒頭に「ヒント:」などの見出しをつけるな。"
|
87 |
+
print(prompt)
|
88 |
try:
|
89 |
response = client.chat.completions.create(
|
90 |
model="gpt-4o-mini",
|