Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import random
|
| 3 |
+
|
| 4 |
+
# Simple quiz questions and answers
|
| 5 |
+
questions = {
|
| 6 |
+
"Geography": [
|
| 7 |
+
{"question": "What is the capital of France?", "options": ["Berlin", "Madrid", "Paris", "Rome"], "answer": "Paris"},
|
| 8 |
+
{"question": "Which is the largest continent?", "options": ["Asia", "Africa", "Europe", "Australia"], "answer": "Asia"},
|
| 9 |
+
{"question": "What is the tallest mountain?", "options": ["Mount Everest", "K2", "Kangchenjunga", "Makalu"], "answer": "Mount Everest"}
|
| 10 |
+
],
|
| 11 |
+
"Science": [
|
| 12 |
+
{"question": "What is the chemical symbol for water?", "options": ["O2", "CO2", "H2O", "HO2"], "answer": "H2O"},
|
| 13 |
+
{"question": "What planet is known as the Red Planet?", "options": ["Mars", "Venus", "Jupiter", "Saturn"], "answer": "Mars"},
|
| 14 |
+
{"question": "What gas do plants absorb from the atmosphere?", "options": ["Oxygen", "Nitrogen", "Carbon Dioxide", "Hydrogen"], "answer": "Carbon Dioxide"}
|
| 15 |
+
],
|
| 16 |
+
"Math": [
|
| 17 |
+
{"question": "What is 5 + 5?", "options": ["10", "12", "14", "15"], "answer": "10"},
|
| 18 |
+
{"question": "What is 12 * 12?", "options": ["144", "100", "130", "110"], "answer": "144"},
|
| 19 |
+
{"question": "What is the square root of 64?", "options": ["6", "8", "10", "12"], "answer": "8"}
|
| 20 |
+
]
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
# Function to generate random quiz based on topic
|
| 24 |
+
def generate_quiz(topic):
|
| 25 |
+
if topic not in questions:
|
| 26 |
+
return "Topic not available. Please try 'Geography', 'Science', or 'Math'."
|
| 27 |
+
|
| 28 |
+
quiz = random.sample(questions[topic], 3) # Select 3 random questions from the topic
|
| 29 |
+
question_list = []
|
| 30 |
+
|
| 31 |
+
for q in quiz:
|
| 32 |
+
question_list.append({
|
| 33 |
+
"question": q["question"],
|
| 34 |
+
"options": q["options"],
|
| 35 |
+
"answer": q["answer"]
|
| 36 |
+
})
|
| 37 |
+
|
| 38 |
+
return question_list
|
| 39 |
+
|
| 40 |
+
# Gradio Interface
|
| 41 |
+
iface = gr.Interface(
|
| 42 |
+
fn=generate_quiz,
|
| 43 |
+
inputs=gr.Textbox(placeholder="Enter a topic like Geography, Science, or Math", label="Topic"),
|
| 44 |
+
outputs=gr.JSON(label="Quiz Questions"),
|
| 45 |
+
title="Simple Quiz Generator",
|
| 46 |
+
description="Enter a subject like 'Geography', 'Science', or 'Math' to get a random quiz."
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
iface.launch()
|