OzoneAsai commited on
Commit
1c0f4ec
·
verified ·
1 Parent(s): 7079af5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -62
app.py CHANGED
@@ -1,66 +1,43 @@
1
- from fastapi import FastAPI
2
- from pydantic import BaseModel
3
- from typing import List, Set
4
-
5
- app = FastAPI()
6
-
7
- class SetOperationInput(BaseModel):
8
- set1: List[int]
9
- set2: List[int]
10
- set3: List[int]
11
-
12
- class UniverseInput(BaseModel):
13
- initial_value: int
14
- step: int
15
- num_steps: int
16
-
17
- class ComplementInput(BaseModel):
18
- universe: List[int]
19
- target_set: List[int]
20
-
21
- class InequalityInput(BaseModel):
22
- inequality: str
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
- "union": list(set1.union(set2, set3)),
32
- "intersection": list(set1.intersection(set2, set3)),
33
- "difference": list(set1.difference(set2, set3)),
34
- "symmetric_difference": list(set1.symmetric_difference(set2))
35
- }
 
 
36
 
37
- return result
38
 
39
- @app.post("/generate_universe/")
40
- def generate_universe(input_data: UniverseInput):
41
- initial_value = input_data.initial_value
42
- step = input_data.step
43
- num_steps = input_data.num_steps
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__ == "__main__":
65
- import uvicorn
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")