diff --git a/app.py b/app.py index c11a7e3..a6e00b1 100644 --- a/app.py +++ b/app.py @@ -4,7 +4,7 @@ """ import gradio as gr -import numpy as np + from quantumpytho.engine import QuantumEngine from quantumpytho.modules.bloch_ascii import one_qubit_from_angles from quantumpytho.modules.circuit_explorer import bell_pair @@ -12,6 +12,7 @@ # Initialize quantum engine engine = QuantumEngine() + def bloch_sphere_demo(theta, phi): """Generate Bloch sphere ASCII visualization.""" try: @@ -20,40 +21,48 @@ def bloch_sphere_demo(theta, phi): except Exception as e: return f"Error: {str(e)}" + def create_bell_pair(): """Create a Bell pair and return circuit diagram.""" try: circuit = bell_pair() - return circuit.draw(output='text') + return circuit.draw(output="text") except Exception as e: return f"Error: {str(e)}" + def run_quantum_teleport(): """Run quantum teleportation demo.""" try: from quantumpytho.modules.teleport_bridge import build_teleport_circuit + circuit = build_teleport_circuit() result = engine.run(circuit) return f"Teleportation circuit executed successfully!\n\nCounts: {result}" except Exception as e: return f"Error: {str(e)}" + def run_qec_demo(code_type="Shor"): """Run Quantum Error Correction demo.""" try: if code_type == "Shor": from quantumpytho.modules.qec_shor import run_shor_qec_demo + return run_shor_qec_demo() else: from quantumpytho.modules.qec_steane import run_steane_qec_demo + return run_steane_qec_demo() except Exception as e: return f"Error: {str(e)}" + def generate_qrng(count, phi_scale=False): """Generate quantum random numbers.""" try: from quantumpytho.modules.qrng_sacred import qrng_phi_sequence + if phi_scale: result = qrng_phi_sequence(count) return f"QRNG with phi-scaling:\n{result}" @@ -67,6 +76,7 @@ def generate_qrng(count, phi_scale=False): except Exception as e: return f"Error: {str(e)}" + # Create Gradio interface def create_interface(): with gr.Blocks(title="QPyth - Quantum Computing") as demo: @@ -75,7 +85,7 @@ def create_interface(): A professionally engineered quantum computing library built on Qiskit. """) - + with gr.Tab("Bloch Sphere"): gr.Markdown("Visualize quantum states on the Bloch sphere") with gr.Row(): @@ -83,27 +93,29 @@ def create_interface(): phi = gr.Slider(0, 360, value=45, label="Phi (degrees)") bloch_output = gr.Textbox(label="Bloch Sphere Visualization", lines=20) bloch_btn = gr.Button("Generate") - bloch_btn.click(bloch_sphere_demo, inputs=[theta, phi], outputs=bloch_output) - + bloch_btn.click( + bloch_sphere_demo, inputs=[theta, phi], outputs=bloch_output + ) + with gr.Tab("Bell Pair"): gr.Markdown("Create an entangled Bell pair") bell_output = gr.Textbox(label="Circuit", lines=15) bell_btn = gr.Button("Create Bell Pair") bell_btn.click(create_bell_pair, outputs=bell_output) - + with gr.Tab("Quantum Teleportation"): gr.Markdown("Run the quantum teleportation protocol") teleport_output = gr.Textbox(label="Result", lines=10) teleport_btn = gr.Button("Run Teleportation") teleport_btn.click(run_quantum_teleport, outputs=teleport_output) - + with gr.Tab("Quantum Error Correction"): gr.Markdown("Demonstrate quantum error correction codes") code_type = gr.Radio(["Shor", "Steane"], label="Code Type", value="Shor") qec_output = gr.Textbox(label="Result", lines=15) qec_btn = gr.Button("Run QEC Demo") qec_btn.click(run_qec_demo, inputs=code_type, outputs=qec_output) - + with gr.Tab("Quantum RNG"): gr.Markdown("Generate quantum random numbers") with gr.Row(): @@ -111,8 +123,10 @@ def create_interface(): phi_scale = gr.Checkbox(label="Use phi-scaling") qrng_output = gr.Textbox(label="Random Numbers", lines=10) qrng_btn = gr.Button("Generate") - qrng_btn.click(generate_qrng, inputs=[count, phi_scale], outputs=qrng_output) - + qrng_btn.click( + generate_qrng, inputs=[count, phi_scale], outputs=qrng_output + ) + gr.Markdown(""" --- @@ -120,9 +134,10 @@ def create_interface(): IBM Quantum hardware access, and the complete web UI, please use the CLI or deploy the full application. """) - + return demo + # Launch the app if __name__ == "__main__": demo = create_interface()