Spaces:
Sleeping
Sleeping
File size: 3,538 Bytes
d446497 772d32e d446497 772d32e d446497 772d32e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
import gradio as gr
import pandas as pd
# Define questions and answers
questions = [
("What is blockchain primarily described as in the image?",
["A centralized database", "A distributed ledger", "A cloud storage system", "A social media platform"], 1),
("What does the “immutable records” feature of blockchain mean?",
["Records can be changed easily", "Records cannot be altered once written", "Records are stored on a single server", "Records are deleted after a certain time"], 1),
("What type of system does blockchain use to operate?",
["Peer-to-peer system", "Client-server system", "Third-party system", "Cloud-based system"], 0),
("What does “trustless trust” in blockchain mean?",
["Trust is based on third parties", "Trust is built through math and code", "Trust is not needed at all", "Trust is only between two parties"], 1),
("According to the image, what happens in a trustless trust system?",
["Everyone has a copy, so there’s no single failure point", "Only one person has a copy of the data", "Third parties control the system", "The system fails if one person loses their copy"], 0),
("Which of the following is a security feature of blockchain mentioned in the image?",
["Centralized control", "Cryptographic hash", "Password protection", "Manual verification"], 1),
("What is one of the security features that ensures blockchain operates without a central authority?",
["Decentralization", "Centralization", "Password encryption", "Cloud storage"], 0),
("Which of the following is an application of blockchain shown in the image?",
["Social media posting", "Bitcoin", "Email services", "Video streaming"], 1),
("What is another application of blockchain mentioned in the image besides Bitcoin?",
["Cloud computing", "NFTs (Non-Fungible Tokens)", "Online gaming", "Web browsing"], 1),
("What mechanism helps blockchain nodes agree on the state of the ledger?",
["Consensus mechanisms", "Centralized voting", "Manual agreement", "Random selection"], 0)
]
# Initialize the DataFrame for storing quiz results
columns = ['Name', 'Score']
# Load the existing Excel file if it exists, or create a new one if not
try:
df = pd.read_excel('quiz_scores.xlsx')
except FileNotFoundError:
df = pd.DataFrame(columns=columns)
# Gradio interface function
def grade_quiz(name, *answers):
score = 0
feedback = ""
for i, answer in enumerate(answers):
correct = questions[i][2]
if answer == questions[i][1][correct]:
score += 1
feedback += f"Q{i+1}: Correct\n"
else:
feedback += f"Q{i+1}: Incorrect (Correct: {questions[i][1][correct]})\n"
# Save the user's result to the Excel file
new_data = pd.DataFrame({'Name': [name], 'Score': [score]})
global df
df = pd.concat([df, new_data], ignore_index=True)
df.drop_duplicates(subset='Name', keep='last', inplace=True)
df.to_excel('quiz_scores.xlsx', index=False) # Save to Excel
return f"Hello {name}, you scored {score} out of 10.\n\n{feedback}"
# Create input components
name_input = gr.Textbox(label="Enter your name:")
inputs = [name_input] + [gr.Radio(q[1], label=q[0]) for q in questions]
# Create Gradio interface
quiz_interface = gr.Interface(
fn=grade_quiz,
inputs=inputs,
outputs="text",
title="Blockchain Quiz",
theme="default"
)
# Launch the interface
quiz_interface.launch()
|