Spaces:
Sleeping
Sleeping
Rename outerElectronFl.py to app.py
Browse files- app.py +105 -0
- outerElectronFl.py +0 -43
app.py
ADDED
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
|
4 |
+
def main():
|
5 |
+
st.title("集合操作アプリ")
|
6 |
+
|
7 |
+
# メニューの選択
|
8 |
+
option = st.sidebar.selectbox("機能を選択してください", ["集合の操作", "全体集合の生成", "補集合の計算", "不等式の計算"])
|
9 |
+
|
10 |
+
if option == "集合の操作":
|
11 |
+
set_operations()
|
12 |
+
elif option == "全体集合の生成":
|
13 |
+
generate_universe()
|
14 |
+
elif option == "補集合の計算":
|
15 |
+
complement_operation()
|
16 |
+
elif option == "不等式の計算":
|
17 |
+
inequality_solver()
|
18 |
+
|
19 |
+
def set_operations():
|
20 |
+
st.header("集合の操作")
|
21 |
+
|
22 |
+
with st.form(key='set_operations_form'):
|
23 |
+
set1 = st.text_input("集合1 (カンマ区切りで要素を入力してください)", "1,2,3")
|
24 |
+
set2 = st.text_input("集合2 (カンマ区切りで要素を入力してください)", "3,4,5")
|
25 |
+
set3 = st.text_input("集合3 (カンマ区切りで要素を入力してください)", "5,6,7")
|
26 |
+
submit_button = st.form_submit_button(label='実行')
|
27 |
+
|
28 |
+
if submit_button:
|
29 |
+
response = requests.post("http://127.0.0.1:8000/set_operations", json={
|
30 |
+
"set1": set1,
|
31 |
+
"set2": set2,
|
32 |
+
"set3": set3
|
33 |
+
})
|
34 |
+
if response.status_code == 200:
|
35 |
+
result = response.json()
|
36 |
+
st.subheader("集合の操作結果")
|
37 |
+
st.write("和集合:", result["union"])
|
38 |
+
st.write("積集合:", result["intersection"])
|
39 |
+
st.write("差集合:", result["difference"])
|
40 |
+
st.write("対称差:", result["symmetric_difference"])
|
41 |
+
else:
|
42 |
+
st.error(response.json()["detail"])
|
43 |
+
|
44 |
+
def generate_universe():
|
45 |
+
st.header("全体集合の生成")
|
46 |
+
|
47 |
+
with st.form(key='generate_universe_form'):
|
48 |
+
initial_value = st.number_input("初期値", value=0)
|
49 |
+
step = st.number_input("ステップ", value=1)
|
50 |
+
num_steps = st.number_input("回数", value=10, min_value=1)
|
51 |
+
submit_button = st.form_submit_button(label='生成')
|
52 |
+
|
53 |
+
if submit_button:
|
54 |
+
response = requests.post("http://127.0.0.1:8000/generate_universe", json={
|
55 |
+
"initial_value": initial_value,
|
56 |
+
"step": step,
|
57 |
+
"num_steps": num_steps
|
58 |
+
})
|
59 |
+
if response.status_code == 200:
|
60 |
+
result = response.json()
|
61 |
+
st.subheader("生成された全体集合")
|
62 |
+
st.write(result["universe_set"])
|
63 |
+
else:
|
64 |
+
st.error(response.json()["detail"])
|
65 |
+
|
66 |
+
def complement_operation():
|
67 |
+
st.header("補集合の計算")
|
68 |
+
|
69 |
+
with st.form(key='complement_operation_form'):
|
70 |
+
universe = st.text_input("全体集合 (カンマ区切りで要素を入力してください)", "1,2,3,4,5,6,7,8,9,10")
|
71 |
+
target_set = st.text_input("対象集合 (カンマ区切りで要素を入力してください)", "1,3,5")
|
72 |
+
submit_button = st.form_submit_button(label='計算')
|
73 |
+
|
74 |
+
if submit_button:
|
75 |
+
response = requests.post("http://127.0.0.1:8000/complement_operation", json={
|
76 |
+
"universe": universe,
|
77 |
+
"target_set": target_set
|
78 |
+
})
|
79 |
+
if response.status_code == 200:
|
80 |
+
result = response.json()
|
81 |
+
st.subheader("補集合の計算結果")
|
82 |
+
st.write(result["complement"])
|
83 |
+
else:
|
84 |
+
st.error(response.json()["detail"])
|
85 |
+
|
86 |
+
def inequality_solver():
|
87 |
+
st.header("不等式の計算")
|
88 |
+
|
89 |
+
with st.form(key='inequality_solver_form'):
|
90 |
+
inequality_input = st.text_input("不等式を入力してください", "2*x >= 2")
|
91 |
+
submit_button = st.form_submit_button(label='解を求める')
|
92 |
+
|
93 |
+
if submit_button:
|
94 |
+
response = requests.post("http://127.0.0.1:8000/inequality_solver", json={
|
95 |
+
"inequality": inequality_input
|
96 |
+
})
|
97 |
+
if response.status_code == 200:
|
98 |
+
result = response.json()
|
99 |
+
st.subheader("不等式の解")
|
100 |
+
st.write(result["solution"])
|
101 |
+
else:
|
102 |
+
st.error(response.json()["detail"])
|
103 |
+
|
104 |
+
if __name__ == "__main__":
|
105 |
+
main()
|
outerElectronFl.py
DELETED
@@ -1,43 +0,0 @@
|
|
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")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|