Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,66 +1,43 @@
|
|
1 |
-
from
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
app =
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
@app.post("/set_operations/")
|
25 |
-
def set_operations(input_data: SetOperationInput):
|
26 |
-
set1 = set(input_data.set1)
|
27 |
-
set2 = set(input_data.set2)
|
28 |
-
set3 = set(input_data.set3)
|
29 |
|
30 |
-
result =
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
36 |
|
37 |
-
return result
|
38 |
|
39 |
-
@app.
|
40 |
-
def
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
universe_set = list(range(initial_value, initial_value + step * num_steps, step))
|
45 |
-
|
46 |
-
return {"universe": universe_set}
|
47 |
-
|
48 |
-
@app.post("/complement_operation/")
|
49 |
-
def complement_operation(input_data: ComplementInput):
|
50 |
-
universe_set = set(input_data.universe)
|
51 |
-
target_set = set(input_data.target_set)
|
52 |
-
complement = list(universe_set.difference(target_set))
|
53 |
-
|
54 |
-
return {"complement": complement}
|
55 |
-
|
56 |
-
@app.post("/inequality_solver/")
|
57 |
-
def inequality_solver(input_data: InequalityInput):
|
58 |
-
x = symbols('x')
|
59 |
-
inequality = eval(input_data.inequality)
|
60 |
-
solution = solve(inequality, x)
|
61 |
-
|
62 |
-
return {"solution": str(solution)}
|
63 |
|
64 |
-
if __name__ ==
|
65 |
-
|
66 |
-
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
1 |
+
from flask import Flask, render_template, request, redirect, url_for, session
|
2 |
+
import random
|
3 |
+
|
4 |
+
app = Flask(__name__)
|
5 |
+
app.secret_key = 'your_secret_key_here' # セッションの安全な署名に必要なキー
|
6 |
+
|
7 |
+
capitals = {
|
8 |
+
'H': 1, 'He': 2,
|
9 |
+
'Li': 3, 'Be': 4, 'B': 5, 'C': 6, 'N': 7, 'O': 8, 'F': 9, 'Ne': 10,
|
10 |
+
'Na': 11, 'Mg': 12, 'Al': 13, 'Si': 14, 'P': 15, 'S': 16, 'Cl': 17,
|
11 |
+
'K': 19, 'Ca': 20, 'Sc': 21,'Cr': 24, 'Mn': 25, 'Fe': 26, 'Co': 27, 'Ni': 28, 'Cu': 29, 'Zn': 30,
|
12 |
+
'Ga': 31, 'Ge': 32, 'As': 33, 'Se': 34, 'Br': 35, 'Pd': 46, 'Ag': 47,
|
13 |
+
'I': 53,
|
14 |
+
}
|
15 |
+
|
16 |
+
def get_random_country():
|
17 |
+
country = random.choice(list(capitals.keys()))
|
18 |
+
return country, capitals[country]
|
19 |
+
|
20 |
+
@app.route('/', methods=['GET', 'POST'])
|
21 |
+
def quiz():
|
22 |
+
if 'current_化合物' not in session: # セッションに現在の化合物がない場合は新しいものを取得
|
23 |
+
session['current_化合物'], session['current_化合物名'] = get_random_country()
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
+
result = None
|
26 |
+
|
27 |
+
if request.method == 'POST':
|
28 |
+
user_input = int(request.form['user_input'])
|
29 |
+
if user_input == session['current_化合物名']:
|
30 |
+
result = '正解です!'
|
31 |
+
else:
|
32 |
+
result = '不正解です。正解は{}です。'.format(session['current_化合物名'])
|
33 |
|
34 |
+
return render_template('quiz.html', element=session['current_化合物'], result=result)
|
35 |
|
36 |
+
@app.route('/next', methods=['POST'])
|
37 |
+
def next_question():
|
38 |
+
session.pop('current_化合物') # 現在の化合物をセッションから削除
|
39 |
+
session.pop('current_化合物名')
|
40 |
+
return redirect(url_for('quiz'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
+
if __name__ == '__main__':
|
43 |
+
app.run(debug=True, port=7860, host="0.0.0.0")
|
|