Transform Historical Images with "Then and Now" Comparisons

The "Flux Then And Now" service offers developers a powerful tool to create stunning visual comparisons between historical and contemporary photographs. This service leverages advanced image processing techniques, particularly the LoRA (Low-Rank Adaptation) model, to generate detailed and customizable images that highlight the evolution of locations, events, or scenes over time. By integrating this service into your applications, you can enhance storytelling, educational content, and digital archiving, making it easier to visualize changes in our world.
Prerequisites
To get started with the "Flux Then And Now" service, you'll need an API key for the Cognitive Actions platform and a basic understanding of making API calls.
Compare Then and Now Photos with LoRA
This action enables you to generate a side-by-side comparison between historical and current photographs. By utilizing the 'ThenAndNow_v1' model, you can produce visually striking images that showcase how scenes have transformed over time.
Purpose
The primary goal of this action is to facilitate the generation of compelling visual narratives that juxtapose past and present imagery. This can be particularly useful for educators, historians, or content creators looking to illustrate changes in urban landscapes, natural environments, or significant historical events.
Input Requirements
The input for this action consists of several parameters, including:
- prompt: A descriptive text prompt to guide image generation (e.g., "Then-and-now: A black-and-white photo of a street scene is held up in front of a modern street scene, the photo is lined up with the street").
- image: URI for the input image that is to be transformed.
- numOutputs: The number of images you want to generate (1 to 4).
- guidanceScale: A scale factor that influences the realism of the generated images.
- imageAspectRatio: Defines the desired aspect ratio of the output images.
Example Input:
{
"prompt": "Then-and-now: A black-and-white photo of a street scene is held up in front of a modern street scene, the photo is lined up with the street",
"numOutputs": 1,
"guidanceScale": 3.5,
"mainLoraScale": 1,
"outputQuality": 90,
"inferenceModel": "dev",
"promptStrength": 0.8,
"imageAspectRatio": "1:1",
"imageOutputFormat": "webp",
"numInferenceSteps": 28,
"additionalLoraScale": 1
}
Expected Output
The output will be a generated image in the specified format (e.g., webp) that visually compares the historical and modern scenes as described in the prompt.
Example Output:
https://assets.cognitiveactions.com/invocations/48fa7d62-0b08-47ac-828d-7a755d2176d1/a21ba18b-2ab6-46ab-a8b4-da3f39a60250.webp
Use Cases for this Action
- Education: Teachers can use this action to create engaging materials that illustrate changes in geography or history.
- Marketing: Brands can showcase their legacy and transformation over the years, creating a strong narrative for their audience.
- Urban Planning: City planners and historians can visualize urban development and conservation efforts, helping to inform future decisions.
- Social Media: Content creators can engage audiences with eye-catching before-and-after comparisons, sparking conversations and interest.
```python
import requests
import json
# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"
action_id = "b7a78ee6-9ac0-4823-bf00-819cf5955948" # Action ID for: Compare Then and Now Photos with LoRA
# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
"prompt": "Then-and-now: A black-and-white photo of a street scene is held up in front of a modern street scene, the photo is lined up with the street",
"numOutputs": 1,
"guidanceScale": 3.5,
"mainLoraScale": 1,
"outputQuality": 90,
"inferenceModel": "dev",
"promptStrength": 0.8,
"imageAspectRatio": "1:1",
"imageOutputFormat": "webp",
"numInferenceSteps": 28,
"additionalLoraScale": 1
}
headers = {
"Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
"Content-Type": "application/json",
# Add any other required headers for the Cognitive Actions API
}
# Prepare the request body for the hypothetical execution endpoint
request_body = {
"action_id": action_id,
"inputs": payload
}
print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")
try:
response = requests.post(
COGNITIVE_ACTIONS_EXECUTE_URL,
headers=headers,
json=request_body
)
response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
result = response.json()
print("Action executed successfully. Result:")
print(json.dumps(result, indent=2))
except requests.exceptions.RequestException as e:
print(f"Error executing action {action_id}: {e}")
if e.response is not None:
print(f"Response status: {e.response.status_code}")
try:
print(f"Response body: {e.response.json()}")
except json.JSONDecodeError:
print(f"Response body (non-JSON): {e.response.text}")
print("------------------------------------------------")
### Conclusion
The "Compare Then and Now Photos with LoRA" action provides a unique opportunity for developers to create visually captivating content that bridges the past and present. By integrating this functionality, you can enhance your applications with striking imagery that tells a story, educates users, and engages audiences. Explore the possibilities of historical image comparison and see how it can transform your projects today!