Wendgan commited on
Commit
80b28df
·
verified ·
1 Parent(s): adc6a9b

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +40 -12
  2. app.py +45 -0
  3. requirements.txt +3 -0
README.md CHANGED
@@ -1,12 +1,40 @@
1
- ---
2
- title: Distractor Generation
3
- emoji: 📚
4
- colorFrom: pink
5
- colorTo: red
6
- sdk: gradio
7
- sdk_version: 5.34.0
8
- app_file: app.py
9
- pinned: false
10
- ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # Gemini Distractor Generator
3
+
4
+ This is a simple web app that uses Gemini 1.5 Flash (via Gemini API) to generate multiple-choice distractors for a given question. It automatically identifies the correct answer and returns three plausible distractors.
5
+
6
+ ## Features
7
+ - Uses Gemini 1.5 Flash (Free Tier) via API
8
+ - Auto-generates distractors based on question context
9
+ - Also attempts to identify the correct answer
10
+ - Includes minimal Gradio UI
11
+
12
+ ## Files
13
+ - `app.py`: Main Gradio application.
14
+ - `requirements.txt`: Required Python libraries.
15
+ - `README.md`: This file.
16
+
17
+ ## How to Run
18
+
19
+ ### Locally
20
+ 1. Install the dependencies:
21
+ ```bash
22
+ pip install -r requirements.txt
23
+ ```
24
+
25
+ 2. Run the app:
26
+ ```bash
27
+ python app.py
28
+ ```
29
+
30
+ 3. Visit the local URL shown by Gradio.
31
+
32
+ ### On Hugging Face Spaces
33
+ 1. Upload all three files to your Hugging Face Space.
34
+ 2. Choose `Gradio` as the SDK.
35
+ 3. Make sure to set your Gemini API key in a secure way (e.g., using secrets or hardcoded for testing).
36
+ 4. Set `app.py` as the entry point.
37
+
38
+ ## Notes
39
+ - Gemini 1.5 Flash is selected to stay within free-tier quotas.
40
+ - You may need to set your API key inside `app.py` manually.
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ import google.generativeai as genai
4
+
5
+ genai.configure(api_key=os.getenv("AIzaSyDDPWejHT0yEyKW3QfF63dYaT3IPdKNuW0"))
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-2.0-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()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ google-generativeai>=0.3.2
2
+ gradio>=4.28.3
3
+ python-dotenv