Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,70 +1,48 @@
|
|
1 |
import gradio as gr
|
2 |
import threading
|
3 |
-
import time
|
4 |
from app_logic import run_my_application
|
5 |
|
6 |
# Global variables for tracking status
|
7 |
status_message = "Idle"
|
8 |
is_running = False
|
9 |
|
10 |
-
def execute_application(
|
11 |
-
"""
|
12 |
-
Execute the application logic while updating the status dynamically.
|
13 |
-
"""
|
14 |
global status_message, is_running
|
15 |
is_running = True
|
16 |
-
status_message = "Python application
|
17 |
-
|
18 |
-
|
19 |
try:
|
20 |
# Call the function from app_logic.py
|
21 |
result = run_my_application()
|
22 |
-
|
23 |
-
for i in range(5): # Simulate progress updates
|
24 |
-
time.sleep(1) # Replace this with actual task updates if available
|
25 |
-
status_message = f"Processing step {i + 1}/5..."
|
26 |
-
status_update(status_message)
|
27 |
-
|
28 |
-
# When the program completes, set the final status
|
29 |
-
status_message = f"Process completed! Result: {result}"
|
30 |
-
status_update(status_message)
|
31 |
-
|
32 |
except Exception as e:
|
33 |
-
# Handle exceptions and update status
|
34 |
status_message = f"An error occurred: {str(e)}"
|
35 |
-
status_update(status_message)
|
36 |
finally:
|
37 |
is_running = False
|
38 |
|
39 |
-
def start_program(
|
40 |
-
"""
|
41 |
-
Start the program in a new thread.
|
42 |
-
"""
|
43 |
global is_running
|
44 |
if not is_running:
|
45 |
-
threading.Thread(target=execute_application
|
46 |
return "Program started. Check status below."
|
47 |
else:
|
48 |
return "Program is already running!"
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
Create a Gradio interface with real-time status updates.
|
54 |
-
"""
|
55 |
-
with gr.Blocks() as app:
|
56 |
-
gr.Markdown("# Python Program Runner")
|
57 |
-
gr.Markdown("Click the button to start your Python program. Status will update below.")
|
58 |
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
start_button.click(fn=start_program, inputs=status_output, outputs=status_output, queue=True)
|
64 |
|
65 |
-
|
|
|
66 |
|
67 |
-
#
|
68 |
-
|
69 |
-
|
|
|
70 |
|
|
|
|
1 |
import gradio as gr
|
2 |
import threading
|
|
|
3 |
from app_logic import run_my_application
|
4 |
|
5 |
# Global variables for tracking status
|
6 |
status_message = "Idle"
|
7 |
is_running = False
|
8 |
|
9 |
+
def execute_application():
|
|
|
|
|
|
|
10 |
global status_message, is_running
|
11 |
is_running = True
|
12 |
+
status_message = "Python application is running..."
|
13 |
+
|
|
|
14 |
try:
|
15 |
# Call the function from app_logic.py
|
16 |
result = run_my_application()
|
17 |
+
status_message = result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
except Exception as e:
|
|
|
19 |
status_message = f"An error occurred: {str(e)}"
|
|
|
20 |
finally:
|
21 |
is_running = False
|
22 |
|
23 |
+
def start_program():
|
|
|
|
|
|
|
24 |
global is_running
|
25 |
if not is_running:
|
26 |
+
threading.Thread(target=execute_application).start()
|
27 |
return "Program started. Check status below."
|
28 |
else:
|
29 |
return "Program is already running!"
|
30 |
|
31 |
+
def get_status():
|
32 |
+
# Return the current status of the program
|
33 |
+
return status_message
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
+
# Gradio interface
|
36 |
+
with gr.Blocks() as app:
|
37 |
+
gr.Markdown("# Python Program Runner")
|
38 |
+
gr.Markdown("Click the button to start your Python program. Status will update below.")
|
|
|
39 |
|
40 |
+
start_button = gr.Button("Start Program")
|
41 |
+
status_output = gr.Textbox(label="Status", value="Idle", interactive=False)
|
42 |
|
43 |
+
# Event bindings
|
44 |
+
start_button.click(start_program, outputs=status_output)
|
45 |
+
status_update = gr.Textbox(label="Current Status", interactive=False)
|
46 |
+
start_button.click(get_status, outputs=status_update)
|
47 |
|
48 |
+
app.launch()
|