Spaces:
Running
Running
Update app.py
Browse files
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
|
| 63 |
-
|
| 64 |
-
display_text
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
gallery_html = "<div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 15px;'>"
|
| 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 |
-
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 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
<
|
| 124 |
-
|
| 125 |
-
<div
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
<div>{favorite_emoji}</div>
|
| 130 |
-
</div>
|
| 131 |
</div>
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 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 |
-
|
| 159 |
-
return
|
| 160 |
|
| 161 |
except Exception as e:
|
| 162 |
-
|
| 163 |
-
return
|
| 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=
|
| 181 |
outputs_display = gr.Textbox(label="Output Details", lines=25)
|
| 182 |
-
with gr.Column(scale=
|
| 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():
|