Wendgan commited on
Commit
79d9148
·
verified ·
1 Parent(s): af455ac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -34
app.py CHANGED
@@ -2,44 +2,34 @@ import os
2
  import gradio as gr
3
  import google.generativeai as genai
4
 
5
- genai.configure(api_key=os.getenv("AIzaSyCqh6P7W0kX7Hkeo-j280RBZLk6ddxx9CU"))
 
6
 
7
- def generate_distractors(question):
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
- Format:
17
- Correct Answer: ...
18
- Distractor 1: ...
19
- Explanation 1: ...
20
- Distractor 2: ...
21
- Explanation 2: ...
22
- Distractor 3: ...
23
- Explanation 3: ...
24
 
25
  Question: {question}
26
  """
27
- model = genai.GenerativeModel("gemini-1.5-flash")
28
- response = model.generate_content(prompt)
29
- return response.text.strip()
30
-
31
- with gr.Blocks() as demo:
32
- gr.Markdown("## Confusing Distractor Generator")
33
- gr.Markdown("Enter a multiple-choice question. The model will generate one correct answer, three plausible distractors, and explanations.")
34
-
35
- with gr.Row():
36
- question = gr.Textbox(label="MCQ Question", placeholder="Enter your question here", lines=2)
37
- with gr.Row():
38
- generate_btn = gr.Button("Generate")
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
- demo.launch()
 
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()