cloudwp commited on
Commit
baaf55c
1 Parent(s): 0f79783

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -22
app.py CHANGED
@@ -1,35 +1,45 @@
1
  import gradio as gr
2
- import os
3
  import runpodctl
4
 
5
- def run_command(command):
6
- # Überprüfung, ob der Befehl eingegeben wurde
7
- if command:
8
- output = os.popen(command).read()
9
- return output
10
- else:
11
- return "Bitte geben Sie einen Befehl ein."
12
 
13
- # Texteingabefeld erstellen
14
- command_input = gr.inputs.Textbox(label="Enter command")
 
15
 
16
- # Senden-Button erstellen
17
- send_button = gr.inputs.Button(label="Send")
 
18
 
19
- # Ausgabe erstellen
20
- output_text = gr.outputs.Text(label="Output")
 
21
 
22
- def run_app(command):
23
- output = run_command(command)
 
 
 
 
 
 
 
 
 
24
  return output
25
 
26
- # Gradio Space erstellen
 
 
27
  iface = gr.Interface(
28
  fn=run_app,
29
- inputs=command_input + send_button,
30
- outputs=output_text,
31
- title="Terminal-Befehl ausführen",
32
- description="Geben Sie den gewünschten Befehl ein und drücken Sie 'Senden', um den Befehl im Terminal auszuführen.",
33
  theme="default"
34
  )
35
- iface.launch()
 
1
  import gradio as gr
2
+ import subprocess
3
  import runpodctl
4
 
5
+ def start_pod(pod_name):
6
+ result = subprocess.run(["runpodctl", "start", pod_name], capture_output=True, text=True)
7
+ return result.stdout
 
 
 
 
8
 
9
+ def stop_pod(pod_name):
10
+ result = subprocess.run(["runpodctl", "stop", pod_name], capture_output=True, text=True)
11
+ return result.stdout
12
 
13
+ def delete_pod(pod_name):
14
+ result = subprocess.run(["runpodctl", "delete", pod_name], capture_output=True, text=True)
15
+ return result.stdout
16
 
17
+ def create_pod(pod_name):
18
+ result = subprocess.run(["runpodctl", "create", pod_name], capture_output=True, text=True)
19
+ return result.stdout
20
 
21
+ def run_app(action, pod_name):
22
+ if action == "start":
23
+ output = start_pod(pod_name)
24
+ elif action == "stop":
25
+ output = stop_pod(pod_name)
26
+ elif action == "delete":
27
+ output = delete_pod(pod_name)
28
+ elif action == "create":
29
+ output = create_pod(pod_name)
30
+ else:
31
+ output = "Unknown action. Please select a valid action."
32
  return output
33
 
34
+ action_options = gr.inputs.Radio(["start", "stop", "delete", "create"], label="Choose action")
35
+ pod_name_input = gr.inputs.Textbox(label="Enter pod name")
36
+
37
  iface = gr.Interface(
38
  fn=run_app,
39
+ inputs=[action_options, pod_name_input],
40
+ outputs="text",
41
+ title="Pod Management",
42
+ description="Enter the pod name and choose an action to perform on the pod.",
43
  theme="default"
44
  )
45
+ iface.launch()