MySafeCode commited on
Commit
24656d8
·
verified ·
1 Parent(s): c41a5ba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +89 -91
app.py CHANGED
@@ -59,108 +59,106 @@ def get_outputs():
59
  total = data.get('total_count', 0)
60
  next_cursor = data.get('next', 'None')
61
 
62
- # Prepare display components
63
- image_gallery = []
64
- display_text = ""
 
 
 
 
65
  gallery_html = "<div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 15px;'>"
66
 
67
- if outputs:
68
- display_text += f"📊 Total outputs: {total}\n"
69
- display_text += f"📋 Showing: {len(outputs)} outputs\n"
70
- display_text += f"⏭️ Next cursor: {next_cursor}\n"
71
- display_text += f"⏰ {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n\n"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
 
73
- for i, output in enumerate(outputs, 1):
74
- output_id = output.get('id', 'N/A')
75
- short_id = output_id[:8] + '...' if len(output_id) > 8 else output_id
76
- created_at = output.get('created_at', 'N/A')
77
- status = output.get('status', 'unknown')
78
- model_name = output.get('model_name', 'Unknown')
79
-
80
- # Gallery status with emojis
81
- gallery_status = output.get('gallery_status', 'not_submitted')
82
- gallery_emoji = {
83
- 'not_submitted': '🔒',
84
- 'submitted': '📤',
85
- 'approved': '✅',
86
- 'rejected': '❌'
87
- }.get(gallery_status, '❓')
88
-
89
- # Favorites
90
- is_favorited = output.get('is_favorited', False)
91
- favorite_emoji = '❤️' if is_favorited else '🤍'
92
-
93
- # Auto-submitted
94
- was_auto_submitted = output.get('was_auto_submitted', False)
95
- auto_submit_emoji = '🤖' if was_auto_submitted else '👤'
96
-
97
- # Format timestamp
98
- if created_at != 'N/A':
99
- try:
100
- dt = datetime.fromisoformat(created_at.replace('Z', '+00:00'))
101
- created_at = dt.strftime('%Y-%m-%d %H:%M')
102
- except:
103
- pass
104
-
105
- display_text += f"{i}. 🔹 **Output {short_id}**\n"
106
- display_text += f" 🕒 Created: {created_at}\n"
107
- display_text += f" 📊 Status: {status}\n"
108
- display_text += f" 🤖 Model: {model_name}\n"
109
- display_text += f" 🖼️ Gallery: {gallery_emoji} {gallery_status}\n"
110
- display_text += f" {favorite_emoji} Favorite\n"
111
- display_text += f" {auto_submit_emoji} {'Auto-submitted' if was_auto_submitted else 'Manual'}\n"
112
-
113
- # Get image URLs
114
- image_url = output.get('image_url')
115
  image_urls = output.get('image_urls', [])
116
-
117
- # Use image_url if available, otherwise check image_urls array
118
- image_to_show = image_url or (image_urls[0] if image_urls else None)
119
-
120
- if image_to_show:
121
- # Add to gallery
122
- gallery_html += f"""
123
- <div style='border-radius: 10px; overflow: hidden; background: rgba(255,255,255,0.1); padding: 10px;'>
124
- <img src='{image_to_show}' style='width: 100%; height: 200px; object-fit: cover; border-radius: 8px;'>
125
- <div style='margin-top: 8px; font-size: 12px;'>
126
- <div>📅 {created_at.split()[0] if ' ' in created_at else created_at}</div>
127
- <div>🤖 {model_name[:15]}{'...' if len(model_name) > 15 else ''}</div>
128
- <div>{gallery_emoji} {gallery_status}</div>
129
- <div>{favorite_emoji}</div>
130
- </div>
131
  </div>
132
- """
133
-
134
- display_text += f" 🖼️ Image: {image_to_show[:50]}...\n"
135
- else:
136
- display_text += f" 🖼️ No image available\n"
137
-
138
- # Show generation details if available
139
- generation = output.get('generation', {})
140
- if generation:
141
- prompt = generation.get('prompt', 'No prompt')
142
- width = generation.get('width', '?')
143
- height = generation.get('height', '?')
144
-
145
- display_text += f" 📝 Prompt: {prompt[:50]}...\n"
146
- display_text += f" 📐 Size: {width}x{height}\n"
147
-
148
- display_text += "─" * 40 + "\n"
149
- else:
150
- display_text = "📭 No outputs found. Generate some images first!"
151
- gallery_html += "<div style='text-align: center; padding: 40px;'>No images found</div>"
152
 
153
  gallery_html += "</div>"
154
 
 
 
 
 
155
  return display_text, gallery_html, str(data)
156
 
157
  else:
158
- error_text = f"❌ Error {response.status_code}"
159
- return error_text, "<div style='color: red; padding: 20px;'>" + error_text + "</div>", f"Error: {response.text}"
160
 
161
  except Exception as e:
162
- error_text = f"❌ Error: {str(e)}"
163
- return error_text, "<div style='color: red; padding: 20px;'>" + error_text + "</div>", "No data"
164
 
165
  # Create Gradio interface
166
  with gr.Blocks(title="StableCog Dashboard") as demo:
@@ -177,9 +175,9 @@ with gr.Blocks(title="StableCog Dashboard") as demo:
177
 
