MySafeCode commited on
Commit
98e8012
·
verified ·
1 Parent(s): 23286e2

Create a.py

Browse files
Files changed (1) hide show
  1. a.py +126 -0
a.py ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import requests
3
+ import gradio as gr
4
+ from datetime import datetime
5
+
6
+ # API Configuration
7
+ API_KEY = os.getenv('StableCogKey')
8
+ API_HOST = 'https://api.stablecog.com'
9
+
10
+ headers = {
11
+ 'Authorization': f'Bearer {API_KEY}',
12
+ 'Content-Type': 'application/json'
13
+ }
14
+
15
+ def get_models():
16
+ """Fetch and display available models"""
17
+ try:
18
+ url = f'{API_HOST}/v1/image/generation/models'
19
+ response = requests.get(url, headers=headers, timeout=10)
20
+
21
+ if response.status_code == 200:
22
+ data = response.json()
23
+ models = data.get('models', [])
24
+
25
+ # Format display
26
+ display_text = f"📊 Found {len(models)} models\n"
27
+ display_text += f"⏰ {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n\n"
28
+
29
+ for i, model in enumerate(models, 1):
30
+ name = model.get('name', 'Unknown')
31
+ model_type = model.get('type', 'unknown')
32
+ description = model.get('description', 'No description')
33
+
34
+ display_text += f"{i}. 🔹 **{name}**\n"
35
+ display_text += f" 📝 {description}\n"
36
+ display_text += f" 🏷️ Type: {model_type}\n"
37
+ display_text += f" 🌍 Public: {'✅' if model.get('is_public') else '❌'}\n"
38
+ display_text += f" ⭐ Default: {'✅' if model.get('is_default') else '❌'}\n"
39
+ display_text += f" 👥 Community: {'✅' if model.get('is_community') else '❌'}\n"
40
+ display_text += "─" * 40 + "\n"
41
+
42
+ return display_text, str(data)
43
+
44
+ else:
45
+ return f"❌ Error {response.status_code}", f"Error: {response.text}"
46
+
47
+ except Exception as e:
48
+ return f"❌ Error: {str(e)}", "No data"
49
+
50
+ def get_outputs():
51
+ """Fetch and display recent outputs"""
52
+ try:
53
+ url = f'{API_HOST}/v1/image/generation/outputs'
54
+ response = requests.get(url, headers=headers, timeout=10)
55
+
56
+ if response.status_code == 200:
57
+ data = response.json()
58
+ outputs = data.get('outputs', [])
59
+ total = data.get('total_count', 0)
60
+ next_cursor = data.get('next', 'None')
61
+
62
+ # Format display
63
+ display_text = f"📊 Total outputs: {total}\n"
64
+ display_text += f"📋 Showing: {len(outputs)} outputs\n"
65
+ display_text += f"⏭️ Next cursor: {next_cursor}\n"
66
+ display_text += f"⏰ {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n\n"
67
+
68
+ for i, output in enumerate(outputs, 1):
69
+ output_id = output.get('id', 'N/A')[:8] + '...'
70
+ created_at = output.get('created_at', 'N/A')
71
+ status = output.get('status', 'unknown')
72
+ model_name = output.get('model_name', 'Unknown')
73
+
74
+ # Format timestamp
75
+ if created_at != 'N/A':
76
+ try:
77
+ dt = datetime.fromisoformat(created_at.replace('Z', '+00:00'))
78
+ created_at = dt.strftime('%Y-%m-%d %H:%M')
79
+ except:
80
+ pass
81
+
82
+ display_text += f"{i}. 🔹 **Output {output_id}**\n"
83
+ display_text += f" 🕒 Created: {created_at}\n"
84
+ display_text += f" 📊 Status: {status}\n"
85
+ display_text += f" 🤖 Model: {model_name}\n"
86
+
87
+ # Show image URLs if available
88
+ images = output.get('image_urls', [])
89
+ if images:
90
+ display_text += f" 🖼️ Images: {len(images)}\n"
91
+ for img_url in images[:2]: # Show first 2 URLs
92
+ display_text += f" 🔗 {img_url[:50]}...\n"
93
+
94
+ display_text += "─" * 40 + "\n"
95
+
96
+ return display_text, str(data)
97
+
98
+ else:
99
+ return f"❌ Error {response.status_code}", f"Error: {response.text}"
100
+
101
+ except Exception as e:
102
+ return f"❌ Error: {str(e)}", "No data"
103
+
104
+ # Create Gradio interface
105
+ with gr.Blocks(title="StableCog Dashboard") as demo:
106
+ gr.Markdown("# 🎯 StableCog Dashboard")
107
+
108
+ with gr.Tabs():
109
+ with gr.Tab("🤖 Models"):
110
+ with gr.Row():
111
+ models_display = gr.Textbox(label="Available Models", lines=25)
112
+ models_raw = gr.Code(label="Raw JSON", language="json", lines=25)
113
+
114
+ check_models_btn = gr.Button("🔄 Refresh Models", variant="primary")
115
+ check_models_btn.click(get_models, outputs=[models_display, models_raw])
116
+
117
+ with gr.Tab("🖼️ Outputs"):
118
+ with gr.Row():
119
+ outputs_display = gr.Textbox(label="Recent Outputs", lines=25)
120
+ outputs_raw = gr.Code(label="Raw JSON", language="json", lines=25)
121
+
122
+ check_outputs_btn = gr.Button("🔄 Refresh Outputs", variant="primary")
123
+ check_outputs_btn.click(get_outputs, outputs=[outputs_display, outputs_raw])
124
+
125
+ if __name__ == "__main__":
126
+ demo.launch()