-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy path04_runninghub_cloud.py
More file actions
178 lines (135 loc) · 5 KB
/
04_runninghub_cloud.py
File metadata and controls
178 lines (135 loc) · 5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
"""
RunningHub Cloud Example - Execute Workflows on RunningHub
Learn how to use RunningHub cloud platform for workflow execution.
No local ComfyUI needed!
"""
import asyncio
import os
from comfykit import ComfyKit
async def example_basic_cloud():
"""Example 1: Basic RunningHub execution"""
print("\n=== Example 1: Basic Cloud Execution ===")
# Check API key
if not os.getenv("RUNNINGHUB_API_KEY"):
print("⚠️ RUNNINGHUB_API_KEY not set, skipping example")
print(" Set it with: export RUNNINGHUB_API_KEY='your-key'")
return False
kit = ComfyKit()
# Execute with workflow ID (numeric string)
result = await kit.execute(
"12345", # RunningHub workflow ID
{"prompt": "a beautiful sunset"}
)
print(f"✓ Status: {result.status}")
print(f"✓ Images: {len(result.images)}")
# Verify
assert result.status == "completed"
return True
async def example_with_config():
"""Example 2: RunningHub with custom config"""
print("\n=== Example 2: Custom Configuration ===")
api_key = os.getenv("RUNNINGHUB_API_KEY")
if not api_key:
print("⚠️ Skipped (no API key)")
return False
kit = ComfyKit(
runninghub_api_key=api_key,
runninghub_timeout=600, # 10 minutes
runninghub_retry_count=5
)
result = await kit.execute(
"12345",
{"prompt": "a cyberpunk city", "seed": 42}
)
print(f"✓ Status: {result.status}")
print(f"✓ Timeout: {kit.runninghub_timeout}s")
return True
async def example_same_params_format():
"""Example 3: Same parameter format as local"""
print("\n=== Example 3: Unified Parameters ===")
if not os.getenv("RUNNINGHUB_API_KEY"):
print("⚠️ Skipped (no API key)")
return False
kit = ComfyKit()
# Same simple format works for both local and cloud!
params = {
"prompt": "a test prompt",
"seed": 42,
"steps": 20
}
# ComfyKit handles the conversion automatically
result = await kit.execute("12345", params)
print(f"✓ Same params format for local and cloud")
print(f"✓ Status: {result.status}")
return True
async def example_auto_detection():
"""Example 4: Automatic workflow type detection"""
print("\n=== Example 4: Auto-Detection ===")
if not os.getenv("RUNNINGHUB_API_KEY"):
print("⚠️ Skipped (no API key)")
return False
kit = ComfyKit()
# ComfyKit auto-detects:
# - "12345" → RunningHub (numeric)
# - "workflow.json" → Local file
# - "https://..." → Download and execute
result = await kit.execute("12345", {"prompt": "auto"})
print(f"✓ Auto-detected as RunningHub workflow")
print(f"✓ Status: {result.status}")
return True
async def example_mixed_usage():
"""Example 5: Mix local and cloud in same app"""
print("\n=== Example 5: Mixed Local + Cloud ===")
kit = ComfyKit()
# Execute local workflow
try:
result_local = await kit.execute(
"workflows/t2i_by_local_flux.json",
{"prompt": "local"}
)
print(f"✓ Local execution: {result_local.status}")
except:
print("⚠️ Local ComfyUI not available")
# Execute cloud workflow
if os.getenv("RUNNINGHUB_API_KEY"):
result_cloud = await kit.execute(
"12345",
{"prompt": "cloud"}
)
print(f"✓ Cloud execution: {result_cloud.status}")
else:
print("⚠️ RunningHub API key not set")
print("✓ Same instance for both!")
async def main():
print("☁️ ComfyKit RunningHub Cloud Examples")
print("="*60)
print("\n💡 RunningHub provides cloud GPU for ComfyUI workflows")
print(" No local setup needed!\n")
# Check configuration
if not os.getenv("RUNNINGHUB_API_KEY"):
print("⚠️ RUNNINGHUB_API_KEY environment variable not set")
print("\nTo use RunningHub:")
print(" 1. Sign up at https://www.runninghub.ai")
print(" 2. Get your API key")
print(" 3. Set environment variable:")
print(" export RUNNINGHUB_API_KEY='your-key-here'")
print("\n" + "="*60)
return
try:
success_count = 0
success_count += await example_basic_cloud() or 0
success_count += await example_with_config() or 0
success_count += await example_same_params_format() or 0
success_count += await example_auto_detection() or 0
await example_mixed_usage()
print("\n" + "="*60)
print(f"✨ Completed {success_count} cloud examples!")
print("\nNext: Check out 05_advanced_features.py")
except Exception as e:
print(f"\n❌ Error: {e}")
print("\n💡 Check:")
print(" 1. API key is valid")
print(" 2. Workflow ID exists")
print(" 3. Network connection")
if __name__ == "__main__":
asyncio.run(main())