Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,44 +2,34 @@ import os
|
|
| 2 |
import gradio as gr
|
| 3 |
import google.generativeai as genai
|
| 4 |
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
prompt = f"""
|
| 9 |
-
You are an expert educator designing challenging multiple-choice questions.
|
| 10 |
-
|
| 11 |
-
Given a question, generate:
|
| 12 |
-
- One correct answer
|
| 13 |
-
- Three plausible distractors
|
| 14 |
-
- A brief explanation for why each distractor seems believable but is incorrect
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
|
| 25 |
Question: {question}
|
| 26 |
"""
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
with gr.Row():
|
| 40 |
-
output = gr.Textbox(label="Model Output", lines=15)
|
| 41 |
-
|
| 42 |
-
generate_btn.click(fn=generate_distractors, inputs=question, outputs=output)
|
| 43 |
|
| 44 |
if __name__ == "__main__":
|
| 45 |
-
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import google.generativeai as genai
|
| 4 |
|
| 5 |
+
GOOGLE_API_KEY = os.environ.get("AIzaSyCqh6P7W0kX7Hkeo-j280RBZLk6ddxx9CU")
|
| 6 |
+
genai.configure(api_key=GOOGLE_API_KEY)
|
| 7 |
|
| 8 |
+
model = genai.GenerativeModel("gemini-1.5-flash")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
def generate_distractors(question):
|
| 11 |
+
try:
|
| 12 |
+
prompt = f"""
|
| 13 |
+
You are a multiple-choice question assistant.
|
| 14 |
+
Generate:
|
| 15 |
+
1. The correct answer
|
| 16 |
+
2. Three confusing but incorrect distractors
|
| 17 |
+
3. One-line explanation for each distractor
|
| 18 |
|
| 19 |
Question: {question}
|
| 20 |
"""
|
| 21 |
+
response = model.generate_content(prompt)
|
| 22 |
+
return response.text
|
| 23 |
+
except Exception as e:
|
| 24 |
+
return f"❌ Error: {e}"
|
| 25 |
+
|
| 26 |
+
iface = gr.Interface(
|
| 27 |
+
fn=generate_distractors,
|
| 28 |
+
inputs=gr.Textbox(label="MCQ Question", placeholder="e.g., What is the capital of France?"),
|
| 29 |
+
outputs=gr.Textbox(label="Response"),
|
| 30 |
+
title="Confusing Distractor Generator",
|
| 31 |
+
description="Enter a multiple-choice question. This app uses Gemini to generate one correct answer, three distractors, and explanations."
|
| 32 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
if __name__ == "__main__":
|
| 35 |
+
iface.launch()
|