Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -44,35 +44,38 @@ materials = {
|
|
| 44 |
# ===== 問題生成 =====
|
| 45 |
def generate_question(text):
|
| 46 |
prompt = f"""
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
| 55 |
Passage:
|
| 56 |
{text}
|
| 57 |
"""
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
|
| 77 |
# ===== テスト初期化 =====
|
| 78 |
def start_test():
|
|
|
|
| 44 |
# ===== 問題生成 =====
|
| 45 |
def generate_question(text):
|
| 46 |
prompt = f"""
|
| 47 |
+
Read the following passage and generate ONE multiple-choice question with 4 options (A–D).
|
| 48 |
+
Clearly mark the correct answer in the format below.
|
| 49 |
+
Return ONLY in this format:
|
| 50 |
+
|
| 51 |
+
Q: <question text>
|
| 52 |
+
A. <option>
|
| 53 |
+
B. <option>
|
| 54 |
+
C. <option>
|
| 55 |
+
D. <option>
|
| 56 |
+
Correct: <A/B/C/D>
|
| 57 |
+
|
| 58 |
Passage:
|
| 59 |
{text}
|
| 60 |
"""
|
| 61 |
|
| 62 |
+
response = client.chat.completions.create(
|
| 63 |
+
model="google/gemma-3-27b-it:free",
|
| 64 |
+
messages=[{"role": "user", "content": prompt}],
|
| 65 |
+
max_tokens=400,
|
| 66 |
+
temperature=0.7,
|
| 67 |
+
)
|
| 68 |
+
full_output = response.choices[0].message.content.strip()
|
| 69 |
+
|
| 70 |
+
# --- 正解を抽出 ---
|
| 71 |
+
match = re.search(r"Correct:\s*([A-D])", full_output, re.IGNORECASE)
|
| 72 |
+
correct_option = match.group(1).upper() if match else None
|
| 73 |
+
|
| 74 |
+
# --- 「Correct:」行を削除して受験者には非表示にする ---
|
| 75 |
+
visible_question = re.sub(r"(?i)Correct:\s*[A-D]", "", full_output).strip()
|
| 76 |
+
|
| 77 |
+
return visible_question, correct_option
|
| 78 |
+
|
| 79 |
|
| 80 |
# ===== テスト初期化 =====
|
| 81 |
def start_test():
|