Fausto Busuito
commited on
Commit
•
ae9e436
1
Parent(s):
64025c3
Application changes
Browse files- README.md +0 -15
- app.py +4 -48
- requirements.txt +1 -2
- static/script.js +0 -2
- static/styles.css +0 -16
- templates/index.html +0 -21
- templates/quiz.html +0 -20
- templates/results.html +0 -23
README.md
DELETED
@@ -1,15 +0,0 @@
|
|
1 |
-
---
|
2 |
-
title: Real Time Quiz Application
|
3 |
-
emoji: 🔥
|
4 |
-
colorFrom: green
|
5 |
-
colorTo: pink
|
6 |
-
sdk: docker
|
7 |
-
pinned: false
|
8 |
-
short_description: 'About A Python-based real-time quiz application designed to '
|
9 |
-
---
|
10 |
-
|
11 |
-
A Python-based real-time quiz application designed to mimic the functionality of Mentimeter, allowing a host to control the quiz and participants (clients) to join, answer questions, and receive immediate feedback. The application is built using Flask and Socket.IO for seamless web-based interaction, and it offers a clean, responsive front-end using HTML, CSS, and Bootstrap.
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
@@ -1,54 +1,10 @@
|
|
1 |
-
from flask import Flask
|
2 |
-
import json
|
3 |
-
import random
|
4 |
-
import os
|
5 |
|
6 |
app = Flask(__name__)
|
7 |
-
app.secret_key = 'supersecretkey'
|
8 |
|
9 |
@app.route('/')
|
10 |
-
def
|
11 |
-
return
|
12 |
-
|
13 |
-
@app.route('/start', methods=['POST'])
|
14 |
-
def start():
|
15 |
-
session['name'] = request.form['name']
|
16 |
-
session['questions'] = load_questions(request.files['questions'])
|
17 |
-
session['current_question'] = 0
|
18 |
-
session['answers'] = []
|
19 |
-
return redirect(url_for('quiz'))
|
20 |
-
|
21 |
-
@app.route('/quiz', methods=['GET', 'POST'])
|
22 |
-
def quiz():
|
23 |
-
if request.method == 'POST':
|
24 |
-
session['answers'].append(request.form.get('answer'))
|
25 |
-
session['current_question'] += 1
|
26 |
-
if session['current_question'] >= len(session['questions']):
|
27 |
-
return redirect(url_for('results'))
|
28 |
-
return redirect(url_for('quiz'))
|
29 |
-
|
30 |
-
question = session['questions'][session['current_question']]
|
31 |
-
return render_template('quiz.html', question=question)
|
32 |
-
|
33 |
-
@app.route('/results')
|
34 |
-
def results():
|
35 |
-
questions = session['questions']
|
36 |
-
answers = session['answers']
|
37 |
-
score = calculate_score(questions, answers)
|
38 |
-
return render_template('results.html', score=score, questions=questions, answers=answers)
|
39 |
-
|
40 |
-
def load_questions(file):
|
41 |
-
print(">>>>>>>>>>>>>>>>>>>>>>>>>>" + str(file))
|
42 |
-
questions = json.load(file)
|
43 |
-
random.shuffle(questions)
|
44 |
-
return questions
|
45 |
-
|
46 |
-
def calculate_score(questions, answers):
|
47 |
-
correct_count = 0
|
48 |
-
for i, question in enumerate(questions):
|
49 |
-
if answers[i] in question['correct']:
|
50 |
-
correct_count += 1
|
51 |
-
return (correct_count / len(questions)) * 100
|
52 |
|
53 |
if __name__ == '__main__':
|
54 |
-
app.run(
|
|
|
1 |
+
from flask import Flask
|
|
|
|
|
|
|
2 |
|
3 |
app = Flask(__name__)
|
|
|
4 |
|
5 |
@app.route('/')
|
6 |
+
def hello_world():
|
7 |
+
return 'Hello, World!'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
if __name__ == '__main__':
|
10 |
+
app.run(host='0.0.0.0', port=5000)
|
requirements.txt
CHANGED
@@ -1,2 +1 @@
|
|
1 |
-
Flask==2.0.1
|
2 |
-
Werkzeug==2.0.1
|
|
|
1 |
+
Flask==2.0.1
|
|
static/script.js
DELETED
@@ -1,2 +0,0 @@
|
|
1 |
-
javascript
|
2 |
-
// This file can be used for any client-side JavaScript if needed.
|
|
|
|
|
|
static/styles.css
DELETED
@@ -1,16 +0,0 @@
|
|
1 |
-
body {
|
2 |
-
font-family: Arial, sans-serif;
|
3 |
-
margin: 20px;
|
4 |
-
}
|
5 |
-
|
6 |
-
h1 {
|
7 |
-
color: #333;
|
8 |
-
}
|
9 |
-
|
10 |
-
form {
|
11 |
-
margin-top: 20px;
|
12 |
-
}
|
13 |
-
|
14 |
-
button {
|
15 |
-
margin-top: 10px;
|
16 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
templates/index.html
DELETED
@@ -1,21 +0,0 @@
|
|
1 |
-
<!DOCTYPE html>
|
2 |
-
<html lang="en">
|
3 |
-
<head>
|
4 |
-
<meta charset="UTF-8">
|
5 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
-
<title>Quiz App</title>
|
7 |
-
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
|
8 |
-
</head>
|
9 |
-
<body>
|
10 |
-
<h1>Welcome to the Quiz App</h1>
|
11 |
-
<form action="/start" method="post" enctype="multipart/form-data">
|
12 |
-
<label for="name">Enter your name:</label>
|
13 |
-
<input type="text" id="name" name="name" required>
|
14 |
-
<br>
|
15 |
-
<label for="questions">Upload questions file:</label>
|
16 |
-
<input type="file" id="questions" name="questions" required>
|
17 |
-
<br>
|
18 |
-
<button type="submit">Start Quiz</button>
|
19 |
-
</form>
|
20 |
-
</body>
|
21 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
templates/quiz.html
DELETED
@@ -1,20 +0,0 @@
|
|
1 |
-
<!DOCTYPE html>
|
2 |
-
<html lang="en">
|
3 |
-
<head>
|
4 |
-
<meta charset="UTF-8">
|
5 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
-
<title>Quiz</title>
|
7 |
-
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
|
8 |
-
</head>
|
9 |
-
<body>
|
10 |
-
<h1>Question {{ session['current_question'] + 1 }}</h1>
|
11 |
-
<p>{{ question['question'] }}</p>
|
12 |
-
<form action="/quiz" method="post">
|
13 |
-
{% for option in question['options'] %}
|
14 |
-
<input type="radio" id="{{ loop.index }}" name="answer" value="{{ loop.index }}" required>
|
15 |
-
<label for="{{ loop.index }}">{{ option }}</label><br>
|
16 |
-
{% endfor %}
|
17 |
-
<button type="submit">Next</button>
|
18 |
-
</form>
|
19 |
-
</body>
|
20 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
templates/results.html
DELETED
@@ -1,23 +0,0 @@
|
|
1 |
-
<!DOCTYPE html>
|
2 |
-
<html lang="en">
|
3 |
-
<head>
|
4 |
-
<meta charset="UTF-8">
|
5 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
-
<title>Results</title>
|
7 |
-
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
|
8 |
-
</head>
|
9 |
-
<body>
|
10 |
-
<h1>Results</h1>
|
11 |
-
<p>Your score: {{ score }}%</p>
|
12 |
-
<h2>Your Answers</h2>
|
13 |
-
<ul>
|
14 |
-
{% for i, question in enumerate(questions) %}
|
15 |
-
<li>
|
16 |
-
<p>{{ question['question'] }}</p>
|
17 |
-
<p>Your answer: {{ answers[i] }}</p>
|
18 |
-
<p>Correct answer: {{ question['correct'] }}</p>
|
19 |
-
</li>
|
20 |
-
{% endfor %}
|
21 |
-
</ul>
|
22 |
-
</body>
|
23 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|