Spaces:
Sleeping
Sleeping
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() | |