Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import requests
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
# API Configuration
|
| 6 |
+
API_KEY = os.getenv('StableCogKey')
|
| 7 |
+
API_HOST = 'https://api.stablecog.com'
|
| 8 |
+
MODELS_ENDPOINT = '/v1/image/generation/models'
|
| 9 |
+
URL = f'{API_HOST}{MODELS_ENDPOINT}'
|
| 10 |
+
|
| 11 |
+
headers = {
|
| 12 |
+
'Authorization': f'Bearer {API_KEY}',
|
| 13 |
+
'Content-Type': 'application/json'
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
def get_models():
|
| 17 |
+
"""Fetch and display available models"""
|
| 18 |
+
try:
|
| 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 = ""
|
| 27 |
+
for model in models:
|
| 28 |
+
name = model.get('name', 'Unknown')
|
| 29 |
+
model_type = model.get('type', 'unknown')
|
| 30 |
+
description = model.get('description', 'No description')
|
| 31 |
+
|
| 32 |
+
display_text += f"🔹 {name} ({model_type})\n"
|
| 33 |
+
display_text += f" 📝 {description}\n"
|
| 34 |
+
display_text += f" 📊 Public: {model.get('is_public', False)}\n"
|
| 35 |
+
display_text += f" ⭐ Default: {model.get('is_default', False)}\n"
|
| 36 |
+
display_text += f" 👥 Community: {model.get('is_community', False)}\n"
|
| 37 |
+
display_text += "─" * 40 + "\n"
|
| 38 |
+
|
| 39 |
+
total = len(models)
|
| 40 |
+
display_text = f"📊 Found {total} models:\n\n" + display_text
|
| 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"❌ Connection error: {str(e)}", "No data"
|
| 49 |
+
|
| 50 |
+
# Create Gradio interface
|
| 51 |
+
with gr.Blocks(title="StableCog Models") as demo:
|
| 52 |
+
gr.Markdown("# 🤖 StableCog Models Checker")
|
| 53 |
+
|
| 54 |
+
with gr.Row():
|
| 55 |
+
models_display = gr.Textbox(label="Models", lines=20)
|
| 56 |
+
raw_output = gr.Code(label="Raw JSON", language="json", lines=20)
|
| 57 |
+
|
| 58 |
+
check_btn = gr.Button("🔄 Check Models", variant="primary")
|
| 59 |
+
check_btn.click(get_models, outputs=[models_display, raw_output])
|
| 60 |
+
|
| 61 |
+
if __name__ == "__main__":
|
| 62 |
+
demo.launch()
|