import gradio as gr def handler(sel, temp): if sel == '攝氏': c=temp f=int(c*9/5 + 32) msg=f'攝氏 {c} 度=華氏 {f} 度' else: f=temp c=int((f-32)*5/9) msg=f'華氏 {f} 度=攝氏 {c} 度' return msg sel=gr.Radio(label='溫度制', value='攝氏', choices=['攝氏', '華氏']) temp=gr.Slider(label='溫度', value=0, minimum=-100, maximum=100) output=gr.Textbox(label='轉換結果') iface=gr.Interface( fn=handler, inputs=[sel, temp], outputs=[output], title='攝氏與華氏溫度轉換', description='請選擇溫度制與移動溫度滑桿', allow_flagging='never', article='攝氏轉華氏公式 : f=c*9/5 + 32
' +\ '華氏轉攝氏公式 : c=(f-32)*5/9', live=True ) iface.launch()