IMage genartion service and models revamp - #Migration Runs

This commit is contained in:
IGNY8 VPS (Salman)
2026-01-03 20:08:16 +00:00
parent a70f8cdd01
commit f518e1751b
15 changed files with 817 additions and 287 deletions

View File

@@ -0,0 +1,113 @@
"""
Migration: Update Runware/Image model configurations for new model structure
This migration:
1. Updates runware:97@1 to "Hi Dream Full - Basic"
2. Adds Bria 3.2 model as bria:10@1 (correct AIR ID)
3. Adds Nano Banana (Google) as google:4@2 (Premium tier)
4. Removes old civitai model reference
5. Adds one_liner_description field values
"""
from decimal import Decimal
from django.db import migrations
def update_image_models(apps, schema_editor):
"""Update image models in AIModelConfig"""
AIModelConfig = apps.get_model('billing', 'AIModelConfig')
# Update existing runware:97@1 model
AIModelConfig.objects.update_or_create(
model_name='runware:97@1',
defaults={
'display_name': 'Hi Dream Full - Basic',
'model_type': 'image',
'provider': 'runware',
'cost_per_image': Decimal('0.006'), # Basic tier, cheaper
'valid_sizes': ['1024x1024', '1280x768', '768x1280'],
'supports_json_mode': False,
'supports_vision': False,
'supports_function_calling': False,
'is_active': True,
'is_default': True,
'sort_order': 10,
'description': 'Fast & affordable image generation. Steps: 20, CFG: 7. Good for quick iterations.',
}
)
# Add Bria 3.2 model with correct AIR ID
AIModelConfig.objects.update_or_create(
model_name='bria:10@1',
defaults={
'display_name': 'Bria 3.2 - Quality',
'model_type': 'image',
'provider': 'runware', # Via Runware API
'cost_per_image': Decimal('0.010'), # Quality tier
'valid_sizes': ['1024x1024', '1344x768', '768x1344', '1216x832', '832x1216'],
'supports_json_mode': False,
'supports_vision': False,
'supports_function_calling': False,
'is_active': True,
'is_default': False,
'sort_order': 11,
'description': 'Commercial-safe AI. Steps: 8, prompt enhancement enabled. Licensed training data.',
}
)
# Add Nano Banana (Google) Premium model
AIModelConfig.objects.update_or_create(
model_name='google:4@2',
defaults={
'display_name': 'Nano Banana - Premium',
'model_type': 'image',
'provider': 'runware', # Via Runware API
'cost_per_image': Decimal('0.015'), # Premium tier
'valid_sizes': ['1024x1024', '1376x768', '768x1376', '1264x848', '848x1264'],
'supports_json_mode': False,
'supports_vision': False,
'supports_function_calling': False,
'is_active': True,
'is_default': False,
'sort_order': 12,
'description': 'Google Gemini 3 Pro. Best quality, text rendering, advanced reasoning. Premium pricing.',
}
)
# Deactivate old civitai model (replaced by correct bria:10@1)
AIModelConfig.objects.filter(
model_name='civitai:618692@691639'
).update(is_active=False)
# Deactivate other old models
AIModelConfig.objects.filter(
model_name__in=['runware:100@1', 'runware:101@1']
).update(is_active=False)
def reverse_migration(apps, schema_editor):
"""Reverse the migration"""
AIModelConfig = apps.get_model('billing', 'AIModelConfig')
# Restore old display names
AIModelConfig.objects.filter(model_name='runware:97@1').update(
display_name='Hi Dream Full - Standard',
)
# Remove new models
AIModelConfig.objects.filter(model_name__in=['bria:10@1', 'google:4@2']).delete()
# Re-activate old models
AIModelConfig.objects.filter(
model_name__in=['runware:100@1', 'runware:101@1', 'civitai:618692@691639']
).update(is_active=True)
class Migration(migrations.Migration):
dependencies = [
('billing', '0023_update_runware_models'),
]
operations = [
migrations.RunPython(update_image_models, reverse_migration),
]

View File

