JatinkInnovision commited on
Commit
11b19c0
·
verified ·
1 Parent(s): a3f9934

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ import openstack
4
+
5
+ # 1. Connect to OpenStack using HF Secrets
6
+ def get_conn():
7
+ return openstack.connect(
8
+ auth_url=os.getenv("OS_AUTH_URL"),
9
+ application_credential_id=os.getenv("OS_APPLICATION_CREDENTIAL_ID"),
10
+ application_credential_secret=os.getenv("OS_APPLICATION_CREDENTIAL_SECRET"),
11
+ region_name="IU", # Jetstream2 default
12
+ interface="public"
13
+ )
14
+
15
+ def activate_copilot():
16
+ try:
17
+ conn = get_conn()
18
+ # Replace with your actual Instance ID or Name
19
+ server = conn.compute.find_server("YOUR_INSTANCE_NAME_OR_ID")
20
+
21
+ if not server:
22
+ return "❌ Error: Instance not found."
23
+
24
+ # Perform the unshelve action
25
+ conn.compute.unshelve_server(server)
26
+ return f"✅ Success: Activation command sent for {server.name}."
27
+ except Exception as e:
28
+ return f"❌ Error: {str(e)}"
29
+
30
+ # 2. Build the UI
31
+ with gr.Blocks() as demo:
32
+ gr.Markdown("# ComFit Copilot Controller")
33
+ gr.Markdown("Click the button below to unshelve the instance on Jetstream2.")
34
+
35
+ status_output = gr.Textbox(label="Status")
36
+ activate_btn = gr.Button("Activate ComFit Copilot", variant="primary")
37
+
38
+ # Link button to function
39
+ activate_btn.click(fn=activate_copilot, outputs=status_output)
40
+
41
+ demo.launch()