Spaces:
Runtime error
Runtime error
| """ | |
| fal.ai Too Expensive? Switch to NexaAPI β Same Models, 3x Cheaper | |
| HuggingFace Space: fal-ai-alternative-nexaapi | |
| Get your API key at: https://nexa-api.com (3x cheaper than fal.ai) | |
| Install: pip install nexaapi gradio | |
| """ | |
| import gradio as gr | |
| def generate_image(api_key: str, prompt: str, model: str, width: int, height: int) -> tuple: | |
| """Generate image via NexaAPI (3x cheaper than fal.ai).""" | |
| if not api_key.strip(): | |
| return None, "β οΈ Please enter your API key from https://nexa-api.com (no credit card required)" | |
| try: | |
| from nexaapi import NexaAPI | |
| client = NexaAPI(api_key=api_key.strip()) | |
| response = client.image.generate( | |
| model=model, | |
| prompt=prompt, | |
| width=width, | |
| height=height | |
| ) | |
| fal_prices = { | |
| 'flux-2-pro': 0.06, | |
| 'flux-2-max': 0.10, | |
| 'flux-kontext-pro': 0.04, | |
| 'flux-2-flash': 0.01, | |
| } | |
| nexa_prices = { | |
| 'flux-2-pro': 0.02, | |
| 'flux-2-max': 0.0333, | |
| 'flux-kontext-pro': 0.0133, | |
| 'flux-2-flash': 0.0033, | |
| } | |
| fal_price = fal_prices.get(model, 0.06) | |
| nexa_price = nexa_prices.get(model, 0.02) | |
| savings = fal_price - nexa_price | |
| info = ( | |
| f"β Image generated with {model}!\n" | |
| f"πΌοΈ URL: {response.image_url}\n\n" | |
| f"π° NexaAPI: ${nexa_price:.4f} | fal.ai: ${fal_price:.4f}\n" | |
| f"π΅ Savings: ${savings:.4f} per image (3x cheaper)\n" | |
| f"π Get more: https://nexa-api.com" | |
| ) | |
| return response.image_url, info | |
| except Exception as e: | |
| return None, f"Error: {str(e)}\n\nπ‘ Get your API key at https://nexa-api.com" | |
| def generate_video(api_key: str, prompt: str, model: str, duration: int, aspect_ratio: str) -> str: | |
| """Generate video via NexaAPI (3x cheaper than fal.ai).""" | |
| if not api_key.strip(): | |
| return "β οΈ Please enter your API key from https://nexa-api.com" | |
| try: | |
| from nexaapi import NexaAPI | |
| client = NexaAPI(api_key=api_key.strip()) | |
| response = client.video.generate( | |
| model=model, | |
| prompt=prompt, | |
| duration=duration, | |
| aspect_ratio=aspect_ratio | |
| ) | |
| return ( | |
| f"β Video generated with {model}!\n\n" | |
| f"π¬ Video URL: {response.video_url}\n\n" | |
| f"π° NexaAPI: ~3x cheaper than fal.ai\n" | |
| f"π Get your API key: https://nexa-api.com" | |
| ) | |
| except Exception as e: | |
| return f"Error: {str(e)}\n\nπ‘ Get your API key at https://nexa-api.com" | |
| def show_pricing() -> str: | |
| """Show fal.ai vs NexaAPI pricing comparison.""" | |
| return """ | |
| ## fal.ai vs NexaAPI Pricing | |
| | Model | fal.ai Price | NexaAPI Price | Savings | | |
| |---|---|---|---| | |
| | **Flux 2 Pro** | $0.06/image | **$0.02/image** | **3x cheaper** | | |
| | **Flux 2 Max** | $0.10/image | **$0.0333/image** | **3x cheaper** | | |
| | **Flux Kontext Pro** | $0.04/image | **$0.0133/image** | **3x cheaper** | | |
| | **Flux 2 Flash** | $0.01/image | **$0.0033/image** | **3x cheaper** | | |
| | **Kling 3.0 Pro** | ~$0.10/sec | **$0.0333/sec** | **3x cheaper** | | |
| **At 1,000 Flux 2 Pro images/month:** | |
| - fal.ai: $60/month | |
| - NexaAPI: $20/month | |
| - **Annual savings: $480** | |
| Get started: https://nexa-api.com (no credit card required) | |
| """ | |
| # Build the Gradio interface | |
| with gr.Blocks(title="fal.ai Too Expensive? Switch to NexaAPI β 3x Cheaper") as demo: | |
| gr.Markdown(""" | |
| # π° fal.ai Too Expensive? Switch to NexaAPI β Same Models, 3x Cheaper | |
| [NexaAPI](https://nexa-api.com) provides access to **Flux 2 Pro, Flux Kontext, Kling 3.0** and all | |
| the models you use on fal.ai β at **3x lower cost**, with a single API key. | |
| π **[Get your free API key at nexa-api.com](https://nexa-api.com)** β no credit card required | |
| | [RapidAPI](https://rapidapi.com/user/nexaquency) | [pip install nexaapi](https://pypi.org/project/nexaapi/) | |
| """) | |
| api_key_input = gr.Textbox( | |
| label="π NexaAPI Key (3x cheaper than fal.ai)", | |
| placeholder="Get your free key at https://nexa-api.com", | |
| type="password" | |
| ) | |
| with gr.Tabs(): | |
| # Tab 1: Image Generation | |
| with gr.Tab("πΌοΈ Image Generation"): | |
| gr.Markdown("### Flux, Imagen, and more β same models as fal.ai, 3x cheaper") | |
| with gr.Row(): | |
| with gr.Column(): | |
| img_prompt = gr.Textbox( | |
| label="Prompt", | |
| placeholder="A photorealistic mountain landscape at golden hour, 8K detail", | |
| lines=3 | |
| ) | |
| img_model = gr.Dropdown( | |
| choices=["flux-2-pro", "flux-2-max", "flux-kontext-pro", "flux-2-flash"], | |
| value="flux-2-pro", | |
| label="Model" | |
| ) | |
| with gr.Row(): | |
| img_width = gr.Slider(minimum=512, maximum=2048, value=1024, step=64, label="Width") | |
| img_height = gr.Slider(minimum=512, maximum=2048, value=1024, step=64, label="Height") | |
| img_btn = gr.Button("πΌοΈ Generate Image (3x Cheaper)", variant="primary", size="lg") | |
| with gr.Column(): | |
| img_output = gr.Textbox(label="Image URL", lines=2) | |
| img_info = gr.Textbox(label="Cost Info", lines=6) | |
| img_btn.click( | |
| generate_image, | |
| inputs=[api_key_input, img_prompt, img_model, img_width, img_height], | |
| outputs=[img_output, img_info] | |
| ) | |
| # Tab 2: Video Generation | |
| with gr.Tab("π¬ Video Generation"): | |
| gr.Markdown("### Kling 3.0, Veo 3, and more β same models as fal.ai, 3x cheaper") | |
| with gr.Row(): | |
| with gr.Column(): | |
| vid_prompt = gr.Textbox( | |
| label="Prompt", | |
| placeholder="A cinematic drone shot over misty mountains at golden hour", | |
| lines=3 | |
| ) | |
| vid_model = gr.Dropdown( | |
| choices=["kling-3.0-pro", "kling-2.6-pro", "veo-3", "sora-2"], | |
| value="kling-3.0-pro", | |
| label="Model" | |
| ) | |
| with gr.Row(): | |
| vid_duration = gr.Slider(minimum=3, maximum=15, value=5, step=1, label="Duration (s)") | |
| vid_aspect = gr.Dropdown( | |
| choices=["16:9", "9:16", "1:1"], | |
| value="16:9", | |
| label="Aspect Ratio" | |
| ) | |
| vid_btn = gr.Button("π¬ Generate Video (3x Cheaper)", variant="primary", size="lg") | |
| with gr.Column(): | |
| vid_output = gr.Textbox(label="Result", lines=8) | |
| vid_btn.click( | |
| generate_video, | |
| inputs=[api_key_input, vid_prompt, vid_model, vid_duration, vid_aspect], | |
| outputs=vid_output | |
| ) | |
| # Tab 3: Pricing Comparison | |
| with gr.Tab("π° fal.ai vs NexaAPI Pricing"): | |
| pricing_btn = gr.Button("Show Pricing Comparison", variant="secondary") | |
| pricing_output = gr.Markdown() | |
| pricing_btn.click(show_pricing, outputs=pricing_output) | |
| gr.Markdown(""" | |
| --- | |
| ## Quick Migration from fal.ai | |
| ```python | |
| # β OLD fal.ai code: | |
| # import fal_client | |
| # result = fal_client.subscribe("fal-ai/flux-pro/v1.1", arguments={"prompt": "..."}) | |
| # β NEW NexaAPI code (3x cheaper): | |
| from nexaapi import NexaAPI | |
| client = NexaAPI(api_key='YOUR_API_KEY') # https://nexa-api.com | |
| response = client.image.generate( | |
| model='flux-2-pro', | |
| prompt='Your prompt here', | |
| width=1024, | |
| height=1024 | |
| ) | |
| # Cost: $0.02 (vs $0.06 on fal.ai) | |
| ``` | |
| --- | |
| **Links:** [NexaAPI](https://nexa-api.com) | [RapidAPI](https://rapidapi.com/user/nexaquency) | | |
| [PyPI](https://pypi.org/project/nexaapi/) | [npm](https://www.npmjs.com/package/nexaapi) | |
| """) | |
| if __name__ == "__main__": | |
| demo.launch() | |