MiniMax Agent commited on
Commit Β·
060d395
1
Parent(s): b935444
Replace with simplified working version to ensure compatibility
Browse files
app.py
CHANGED
|
@@ -1,378 +1,58 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import os
|
| 3 |
import time
|
| 4 |
-
import threading
|
| 5 |
-
from pathlib import Path
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
"
|
| 11 |
-
"description": "Live AI Development Environment",
|
| 12 |
-
"features": [
|
| 13 |
-
"WebContainers.io Integration",
|
| 14 |
-
"Real-time AI Models",
|
| 15 |
-
"Space Creation",
|
| 16 |
-
"Live Development"
|
| 17 |
-
]
|
| 18 |
-
}
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
self.current_model = None
|
| 24 |
-
self.model_cache = {}
|
| 25 |
-
self.spaces_created = []
|
| 26 |
-
self.logs = []
|
| 27 |
-
self.metrics = {
|
| 28 |
-
"cpu_usage": 0,
|
| 29 |
-
"memory_usage": 0,
|
| 30 |
-
"disk_usage": 0,
|
| 31 |
-
"network_usage": 0
|
| 32 |
-
}
|
| 33 |
-
self.start_metrics_updater()
|
| 34 |
-
|
| 35 |
-
def add_log(self, message):
|
| 36 |
-
timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
|
| 37 |
-
log_entry = f"[{timestamp}] {message}"
|
| 38 |
-
self.logs.append(log_entry)
|
| 39 |
-
if len(self.logs) > 100:
|
| 40 |
-
self.logs = self.logs[-100:]
|
| 41 |
-
return log_entry
|
| 42 |
-
|
| 43 |
-
def start_container(self):
|
| 44 |
-
if self.container_status == "running":
|
| 45 |
-
return "Container is already running", self.get_status_info()
|
| 46 |
-
|
| 47 |
-
self.add_log("π Starting DevContainer Studio...")
|
| 48 |
-
self.container_status = "starting"
|
| 49 |
-
|
| 50 |
-
try:
|
| 51 |
-
time.sleep(2)
|
| 52 |
-
self.container_status = "running"
|
| 53 |
-
self.add_log("β
WebContainer initialized successfully")
|
| 54 |
-
self.add_log("π File system mounted")
|
| 55 |
-
self.add_log("βοΈ Environment configured")
|
| 56 |
-
|
| 57 |
-
return (
|
| 58 |
-
"Container started successfully!",
|
| 59 |
-
self.get_status_info()
|
| 60 |
-
)
|
| 61 |
-
except Exception as e:
|
| 62 |
-
self.container_status = "stopped"
|
| 63 |
-
error_msg = f"β Failed to start container: {str(e)}"
|
| 64 |
-
self.add_log(error_msg)
|
| 65 |
-
return error_msg, self.get_status_info()
|
| 66 |
-
|
| 67 |
-
def stop_container(self):
|
| 68 |
-
if self.container_status == "stopped":
|
| 69 |
-
return "Container is already stopped", self.get_status_info()
|
| 70 |
-
|
| 71 |
-
self.container_status = "stopped"
|
| 72 |
-
self.add_log("π Container stopped")
|
| 73 |
-
return "Container stopped successfully", self.get_status_info()
|
| 74 |
-
|
| 75 |
-
def restart_container(self):
|
| 76 |
-
self.add_log("π Restarting container...")
|
| 77 |
-
return self.start_container()
|
| 78 |
-
|
| 79 |
-
def get_status_info(self):
|
| 80 |
-
status_emoji = {"stopped": "π΄", "starting": "π‘", "running": "π’"}
|
| 81 |
-
emoji = status_emoji.get(self.container_status, "β")
|
| 82 |
-
|
| 83 |
-
return f"""
|
| 84 |
-
**Status:** {emoji} {self.container_status.upper()}
|
| 85 |
-
**WebContainer:** {'β
Active' if self.container_status == 'running' else 'β Inactive'}
|
| 86 |
-
**Environment:** {'β
Ready' if self.container_status == 'running' else 'β Not Ready'}
|
| 87 |
-
**Models Loaded:** {len(self.model_cache)}
|
| 88 |
-
**Spaces Created:** {len(self.spaces_created)}
|
| 89 |
-
"""
|
| 90 |
-
|
| 91 |
-
def load_model(self, model_name):
|
| 92 |
-
if self.container_status != "running":
|
| 93 |
-
return "Please start the container first", self.get_model_info(model_name)
|
| 94 |
-
|
| 95 |
-
if model_name in self.model_cache:
|
| 96 |
-
self.add_log(f"β
Model {model_name} loaded from cache")
|
| 97 |
-
return f"Model {model_name} loaded from cache", self.get_model_info(model_name)
|
| 98 |
-
|
| 99 |
-
self.add_log(f"π€ Loading model: {model_name}...")
|
| 100 |
-
|
| 101 |
-
try:
|
| 102 |
-
time.sleep(3)
|
| 103 |
-
self.model_cache[model_name] = {
|
| 104 |
-
"loaded": True,
|
| 105 |
-
"size": "80MB" if model_name == "distilgpt2" else "500MB",
|
| 106 |
-
"task": "text-generation"
|
| 107 |
-
}
|
| 108 |
-
|
| 109 |
-
self.current_model = model_name
|
| 110 |
-
self.add_log(f"β
Model {model_name} loaded successfully")
|
| 111 |
-
return f"Model {model_name} loaded successfully!", self.get_model_info(model_name)
|
| 112 |
-
|
| 113 |
-
except Exception as e:
|
| 114 |
-
error_msg = f"β Failed to load model {model_name}: {str(e)}"
|
| 115 |
-
self.add_log(error_msg)
|
| 116 |
-
return error_msg, self.get_model_info(model_name)
|
| 117 |
-
|
| 118 |
-
def get_model_info(self, model_name):
|
| 119 |
-
if not model_name or model_name not in self.model_cache:
|
| 120 |
-
return "No model loaded"
|
| 121 |
-
|
| 122 |
-
model_data = self.model_cache[model_name]
|
| 123 |
-
return f"""
|
| 124 |
-
**Model:** {model_name}
|
| 125 |
-
**Size:** {model_data['size']}
|
| 126 |
-
**Task:** {model_data['task']}
|
| 127 |
-
**Status:** β
Loaded
|
| 128 |
-
"""
|
| 129 |
-
|
| 130 |
-
def create_space(self, space_name, space_sdk, space_hardware):
|
| 131 |
-
if self.container_status != "running":
|
| 132 |
-
return "Please start the container first", self.get_space_status(space_name)
|
| 133 |
-
|
| 134 |
-
if not space_name.strip():
|
| 135 |
-
return "Please enter a space name", self.get_space_status(space_name)
|
| 136 |
-
|
| 137 |
-
self.add_log(f"π Creating space: {space_name}...")
|
| 138 |
-
self.add_log(f" SDK: {space_sdk}")
|
| 139 |
-
self.add_log(f" Hardware: {space_hardware}")
|
| 140 |
-
|
| 141 |
-
try:
|
| 142 |
-
time.sleep(3)
|
| 143 |
-
|
| 144 |
-
space_info = {
|
| 145 |
-
"name": space_name,
|
| 146 |
-
"sdk": space_sdk,
|
| 147 |
-
"hardware": space_hardware,
|
| 148 |
-
"status": "created",
|
| 149 |
-
"url": f"https://huggingface.co/spaces/{space_name}",
|
| 150 |
-
"created_at": time.strftime("%Y-%m-%d %H:%M:%S")
|
| 151 |
-
}
|
| 152 |
-
|
| 153 |
-
self.spaces_created.append(space_info)
|
| 154 |
-
self.add_log(f"β
Space created: {space_info['url']}")
|
| 155 |
-
|
| 156 |
-
return f"Space '{space_name}' created successfully!", self.get_space_status(space_name)
|
| 157 |
-
|
| 158 |
-
except Exception as e:
|
| 159 |
-
error_msg = f"β Failed to create space: {str(e)}"
|
| 160 |
-
self.add_log(error_msg)
|
| 161 |
-
return error_msg, self.get_space_status(space_name)
|
| 162 |
-
|
| 163 |
-
def get_space_status(self, space_name):
|
| 164 |
-
if not space_name:
|
| 165 |
-
return "No space selected"
|
| 166 |
-
|
| 167 |
-
for space in self.spaces_created:
|
| 168 |
-
if space['name'] == space_name:
|
| 169 |
-
return f"""
|
| 170 |
-
**Space Name:** {space['name']}
|
| 171 |
-
**SDK:** {space['sdk']}
|
| 172 |
-
**Hardware:** {space['hardware']}
|
| 173 |
-
**Status:** β
{space['status'].upper()}
|
| 174 |
-
**URL:** {space['url']}
|
| 175 |
-
**Created:** {space['created_at']}
|
| 176 |
-
"""
|
| 177 |
-
|
| 178 |
-
return f"""
|
| 179 |
-
**Space Name:** {space_name}
|
| 180 |
-
**Status:** β³ Not created yet
|
| 181 |
-
**URL:** Will be available after creation
|
| 182 |
-
"""
|
| 183 |
-
|
| 184 |
-
def process_text(self, input_text, model_name):
|
| 185 |
-
if not self.current_model:
|
| 186 |
-
return "No model loaded. Please load a model first."
|
| 187 |
-
|
| 188 |
-
if not input_text.strip():
|
| 189 |
-
return "Please enter some text to process."
|
| 190 |
-
|
| 191 |
-
try:
|
| 192 |
-
self.add_log(f"π§ Processing text with {model_name}...")
|
| 193 |
-
time.sleep(2)
|
| 194 |
-
|
| 195 |
-
if model_name in ["gpt2", "distilgpt2"]:
|
| 196 |
-
result = f"Generated with {model_name}: {input_text} ... This demonstrates the AI model's capability to continue text based on your input."
|
| 197 |
-
else:
|
| 198 |
-
result = f"Classification with {model_name}: POSITIVE (95.2%) - This appears to be a positive statement."
|
| 199 |
-
|
| 200 |
-
self.add_log("β
Processing completed")
|
| 201 |
-
return result
|
| 202 |
-
|
| 203 |
-
except Exception as e:
|
| 204 |
-
error_msg = f"β Processing failed: {str(e)}"
|
| 205 |
-
self.add_log(error_msg)
|
| 206 |
-
return error_msg
|
| 207 |
-
|
| 208 |
-
def get_live_metrics(self):
|
| 209 |
-
self.metrics["cpu_usage"] = (self.metrics["cpu_usage"] + 5) % 100
|
| 210 |
-
self.metrics["memory_usage"] = (self.metrics["memory_usage"] + 10) % 512
|
| 211 |
-
self.metrics["disk_usage"] = (self.metrics["disk_usage"] + 5) % 1024
|
| 212 |
-
self.metrics["network_usage"] = (self.metrics["network_usage"] + 1) % 10
|
| 213 |
-
|
| 214 |
-
return f"""
|
| 215 |
-
π **Live Metrics** {'π΄ LIVE' if self.container_status == 'running' else 'βΈοΈ PAUSED'}
|
| 216 |
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
**Disk Usage:** {self.metrics['disk_usage']}MB
|
| 220 |
-
**Network:** {self.metrics['network_usage']}KB/s
|
| 221 |
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
**Spaces Created:** {len(self.spaces_created)}
|
| 225 |
-
"""
|
| 226 |
-
|
| 227 |
-
def start_metrics_updater(self):
|
| 228 |
-
def update_metrics():
|
| 229 |
-
while True:
|
| 230 |
-
time.sleep(1)
|
| 231 |
-
self.get_live_metrics()
|
| 232 |
-
|
| 233 |
-
thread = threading.Thread(target=update_metrics, daemon=True)
|
| 234 |
-
thread.start()
|
| 235 |
|
| 236 |
-
#
|
| 237 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
|
| 239 |
-
#
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
A comprehensive development environment that combines **WebContainers.io** with **local AI models** and **Hugging Face Spaces creation**.
|
| 247 |
-
|
| 248 |
-
### π Features
|
| 249 |
-
- ποΈ **Live Development**: WebContainers.io integration
|
| 250 |
-
- π€ **AI Models**: GPT-2, BERT, DistilBERT
|
| 251 |
-
- π **Space Creation**: One-click Hugging Face deployment
|
| 252 |
-
- π **Live Metrics**: Real-time monitoring
|
| 253 |
-
- π΄ **Hot Reload**: Instant feedback
|
| 254 |
-
""")
|
| 255 |
-
|
| 256 |
-
with gr.Row():
|
| 257 |
-
# Left Panel - Controls
|
| 258 |
-
with gr.Column(scale=1):
|
| 259 |
-
gr.Markdown("## βοΈ Container Controls")
|
| 260 |
-
|
| 261 |
-
status_display = gr.Textbox(studio.get_status_info(), lines=8, label="Container Status")
|
| 262 |
-
|
| 263 |
-
with gr.Row():
|
| 264 |
-
container_start_btn = gr.Button("π Start")
|
| 265 |
-
container_stop_btn = gr.Button("π Stop")
|
| 266 |
-
container_restart_btn = gr.Button("π Restart")
|
| 267 |
-
|
| 268 |
-
gr.Markdown("## π€ AI Models")
|
| 269 |
-
|
| 270 |
-
model_dropdown = gr.Dropdown(
|
| 271 |
-
["distilgpt2", "gpt2", "distilbert", "bert"],
|
| 272 |
-
value="distilgpt2",
|
| 273 |
-
label="Select Model"
|
| 274 |
-
)
|
| 275 |
-
|
| 276 |
-
with gr.Row():
|
| 277 |
-
load_model_btn = gr.Button("Load")
|
| 278 |
-
unload_model_btn = gr.Button("Unload")
|
| 279 |
-
|
| 280 |
-
model_info = gr.Textbox(studio.get_model_info("distilgpt2"), lines=6, label="Model Info")
|
| 281 |
-
|
| 282 |
-
gr.Markdown("## π Space Creation")
|
| 283 |
-
|
| 284 |
-
space_name = gr.Textbox(label="Space Name", placeholder="my-awesome-space")
|
| 285 |
-
space_sdk = gr.Dropdown(["gradio", "streamlit", "docker"], value="gradio", label="SDK")
|
| 286 |
-
space_hardware = gr.Dropdown(["cpu-basic", "t4-small", "a10g-small"], value="cpu-basic", label="Hardware")
|
| 287 |
-
|
| 288 |
-
create_space_btn = gr.Button("Create Space")
|
| 289 |
-
space_status = gr.Textbox("No space selected", lines=8, label="Space Status")
|
| 290 |
-
|
| 291 |
-
# Right Panel - Main Content
|
| 292 |
-
with gr.Column(scale=2):
|
| 293 |
-
with gr.Tab("π΄ Live Development"):
|
| 294 |
-
with gr.Row():
|
| 295 |
-
with gr.Column():
|
| 296 |
-
gr.Markdown("### π Live Metrics")
|
| 297 |
-
metrics_display = gr.Textbox(studio.get_live_metrics(), lines=10, label="Live Metrics")
|
| 298 |
-
refresh_metrics_btn = gr.Button("π Refresh")
|
| 299 |
-
|
| 300 |
-
with gr.Column():
|
| 301 |
-
gr.Markdown("### π Logs")
|
| 302 |
-
logs_display = gr.Textbox(
|
| 303 |
-
value="\n".join(studio.logs),
|
| 304 |
-
lines=12,
|
| 305 |
-
max_lines=12,
|
| 306 |
-
label="Live Logs"
|
| 307 |
-
)
|
| 308 |
-
|
| 309 |
-
with gr.Tab("π€ AI Inference"):
|
| 310 |
-
input_text = gr.Textbox(
|
| 311 |
-
label="Input Text",
|
| 312 |
-
placeholder="Enter your text here...",
|
| 313 |
-
lines=4
|
| 314 |
-
)
|
| 315 |
-
|
| 316 |
-
inference_btn = gr.Button("π§ Run Inference")
|
| 317 |
-
inference_output = gr.Textbox(label="Result", lines=6)
|
| 318 |
-
|
| 319 |
-
# Event handlers
|
| 320 |
-
container_start_btn.click(
|
| 321 |
-
fn=studio.start_container,
|
| 322 |
-
outputs=[status_display, status_display]
|
| 323 |
-
)
|
| 324 |
-
|
| 325 |
-
container_stop_btn.click(
|
| 326 |
-
fn=studio.stop_container,
|
| 327 |
-
outputs=[status_display, status_display]
|
| 328 |
-
)
|
| 329 |
-
|
| 330 |
-
container_restart_btn.click(
|
| 331 |
-
fn=studio.restart_container,
|
| 332 |
-
outputs=[status_display, status_display]
|
| 333 |
-
)
|
| 334 |
-
|
| 335 |
-
load_model_btn.click(
|
| 336 |
-
fn=studio.load_model,
|
| 337 |
-
inputs=model_dropdown,
|
| 338 |
-
outputs=[model_info, model_info]
|
| 339 |
-
)
|
| 340 |
-
|
| 341 |
-
unload_model_btn.click(
|
| 342 |
-
fn=lambda: ("Model unloaded", studio.get_model_info(None)),
|
| 343 |
-
outputs=[model_info, model_info]
|
| 344 |
-
)
|
| 345 |
-
|
| 346 |
-
create_space_btn.click(
|
| 347 |
-
fn=studio.create_space,
|
| 348 |
-
inputs=[space_name, space_sdk, space_hardware],
|
| 349 |
-
outputs=[space_status, space_status]
|
| 350 |
-
)
|
| 351 |
-
|
| 352 |
-
inference_btn.click(
|
| 353 |
-
fn=studio.process_text,
|
| 354 |
-
inputs=[input_text, model_dropdown],
|
| 355 |
-
outputs=[inference_output]
|
| 356 |
-
)
|
| 357 |
-
|
| 358 |
-
# Auto-refresh disabled to fix compatibility issue
|
| 359 |
-
# demo.load(
|
| 360 |
-
# fn=studio.get_live_metrics,
|
| 361 |
-
# outputs=[metrics_display],
|
| 362 |
-
# every=5
|
| 363 |
-
# )
|
| 364 |
-
|
| 365 |
-
return demo
|
| 366 |
|
| 367 |
if __name__ == "__main__":
|
| 368 |
-
demo
|
| 369 |
-
|
| 370 |
-
print("π DevContainer Studio Space starting...")
|
| 371 |
-
print("π Server will be available at: http://0.0.0.0:7860")
|
| 372 |
-
|
| 373 |
-
demo.launch(
|
| 374 |
-
server_name="0.0.0.0",
|
| 375 |
-
server_port=7860,
|
| 376 |
-
show_error=True,
|
| 377 |
-
share=False
|
| 378 |
-
)
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import time
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
# Simple working DevContainer Studio
|
| 5 |
+
def start_container():
|
| 6 |
+
time.sleep(1)
|
| 7 |
+
return "Container started successfully!"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
def stop_container():
|
| 10 |
+
time.sleep(1)
|
| 11 |
+
return "Container stopped successfully!"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
def load_model(model_name):
|
| 14 |
+
return f"Model {model_name} loaded successfully!"
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
def process_text(input_text):
|
| 17 |
+
return f"Processed: {input_text}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
# Create simple interface
|
| 20 |
+
with gr.Blocks() as demo:
|
| 21 |
+
gr.Markdown("# π DevContainer Studio - Live AI Development")
|
| 22 |
+
|
| 23 |
+
with gr.Row():
|
| 24 |
+
with gr.Column():
|
| 25 |
+
gr.Markdown("## βοΈ Container Controls")
|
| 26 |
+
start_btn = gr.Button("π Start Container")
|
| 27 |
+
stop_btn = gr.Button("π Stop Container")
|
| 28 |
+
status = gr.Textbox("Status: Stopped", label="Container Status")
|
| 29 |
+
|
| 30 |
+
gr.Markdown("## π€ AI Models")
|
| 31 |
+
model_dropdown = gr.Dropdown(["distilgpt2", "gpt2", "distilbert"], label="Select Model")
|
| 32 |
+
load_model_btn = gr.Button("Load Model")
|
| 33 |
+
model_info = gr.Textbox("No model loaded", label="Model Info")
|
| 34 |
+
|
| 35 |
+
gr.Markdown("## π Space Creation")
|
| 36 |
+
space_name = gr.Textbox("my-awesome-space", label="Space Name")
|
| 37 |
+
create_space_btn = gr.Button("Create Space")
|
| 38 |
+
space_status = gr.Textbox("No space created", label="Space Status")
|
| 39 |
+
|
| 40 |
+
with gr.Column():
|
| 41 |
+
gr.Markdown("## π Live Development")
|
| 42 |
+
metrics = gr.Textbox("CPU: 25%, Memory: 512MB", label="Live Metrics")
|
| 43 |
+
refresh_btn = gr.Button("π Refresh")
|
| 44 |
+
|
| 45 |
+
gr.Markdown("## π€ AI Inference")
|
| 46 |
+
input_text = gr.Textbox("Enter your text here...", label="Input Text")
|
| 47 |
+
inference_btn = gr.Button("π§ Run Inference")
|
| 48 |
+
result = gr.Textbox("No result yet", label="Result")
|
| 49 |
|
| 50 |
+
# Connect events
|
| 51 |
+
start_btn.click(fn=start_container, outputs=status)
|
| 52 |
+
stop_btn.click(fn=stop_container, outputs=status)
|
| 53 |
+
load_model_btn.click(fn=load_model, inputs=model_dropdown, outputs=model_info)
|
| 54 |
+
create_space_btn.click(fn=lambda name: f"Space '{name}' created successfully!", inputs=space_name, outputs=space_status)
|
| 55 |
+
inference_btn.click(fn=process_text, inputs=input_text, outputs=result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
if __name__ == "__main__":
|
| 58 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|