178
  with gr.Tab("🖼️ Outputs"):
179
  with gr.Row():
180
- with gr.Column(scale=2):
181
  outputs_display = gr.Textbox(label="Output Details", lines=25)
182
- with gr.Column(scale=3):
183
  outputs_gallery = gr.HTML(label="Image Gallery")
184
 
185
  with gr.Row():
 
59
  total = data.get('total_count', 0)
60
  next_cursor = data.get('next', 'None')
61
 
62
+ # Prepare 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
+ # Create gallery HTML
69
  gallery_html = "<div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 15px;'>"
70
 
71
+ for i, output in enumerate(outputs, 1):
72
+ output_id = output.get('id', 'N/A')
73
+ short_id = output_id[:8] + '...' if len(output_id) > 8 else output_id
74
+ created_at = output.get('created_at', 'N/A')
75
+ status = output.get('status', 'unknown')
76
+ model_name = output.get('model_name', 'Unknown')
77
+
78
+ # Gallery status with emojis
79
+ gallery_status = output.get('gallery_status', 'not_submitted')
80
+ gallery_emoji = {
81
+ 'not_submitted': '🔒',
82
+ 'submitted': '📤',
83
+ 'approved': '✅',
84
+ 'rejected': '❌'
85
+ }.get(gallery_status, '❓')
86
+
87
+ # Favorites
88
+ is_favorited = output.get('is_favorited', False)
89
+ favorite_emoji = '❤️' if is_favorited else '🤍'
90
 
91
+ # Format timestamp
92
+ if created_at != 'N/A':
93
+ try:
94
+ dt = datetime.fromisoformat(created_at.replace('Z', '+00:00'))
95
+ created_date = dt.strftime('%Y-%m-%d')
96
+ created_time = dt.strftime('%H:%M')
97
+ except:
98
+ created_date = created_at
99
+ created_time = ''
100
+ else:
101
+ created_date = 'Unknown'
102
+ created_time = ''
103
+
104
+ # Text display
105
+ display_text += f"{i}. 🔹 **Output {short_id}**\n"
106
+ display_text += f" 🕒 Created: {created_at}\n"
107
+ display_text += f" 📊 Status: {status}\n"
108
+ display_text += f" 🤖 Model: {model_name}\n"
109
+ display_text += f" 🖼️ Gallery: {gallery_emoji} {gallery_status}\n"
110
+ display_text += f" {favorite_emoji} Favorite\n"
111
+
112
+ # Get image URL
113
+ image_url = output.get('image_url')
114
+ if not image_url:
115
+ # Try to get from image_urls array
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  image_urls = output.get('image_urls', [])
117
+ if image_urls and isinstance(image_urls, list) and len(image_urls) > 0:
118
+ image_url = image_urls[0]
119
+
120
+ if image_url:
121
+ # Add to gallery
122
+ gallery_html += f"""
123
+ <div style='border-radius: 10px; overflow: hidden; background: rgba(255,255,255,0.1); padding: 10px;'>
124
+ <img src='{image_url}' style='width: 100%; height: 200px; object-fit: cover; border-radius: 8px;'>
125
+ <div style='margin-top: 8px; font-size: 12px;'>
126
+ <div>📅 {created_date}</div>
127
+ <div>🤖 {model_name[:15]}{'...' if len(model_name) > 15 else ''}</div>
128
+ <div>{gallery_emoji} {gallery_status}</div>
129
+ <div>{favorite_emoji}</div>
 
 
130
  </div>
131
+ </div>
132
+ """
133
+ display_text += f" 🖼️ Image URL: {image_url[:50]}...\n"
134
+ else:
135
+ display_text += f" 🖼️ No image available\n"
136
+
137
+ # Show generation details if available
138
+ generation = output.get('generation', {})
139
+ if generation:
140
+ prompt = generation.get('prompt', 'No prompt')
141
+ if len(prompt) > 50:
142
+ prompt = prompt[:50] + '...'
143
+ display_text += f" 📝 Prompt: {prompt}\n"
144
+
145
+ display_text += "─" * 40 + "\n"
 
 
 
 
 
146
 
147
  gallery_html += "</div>"
148
 
149
+ if not outputs:
150
+ display_text = "📭 No outputs found. Generate some images first!"
151
+ gallery_html = "<div style='text-align: center; padding: 40px; color: #888;'>No images found</div>"
152
+
153
  return display_text, gallery_html, str(data)
154
 
155
  else:
156
+ error_msg = f"❌ Error {response.status_code}"
157
+ return error_msg, f"<div style='color: red; padding: 20px;'>{error_msg}</div>", f"Error: {response.text}"
158
 
159
  except Exception as e:
160
+ error_msg = f"❌ Error: {str(e)}"
161
+ return error_msg, f"<div style='color: red; padding: 20px;'>{error_msg}</div>", "No data"
162
 
163
  # Create Gradio interface
164
  with gr.Blocks(title="StableCog Dashboard") as demo:
 
175
 
176
  with gr.Tab("🖼️ Outputs"):
177
  with gr.Row():
178
+ with gr.Column(scale=1):
179
  outputs_display = gr.Textbox(label="Output Details", lines=25)
180
+ with gr.Column(scale=2):
181
  outputs_gallery = gr.HTML(label="Image Gallery")
182
 
183
  with gr.Row():