add project files
Browse files- app.py +25 -5
- src/__pycache__/check_backpack.cpython-37.pyc +0 -0
- src/__pycache__/gr_func.cpython-37.pyc +0 -0
- src/gr_func.py +3 -0
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from src.check_backpack import sort_yaocai
|
| 3 |
-
from src.gr_func import init,get_medicines,get_first_material,get_second_material,get_possible_material
|
| 4 |
|
| 5 |
medicine_list_init = init()
|
| 6 |
|
|
@@ -23,13 +23,23 @@ def medicine_select_acc_change(medicine_select_acc):
|
|
| 23 |
def run_btn_click(medicine_select,material_1_select,material_2_select):
|
| 24 |
rtn = medicine_select+"\n"
|
| 25 |
possible_material_list = get_possible_material(medicine_select,material_1_select,material_2_select)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
for index,(main_material,auxi_material,material_third_list) in enumerate(possible_material_list):
|
| 27 |
rtn += f"""### 选择{index+1}
|
| 28 |
- **主药**:{main_material}
|
| 29 |
- **药引**:{",".join(material_third_list)}
|
| 30 |
- **辅药**:{auxi_material}
|
| 31 |
"""
|
| 32 |
-
return rtn
|
| 33 |
|
| 34 |
def medicine_select_change(medicine_select):
|
| 35 |
a = get_first_material(medicine_select)
|
|
@@ -51,6 +61,10 @@ def material_2_grade_select_change(medicine_select,material_1_select,material_2_
|
|
| 51 |
a = get_second_material(medicine_select,material_1_select,material_2_grade_select,material_2_num)
|
| 52 |
return gr.Dropdown.update(choices=["无"]+a, value="无", visible=True)
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
with gr.Blocks() as demo:
|
| 55 |
with gr.Tab("丹药配方"):
|
| 56 |
gr.Markdown("选择你要炼制的丹药")
|
|
@@ -71,8 +85,12 @@ with gr.Blocks() as demo:
|
|
| 71 |
material_2_select = gr.Dropdown(visible=False,label="第二个药材")
|
| 72 |
|
| 73 |
run_btn = gr.Button("Run")
|
| 74 |
-
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
with gr.Tab("背包查询"):
|
| 78 |
gr.Markdown("复制全部药材到左边文本框")
|
|
@@ -104,7 +122,9 @@ with gr.Blocks() as demo:
|
|
| 104 |
material_2_grade_select.change(fn=material_2_grade_select_change,inputs=[medicine_select, material_1_select, material_2_grade_select, material_2_num],outputs=[material_2_select])
|
| 105 |
material_2_num.change(fn=material_2_grade_select_change,inputs=[medicine_select, material_1_select, material_2_grade_select, material_2_num],outputs=[material_2_select])
|
| 106 |
|
| 107 |
-
run_btn.click(fn=run_btn_click,inputs=[medicine_select,material_1_select,material_2_select],outputs=[output_mk])
|
|
|
|
|
|
|
| 108 |
|
| 109 |
# 背包
|
| 110 |
medicine_select_acc_b.change(fn=medicine_select_acc_change_b, inputs=[medicine_select_acc_b],
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from src.check_backpack import sort_yaocai
|
| 3 |
+
from src.gr_func import init,get_medicines,get_first_material,get_second_material,get_possible_material,get_basename
|
| 4 |
|
| 5 |
medicine_list_init = init()
|
| 6 |
|
|
|
|
| 23 |
def run_btn_click(medicine_select,material_1_select,material_2_select):
|
| 24 |
rtn = medicine_select+"\n"
|
| 25 |
possible_material_list = get_possible_material(medicine_select,material_1_select,material_2_select)
|
| 26 |
+
if len(possible_material_list) == 1:
|
| 27 |
+
main_material, auxi_material, material_third_list = possible_material_list[0]
|
| 28 |
+
rtn += f"""###
|
| 29 |
+
- **主药**:{main_material}
|
| 30 |
+
- **辅药**:{auxi_material}
|
| 31 |
+
"""
|
| 32 |
+
peifang = f"配方:主药{get_basename(main_material)}药引{get_basename(material_third_list[0])}辅药{get_basename(auxi_material)}丹炉陨铁炉"
|
| 33 |
+
return rtn,gr.Radio.update(choices=material_third_list,value=material_third_list[0],visible=True),gr.Markdown.update(visible=True,value=peifang),(main_material,auxi_material)
|
| 34 |
+
# else:
|
| 35 |
+
|
| 36 |
for index,(main_material,auxi_material,material_third_list) in enumerate(possible_material_list):
|
| 37 |
rtn += f"""### 选择{index+1}
|
| 38 |
- **主药**:{main_material}
|
| 39 |
- **药引**:{",".join(material_third_list)}
|
| 40 |
- **辅药**:{auxi_material}
|
| 41 |
"""
|
| 42 |
+
return rtn,gr.Radio.update(visible=False),gr.Markdown.update(visible=False,value=""),(main_material,auxi_material)
|
| 43 |
|
| 44 |
def medicine_select_change(medicine_select):
|
| 45 |
a = get_first_material(medicine_select)
|
|
|
|
| 61 |
a = get_second_material(medicine_select,material_1_select,material_2_grade_select,material_2_num)
|
| 62 |
return gr.Dropdown.update(choices=["无"]+a, value="无", visible=True)
|
| 63 |
|
| 64 |
+
def output_Radio_change(output_state,output_Radio):
|
| 65 |
+
main_material, auxi_material = output_state
|
| 66 |
+
return f"配方:主药{get_basename(main_material)}药引{get_basename(output_Radio)}辅药{get_basename(auxi_material)}丹炉陨铁炉"
|
| 67 |
+
|
| 68 |
with gr.Blocks() as demo:
|
| 69 |
with gr.Tab("丹药配方"):
|
| 70 |
gr.Markdown("选择你要炼制的丹药")
|
|
|
|
| 85 |
material_2_select = gr.Dropdown(visible=False,label="第二个药材")
|
| 86 |
|
| 87 |
run_btn = gr.Button("Run")
|
| 88 |
+
with gr.Column():
|
| 89 |
+
output_mk = gr.Markdown("输出结果")
|
| 90 |
+
with gr.Blocks():
|
| 91 |
+
output_Radio = gr.Radio(visible=False,label="药引")
|
| 92 |
+
output_state = gr.State((None,None))
|
| 93 |
+
output_end = gr.Markdown(visible=False)
|
| 94 |
|
| 95 |
with gr.Tab("背包查询"):
|
| 96 |
gr.Markdown("复制全部药材到左边文本框")
|
|
|
|
| 122 |
material_2_grade_select.change(fn=material_2_grade_select_change,inputs=[medicine_select, material_1_select, material_2_grade_select, material_2_num],outputs=[material_2_select])
|
| 123 |
material_2_num.change(fn=material_2_grade_select_change,inputs=[medicine_select, material_1_select, material_2_grade_select, material_2_num],outputs=[material_2_select])
|
| 124 |
|
| 125 |
+
run_btn.click(fn=run_btn_click,inputs=[medicine_select,material_1_select,material_2_select],outputs=[output_mk,output_Radio,output_end,output_state])
|
| 126 |
+
|
| 127 |
+
output_Radio.change(fn=output_Radio_change,inputs=[output_state,output_Radio],outputs=[output_end])
|
| 128 |
|
| 129 |
# 背包
|
| 130 |
medicine_select_acc_b.change(fn=medicine_select_acc_change_b, inputs=[medicine_select_acc_b],
|
src/__pycache__/check_backpack.cpython-37.pyc
ADDED
|
Binary file (2.61 kB). View file
|
|
|
src/__pycache__/gr_func.cpython-37.pyc
CHANGED
|
Binary files a/src/__pycache__/gr_func.cpython-37.pyc and b/src/__pycache__/gr_func.cpython-37.pyc differ
|
|
|
src/gr_func.py
CHANGED
|
@@ -163,6 +163,9 @@ def get_possible_material(medicine_select, first_material:str="无", second_mate
|
|
| 163 |
rtn.append((main_material,auxi_material,material_third_list))
|
| 164 |
return rtn
|
| 165 |
|
|
|
|
|
|
|
|
|
|
| 166 |
|
| 167 |
|
| 168 |
def init():
|
|
|
|
| 163 |
rtn.append((main_material,auxi_material,material_third_list))
|
| 164 |
return rtn
|
| 165 |
|
| 166 |
+
def get_basename(text):
|
| 167 |
+
name,num = text.split("*")
|
| 168 |
+
return name[:-4]+num
|
| 169 |
|
| 170 |
|
| 171 |
def init():
|