File size: 1,423 Bytes
70568e3
 
 
 
 
 
 
 
2db5146
70568e3
 
2db5146
 
70568e3
 
 
2db5146
70568e3
 
 
 
 
2db5146
70568e3
 
2db5146
70568e3
 
 
 
2db5146
 
 
91db2c5
2db5146
 
 
 
70568e3
2db5146
 
70568e3
2db5146
 
 
 
70568e3
2db5146
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
38
39
40
41
42
43
44
45
46
47
48
49
import gradio as gr
import threading
from app_logic import run_my_application

# Global variables for tracking status
status_message = "Idle"
is_running = False

def execute_application():
    global status_message, is_running
    is_running = True
    status_message = "Python application is running..."
    
    try:
        # Call the function from app_logic.py
        result = run_my_application()
        status_message = result
    except Exception as e:
        status_message = f"An error occurred: {str(e)}"
    finally:
        is_running = False

def start_program():
    global is_running
    if not is_running:
        threading.Thread(target=execute_application).start()
        return "Program started. Check status below."
    else:
        return "Program is already running!"

def get_status():
    # Return the current status of the program
    return status_message

# Gradio interface
with gr.Blocks() as app:
    gr.Markdown("# Python Program Runner")
    gr.Markdown("Click the button to start your Python program. Status will update below.")

    start_button = gr.Button("Start Program")
    status_output = gr.Textbox(label="Status", value="Idle", interactive=False)

    # Event bindings
    start_button.click(start_program, outputs=status_output)
    status_update = gr.Textbox(label="Current Status", interactive=False)
    start_button.click(get_status, outputs=status_update)

app.launch()