File size: 1,158 Bytes
e14fa43
 
 
1b8c9a6
 
e14fa43
 
1b8c9a6
 
e14fa43
 
 
 
921b5d4
e14fa43
 
921b5d4
e14fa43
 
921b5d4
e14fa43
 
 
 
1b8c9a6
 
 
 
e14fa43
 
1b8c9a6
e14fa43
 
1b8c9a6
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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()