@@ -63,8 +63,9 @@ def get_image_model_choices(provider=None):
]
elif provider == 'runware':
return [
('runware:97@1', 'Hi Dream Full - Standard'),
('civitai:618692@691639', 'Bria 3.2 - Premium'),
('runware:97@1', 'Hi Dream Full - Basic'),
('bria:10@1', 'Bria 3.2 - Quality'),
('google:4@2', 'Nano Banana - Premium'),
]
return []
@@ -171,10 +172,21 @@ class GlobalIntegrationSettings(models.Model):
]
RUNWARE_MODEL_CHOICES = [
('runware:97@1', 'Hi Dream Full - Standard'),
('civitai:618692@691639', 'Bria 3.2 - Premium'),
('runware:97@1', 'Hi Dream Full - Basic'),
('bria:10@1', 'Bria 3.2 - Quality'),
('google:4@2', 'Nano Banana - Premium'),
]
# Model-specific landscape sizes (square is always 1024x1024 for all models)
MODEL_LANDSCAPE_SIZES = {
'runware:97@1': '1280x768', # Hi Dream Full landscape
'bria:10@1': '1344x768', # Bria 3.2 landscape (16:9)
'google:4@2': '1376x768', # Nano Banana landscape (16:9)
}
# Default square size (universal across all models)
DEFAULT_SQUARE_SIZE = '1024x1024'
BRIA_MODEL_CHOICES = [
('bria-2.3', 'Bria 2.3 - High Quality ($0.015/image)'),
('bria-2.3-fast', 'Bria 2.3 Fast - Quick Generation ($0.010/image)'),
@@ -335,13 +347,9 @@ class GlobalIntegrationSettings(models.Model):
desktop_image_size = models.CharField(
max_length=20,
default='1024x1024',
help_text="Default desktop image size (accounts can override if plan allows)"
)
mobile_image_size = models.CharField(
max_length=20,
default='512x512',
help_text="Default mobile image size (accounts can override if plan allows)"
help_text="Default image size for in-article images (accounts can override if plan allows)"
)
# Note: mobile_image_size removed - no longer needed
# Metadata
is_active = models.BooleanField(default=True)

View File

@@ -0,0 +1,43 @@
# Generated migration for updating Runware image models
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('system', '0013_add_anthropic_integration'),
]
operations = [
# Update runware_model field with new model choices
migrations.AlterField(
model_name='globalintegrationsettings',
name='runware_model',
field=models.CharField(
choices=[
('runware:97@1', 'Hi Dream Full - Basic'),
('bria:10@1', 'Bria 3.2 - Quality'),
('google:4@2', 'Nano Banana - Premium'),
],
default='runware:97@1',
help_text='Default Runware model (accounts can override if plan allows)',
max_length=100,
),
),
# Update desktop_image_size help text (mobile removed)
migrations.AlterField(
model_name='globalintegrationsettings',
name='desktop_image_size',
field=models.CharField(
default='1024x1024',
help_text='Default image size for in-article images (accounts can override if plan allows)',
max_length=20,
),
),
# Remove mobile_image_size field if it exists (safe removal)
migrations.RemoveField(
model_name='globalintegrationsettings',
name='mobile_image_size',
),
]

View File

@@ -0,0 +1,23 @@
# Generated migration for Images model unique constraint
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('writer', '0015_add_publishing_scheduler_fields'),
]
operations = [
# Add unique constraint for content + image_type + position
# This ensures no duplicate positions for the same image type within a content
migrations.AddConstraint(
model_name='images',
constraint=models.UniqueConstraint(
condition=models.Q(('is_deleted', False)),
fields=('content', 'image_type', 'position'),
name='unique_content_image_type_position',
),
),
]

View File

@@ -76,6 +76,7 @@ class ImagesSerializer(serializers.ModelSerializer):
"""Serializer for Images model"""
task_title = serializers.SerializerMethodField()
content_title = serializers.SerializerMethodField()
aspect_ratio = serializers.ReadOnlyField() # Expose aspect_ratio property
class Meta:
model = Images
@@ -92,11 +93,12 @@ class ImagesSerializer(serializers.ModelSerializer):
'caption',
'status',
'position',
'aspect_ratio',
'created_at',
'updated_at',
'account_id',
]
read_only_fields = ['id', 'created_at', 'updated_at', 'account_id']
read_only_fields = ['id', 'created_at', 'updated_at', 'account_id', 'aspect_ratio']
def get_task_title(self, obj):
"""Get task title"""