Spaces:
Sleeping
Sleeping
| 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() | |