Spaces:
Runtime error
Runtime error
| from qiskit_aer import Aer | |
| from qiskit.utils import QuantumInstance | |
| from qiskit.algorithms import Shor | |
| import gradio as gr | |
| # Function to run Shor's algorithm | |
| def run_shor(N): | |
| try: | |
| N = int(N) | |
| if N % 2 == 0 or N <= 1: | |
| return f"Please enter an odd integer > 1." | |
| if N > 21: | |
| return f"Too big! Factor small numbers like 15 or 21 for simulation." | |
| backend = Aer.get_backend('aer_simulator') | |
| quantum_instance = QuantumInstance(backend, shots=1024) | |
| shor = Shor(quantum_instance=quantum_instance) | |
| result = shor.factor(N) | |
| if result.factors: | |
| return f"Factors of {N} are: {result.factors}" | |
| else: | |
| return f"Failed to find factors. Try again!" | |
| except Exception as e: | |
| return str(e) | |
| iface = gr.Interface( | |
| fn=run_shor, | |
| inputs=gr.Number(label="Enter an integer to factor"), | |
| outputs=gr.Textbox(label="Result"), | |
| title="Shor's Algorithm Demo", | |
| description="A simple Qiskit + Gradio demo using the classic Shor's Algorithm. Runs on a simulator β use small N like 15, 21." | |
| ) | |
| if __name__ == "__main__": | |
| iface.launch() |