File size: 5,211 Bytes
98e8012
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import requests
import gradio as gr
from datetime import datetime

# API Configuration
API_KEY = os.getenv('StableCogKey')
API_HOST = 'https://api.stablecog.com'

headers = {
    'Authorization': f'Bearer {API_KEY}',
    'Content-Type': 'application/json'
}

def get_models():
    """Fetch and display available models"""
    try:
        url = f'{API_HOST}/v1/image/generation/models'
        response = requests.get(url, headers=headers, timeout=10)
        
        if response.status_code == 200:
            data = response.json()
            models = data.get('models', [])
            
            # Format display
            display_text = f"📊 Found {len(models)} models\n"
            display_text += f"⏰ {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n\n"
            
            for i, model in enumerate(models, 1):
                name = model.get('name', 'Unknown')
                model_type = model.get('type', 'unknown')
                description = model.get('description', 'No description')
                
                display_text += f"{i}. 🔹 **{name}**\n"
                display_text += f"   📝 {description}\n"
                display_text += f"   🏷️ Type: {model_type}\n"
                display_text += f"   🌍 Public: {'✅' if model.get('is_public') else '❌'}\n"
                display_text += f"   ⭐ Default: {'✅' if model.get('is_default') else '❌'}\n"
                display_text += f"   👥 Community: {'✅' if model.get('is_community') else '❌'}\n"
                display_text += "─" * 40 + "\n"
            
            return display_text, str(data)
            
        else:
            return f"❌ Error {response.status_code}", f"Error: {response.text}"
            
    except Exception as e:
        return f"❌ Error: {str(e)}", "No data"

def get_outputs():
    """Fetch and display recent outputs"""
    try:
        url = f'{API_HOST}/v1/image/generation/outputs'
        response = requests.get(url, headers=headers, timeout=10)
        
        if response.status_code == 200:
            data = response.json()
            outputs = data.get('outputs', [])
            total = data.get('total_count', 0)
            next_cursor = data.get('next', 'None')
            
            # Format display
            display_text = f"📊 Total outputs: {total}\n"
            display_text += f"📋 Showing: {len(outputs)} outputs\n"
            display_text += f"⏭️ Next cursor: {next_cursor}\n"
            display_text += f"⏰ {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n\n"
            
            for i, output in enumerate(outputs, 1):
                output_id = output.get('id', 'N/A')[:8] + '...'
                created_at = output.get('created_at', 'N/A')
                status = output.get('status', 'unknown')
                model_name = output.get('model_name', 'Unknown')
                
                # Format timestamp
                if created_at != 'N/A':
                    try:
                        dt = datetime.fromisoformat(created_at.replace('Z', '+00:00'))
                        created_at = dt.strftime('%Y-%m-%d %H:%M')
                    except:
                        pass
                
                display_text += f"{i}. 🔹 **Output {output_id}**\n"
                display_text += f"   🕒 Created: {created_at}\n"
                display_text += f"   📊 Status: {status}\n"
                display_text += f"   🤖 Model: {model_name}\n"
                
                # Show image URLs if available
                images = output.get('image_urls', [])
                if images:
                    display_text += f"   🖼️ Images: {len(images)}\n"
                    for img_url in images[:2]:  # Show first 2 URLs
                        display_text += f"      🔗 {img_url[:50]}...\n"
                
                display_text += "─" * 40 + "\n"
            
            return display_text, str(data)
            
        else:
            return f"❌ Error {response.status_code}", f"Error: {response.text}"
            
    except Exception as e:
        return f"❌ Error: {str(e)}", "No data"

# Create Gradio interface
with gr.Blocks(title="StableCog Dashboard") as demo:
    gr.Markdown("# 🎯 StableCog Dashboard")
    
    with gr.Tabs():
        with gr.Tab("🤖 Models"):
            with gr.Row():
                models_display = gr.Textbox(label="Available Models", lines=25)
                models_raw = gr.Code(label="Raw JSON", language="json", lines=25)
            
            check_models_btn = gr.Button("🔄 Refresh Models", variant="primary")
            check_models_btn.click(get_models, outputs=[models_display, models_raw])
        
        with gr.Tab("🖼️ Outputs"):
            with gr.Row():
                outputs_display = gr.Textbox(label="Recent Outputs", lines=25)
                outputs_raw = gr.Code(label="Raw JSON", language="json", lines=25)
            
            check_outputs_btn = gr.Button("🔄 Refresh Outputs", variant="primary")
            check_outputs_btn.click(get_outputs, outputs=[outputs_display, outputs_raw])

if __name__ == "__main__":
    demo.launch()