88import requests
99import responses
1010from rich import print_json
11+ import subprocess
1112import typer
1213
1314# local imports
1718app = typer .Typer ()
1819
1920
21+ mock_image = "https://developer.adobe.com/firefly-services/docs/static/82044b6fe3cf44ec68c4872f784cd82d/96d48/cat-coding.webp"
22+
23+
2024def use_requests_mock ():
2125 rsps = responses .RequestsMock (assert_all_requests_are_fired = False )
2226 rsps .start ()
2327
2428 ims_url = "https://ims-na1.adobelogin.com/ims/token/v3"
2529 image_url = "https://firefly-api.adobe.io/v3/images/generate"
26- mock_image = "https://clio-assets.adobe.com/clio-playground/image-style-zeros/v3/images/Photo_manipulation/4.jpg"
27- with open ("tests/images/4.jpg" , "rb" ) as img_file :
30+ with open ("tests/images/cat-coding.webp" , "rb" ) as img_file :
2831 img_data = img_file .read ()
2932
3033 rsps .add (
@@ -88,6 +91,7 @@ def generate(
8891 client_secret : str = typer .Option (..., help = "Your Adobe Firefly client secret" ),
8992 prompt : str = typer .Option (..., help = "Text prompt for image generation" ),
9093 download : bool = typer .Option (False , help = "Download the generated image to a file (filename is taken from the image URL)" ),
94+ show_images : bool = typer .Option (False , help = "Display the image in the terminal after download." ),
9195 use_mocks : bool = typer .Option (False , help = "Mock API responses for testing without a valid client secret." ),
9296 format : str = typer .Option ("text" , help = "Output format: 'text' (default) or 'json' for pretty-printed JSON response." ),
9397 verbose : bool = typer .Option (False , help = "Print status messages to stderr." ),
@@ -96,10 +100,10 @@ def generate(
96100 Generate an image from a text prompt using Adobe Firefly API.
97101 """
98102 with with_maybe_use_mocks (use_mocks ):
99- _generate (client_id , client_secret , prompt , download , format , verbose )
103+ _generate (client_id , client_secret , prompt , download , show_images , format , verbose )
100104
101105
102- def _generate (client_id , client_secret , prompt , download , format , verbose ):
106+ def _generate (client_id , client_secret , prompt , download , show_images , format , verbose ):
103107 client = FireflyClient (client_id = client_id , client_secret = client_secret )
104108 image_api_url = client .BASE_URL
105109 if verbose :
@@ -150,6 +154,14 @@ def capture_request(*args, **kwargs):
150154 typer .echo (f"Generated image URL: { image_url } " )
151155 if download :
152156 download_image (image_url )
157+ if show_images :
158+ try :
159+ if image_url == mock_image :
160+ subprocess .run (["imgcat tests/images/cat-coding.png" ], shell = True , check = True )
161+ else :
162+ subprocess .run ([f"imgcat --url '{ image_url } '" ], shell = True , check = True )
163+ except Exception as e :
164+ typer .secho (f"[warn] Could not display image in terminal using imgcat: { e } " , fg = typer .colors .YELLOW , err = True )
153165
154166
155167if __name__ == "__main__" :
0 commit comments